Mark Grealish

Cats and wizardry.



prep 6.0

I took three hours out of tonight to add srcset capability to my image upload script. The srcset test was hand-everything: hand-copied, hand-mogrified, hand-uploaded and the HTML assembled by hand. The updated script: Copies images to the thumbnail folder. Shrinks thumbnail images and resizes them into each size in the srcset array. Generates link […]

Three random narcissistic selfies

I’m testing a script, ignore.

Caira and Garrett, Hallowe’en 2015

Project Euler Problem #1

I’m on a Ruby refresher through Project Euler. I’ve come a long way since my brute force C# solution in 2012. def sum_to(multiples, end_num)! do |number| number = number.to_f max = end_num - (end_num % number) number = (max / number / 2) * (max + number) end end three, five, fifteen = sum_to([3, […]

Project Euler Problem #2

This is again less brute-forcey than my original C# solution because I used an algorithm to find the next Fibonacci number in line. def fib(n) # fib(n) = round(ϕ^n / √5) phi = 1.618033988749894 sqrt_5 = 2.23606797749979 (phi ** n / sqrt_5).round end fib_n = 0 fib_val = 0 fib_sum = 0 while true do […]

Project Euler #3

Problem #3 in C#. require 'prime' p { |f| f[0] if[0]) }.max

Project Euler Problem #4

Still bruteforcey, just less so compared to my original C# solution. def palindrome?(str) str == str.reverse end def largest_palindrome(range) palindromes = [] range.each { |x| range.each { |y| xy = x * y palindromes << xy if palindrome?(xy.to_s) } } palindromes.max end p largest_palindrome 100..999

Project Euler Problem #20

Problem #20 is probably the easiest problem. Hurray for builtin functions! Original C# solution. p (1..100).reduce(:*).to_s.split(//).map(&:to_i).reduce(:+)

Project Euler Problem #13

My previous C# solution was…actually a Bourne shell script, because C# made this problem a pain in the ass: Add System.IO namespace. Add System.Numerics namespace. Walk through all of the pain-in-the-ass steps to read the text file and work with BigInteger. Shell? Read file, add lines. Ruby was even easier: p"13.txt").split(/\n/).map(&:to_i).reduce(:+).to_s[0,10].to_i

Project Euler Problem #19

Holy shit. Here is how far I’ve come: Dat C#. Dat leap year function. Dem lack of braces. I remember the Wikipedia articles and blog posts I read to figure out leap years, and the hours of trials to get function right. Here’s my 2015 leap year function: return year % 400 === 0 || […]

Fibonacci’s method to find Pythagorean triples (in Ruby)

When I made my first run through the Project Euler problems I: did not care so much for algorithms, as I did about the solution; and wrote my code such that its function wouldn’t be obvious. There was an unspoken rule about Project Euler: “don’t give away the answer.” You can paste my code into […]

This is my life now

Hell of a week

This blog post came about because I needed to practice my typing. On monday last I began my new job as a Ruby on Rails developer in Dublin, 9-5 Monday to Friday and probably overtime as I advance in the position. And what does a developer do but type? My WPM is an okay 80 […]

Mmm…sacrilegious coffee

There was a bunch of taff on Twitter about coffee cups…so why not?

Rails is hard

I’ve spent the past week learning Ruby on Rails by way of a crappy Twitter clone named nttr, which I bill as “the world’s first vowelless microblogging service.” I now have an appreciation for how hard it is to make a shitty web app, let alone a good web app.