Skip to content

Instantly share code, notes, and snippets.

View alfo's full-sized avatar

Alex Forey alfo

View GitHub Profile
@alfo
alfo / multiply.rb
Created December 10, 2014 19:36
Multiply two huge numbers together without Ruby's help
first_string = gets.chomp
second_string = gets.chomp
to_find = gets.chomp
def string_times_int(string, int)
product = ""
carry = 0
loop = string.length - 1
@alfo
alfo / apple-touch-icon.erb
Created July 21, 2014 18:03
A quick way to add link tags for all the different sizes of Apple Touch Icon
<% [57, 60, 72, 76, 114, 144, 120, 152].each do |size| %>
<link rel="apple-touch-icon" sizes="<%= size %>x<%= size %>" href="<%= image_path("icons/apple-touch-icon-#{size}x#{size}.png") %>">
<% end %>
@alfo
alfo / cron.php
Created January 14, 2014 17:48
Cron job to update Cloudflare's DNS to point to your current IP address. Useful for people with dynamic public IPs because their stupid ISP won't let them have a static one.
<?php
// Grab the IP address
// This is the fastest method I've found so far
$ip = system('dig +short myip.opendns.com @resolver1.opendns.com');
// For cron logs
print "New IP is: " . $ip;
$ch = curl_init();
@alfo
alfo / jmc-22.rb
Last active December 16, 2015 14:19
JMC 2006 Question 22 answered in 3 lines. "A positive whole number less than 100 has remainder 2 when divided by 3, remainder 3 when divided by 4, and remainder 4 when divided by 5. What is the remainder when the number is divided by 7?"
for n in 1..99 do
p n % 7 if n % 3 == 2 and n % 4 == 3 and n % 5 == 4
end
# By Oto Brglez - @otobrglez
# Rake task. Put in your (lib/tasks) folder of your Rails application
# Execute with "rake dropbox:backup"
# Configuration must be inside config/dropbox.yml file
namespace :dropbox do
desc "Backup production database to dropbox"
task :backup do