I took three hours out of tonight to add srcset capability to my image upload script. https://github.com/bhalash/prep 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 […]

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) multiples.map! 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, […]

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 […]

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

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(:+)

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 File.read("13.txt").split(/\n/).map(&:to_i).reduce(:+).to_s[0,10].to_i

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 || […]

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 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 […]

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.