Instantly share code, notes, and snippets.

# Jason Lewiscanweriotnow

• Sort options
Created Sep 4, 2010
Solution to Euler problem 22 in Ruby
View euler022.rb
 # 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
Created Sep 9, 2010
Solution to Euler problem 048
View euler048.rb
 #!/usr/bin/ruby sum = 0 x = (1..1000).to_a x.each do |n| sum += n**n end puts sum
Created Sep 10, 2010
Jay-Z in Ruby!
View jayz.rb
 #!/usr/bin/ruby foo = "a bitch" problems = (1..99).to_a sum = 0 problems.each do |x| if x == foo next else sum += 1
Created May 10, 2011
Patching Date.parse() to accept ISO dates (bug in Safari)
View fixdate.coffee
 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
Created May 25, 2011
Funnyjunk.com ISP info
View funnyjunk.txt
 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.
Created Jul 5, 2011
/etc/init.d script for unicorn
View 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 ##
Created Nov 1, 2011
A quine and a wabbit walk into a bar...
View quinebunny.rb
 #!/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})
Created Nov 4, 2011
Finding Fibonacci w/ anonymous function in Clojure
View fib.clj
 ;; 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])))))
Created Feb 7, 2012
Evil params checking
View maybe.rb
 # In the controller: private def maybe(param) if params[param] {param => params[param]} end end
Created Feb 7, 2012
Chaining scopes for milt
View issue.rb
 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:
You can’t perform that action at this time.