Skip to content

Instantly share code, notes, and snippets.

@canweriotnow
canweriotnow / euler022.rb
Created September 4, 2010 17:48
Solution to Euler problem 22 in Ruby
# Ruby script to solve Euler Problem 22
# names.txt d/l'd from http://projecteuler.net/project/names.txt
nf = File.open("names.txt", 'r')
names = nf.gets.scan(/\w+/).sort
total = 0
names.each_with_index do |n,i|
tmp = 0
@canweriotnow
canweriotnow / euler048.rb
Created September 9, 2010 00:08
Solution to Euler problem 048
#!/usr/bin/ruby
sum = 0
x = (1..1000).to_a
x.each do |n|
sum += n**n
end
puts sum
@canweriotnow
canweriotnow / jayz.rb
Created September 10, 2010 00:19
Jay-Z in Ruby!
#!/usr/bin/ruby
foo = "a bitch"
problems = (1..99).to_a
sum = 0
problems.each do |x|
if x == foo
next
else
sum += 1
@canweriotnow
canweriotnow / fixdate.coffee
Created May 10, 2011 15:38
Patching Date.parse() to accept ISO dates (bug in Safari)
origParse = Date.parse
Date.parse = (date) ->
timestamp = origParse(date)
if isNaN(timestamp) && date.match(/^\d{4}-\d{2}-\d{2}/)
dary = date.split('-')
timestamp = origParse(dary[1] + '/' + dary[2] + '/' + dary[0])
return timestamp
@canweriotnow
canweriotnow / funnyjunk.txt
Created May 25, 2011 20:14
Funnyjunk.com ISP info
DNS Info:
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
Domain Name: FUNNYJUNK.COM
Registrar: MONIKER ONLINE SERVICES, INC.
@canweriotnow
canweriotnow / unicorn
Created July 5, 2011 17:38
/etc/init.d script for unicorn
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by jay@gooby.org http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
@canweriotnow
canweriotnow / quinebunny.rb
Created November 1, 2011 12:37
A quine and a wabbit walk into a bar...
#!/usr/bin/env ruby
file = File.read(__FILE__)
name = "quinebunny-#{Time.now.to_s.gsub(/\s/, '')}.rb"
io = File.new(name, 'w')
io.write(file)
io.close
%x(ruby #{name})
@canweriotnow
canweriotnow / fib.clj
Created November 4, 2011 19:41
Finding Fibonacci w/ anonymous function in Clojure
;; solution to Fibonacci Sequence
;; https://4clojure.com/problem/26
(fn [n] (take n (map first (iterate (fn [[a b]] (vector b (+ a b))) [1 1])))))
@canweriotnow
canweriotnow / maybe.rb
Created February 7, 2012 19:22
Evil params checking
# In the controller:
private
def maybe(param)
if params[param]
{param => params[param]}
end
end
@canweriotnow
canweriotnow / issue.rb
Created February 7, 2012 21:45
Chaining scopes for milt
class Issue < ActiveRecord::Base
named_scope :tasks, :conditions => {:tracker_id => 7} # if the id of the Tasks tracker is 7, natch
named_scope :open, :conditions => {:status_id => 1} # assuming 'Open' == 1
end
# Then in your controller action: