Skip to content

Instantly share code, notes, and snippets.

View sunkencity's full-sized avatar

Joel Westerberg sunkencity

  • Stockholm, Sweden
View GitHub Profile
:vimgrep /pattern/ path/**
:cope #to open quickfix list
@sunkencity
sunkencity / gist:3736683
Created September 17, 2012 10:55
compojure test
(defn
^{:doc "Action that shows the help and about page."
:path "/help"
:http_method :get}
action-show
[account member]
(normal-layout account
[:div
[:h1 "Title"]
[:p "lorem")
@sunkencity
sunkencity / mapreduce
Created May 14, 2012 07:48
A simple mapreduce example
A little tutorial on mapreduce.
This is a short tutorial on what mapreduce is. It'll do a process first sequentially and then with multiple mapper jobs As a silly example we will try to get a list of prime numbers in a big corpus of random numbers. Let's first start out with creating some test data that has good behaviour. We'll do this in the a terminal shell using ruby.
$ruby -e "(1..100).each { |x| puts x }" > data_1..100.txt
Look at the file with the "cat" utility:
$ cat data_1..100.txt
1
@sunkencity
sunkencity / gist:2225386
Created March 28, 2012 10:54
Validera personnummer
# encoding: utf-8
class SocialSecurityNumber
def initialize str
if str =~ /(\d{2})(\d{2})(\d{2})(\d{4})/
@str = str
@year,@month,@day,@last_four = $1,$2,$3,$4
current_year = Time.now.year % 100
century = @year.to_i > current_year ? "19" : "20"
@full_year = "#{century}#{@year}"
@sunkencity
sunkencity / database.yml
Created April 26, 2011 06:45
nice tip for testing #rails with #postgresql to file to get rid of NOTICE messages for primary keys
min_messages: WARNING
@sunkencity
sunkencity / gist:925082
Created April 18, 2011 09:36
Rails:: Quick and Dirty move attachments on S3 from one path to another with paperclip.
class Paperclip::Attachment
def save
flush_deletes
oldpath = @path
@path = '/:attachment/:id/:style/:filename'
puts 'patching the path...'
flush_writes
@path = oldpath
@dirty = false
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
<title>Search Input Issue</title>
</head>
@sunkencity
sunkencity / do ... end block ruby
Created March 16, 2011 15:17
in 1.9.2 do ... end blocks return an enumerator, in 1.8.7 nil, but return the same as {} if assigned to a var. why?
puts [1,2,3].map {|x|x+1}.inspect
#[2, 3, 4]
puts [1,2,3].map do |x|x+1 end.inspect
#<Enumerator:0x00000100868110>
require 'rubygems'
require 'nokogiri'
require 'pp'
class XMLToArr < Nokogiri::XML::SAX::Document
def XMLToArr.parse str, hsh
[].tap do |returning|
Nokogiri::XML::SAX::Parser.new(self.new(returning, hsh)).parse(str)
end
@sunkencity
sunkencity / gist:851560
Created March 2, 2011 19:36
start a irb console from rake
desc "Start a console"
task :console do
require 'irb'
ARGV.clear
IRB.start
end