Skip to content

Instantly share code, notes, and snippets.

View sunkencity's full-sized avatar

Joel Westerberg sunkencity

  • Stockholm, Sweden
View GitHub Profile
@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
#
# Short words in Rails locale files with åäö become binary!
# But the _why oneliner seems to work. The problem is probably elsewhere. Logging this for reference.
#
# http://stdlib.rubyonrails.org/libdoc/yaml/rdoc/classes/String.html
# File yaml/rubytypes.rb, line 145
# def is_binary_data?
# ( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 ) unless empty?
/** C grade styles for jquery mobile **/
body,html { font-family: Helvetica,Arial,sans-serif; padding: 0; margin: 0; background: #F0F0F0; }
h1 { margin: 0; width: 100%; background: #111111; color: #ffffff; font-size: 16px; line-height: 39px; text-align: center; margin-bottom: 30px; }
p { margin: 20px 15px 20px 15px; color: #333333; font-size: 16px; }
a { color: #2489CE; font-weight: bold; }
h2,h3,h4,h5,h6,img,pre,form,table,ul { margin: 0 15px 0 15px; }
dt { margin: 20px 15px 0 15px; }
dd { margin: 0 30px 0 30px; }
ul { list-style-type: none; border-bottom: 1px solid #cccccc; padding: 0; font-size: 14px; }
@sunkencity
sunkencity / gist:704976
Created November 18, 2010 13:38
weird id behaviour
diff --git a/js/jquery.mobile.js b/js/jquery.mobile.js
index 86f8472..c9c7e3c 100644
--- a/js/jquery.mobile.js
+++ b/js/jquery.mobile.js
@@ -478,7 +478,7 @@
}
to
- .attr( "id", fileUrl )
+ .attr( "id", fileUrl.replace(".", "") )
#!/usr/bin/env ruby
# backup script for postgresql databases
# connects via ssh and copies the file to a local path
@ssh_host = ""
@ssh_user = ""
@ssh_pass = ""
@db_name = ""
namespace :delayed_job do
task :ensure, :roles => :app do
pid_from_file = capture("cat #{current_path}/tmp/pids/delayed_job.pid").strip
running_pids = capture("ps -ef | grep [d]elayed_job").split("\n").map { |x| x.split[1] }
if pid_from_file != running_pids.first || running_pids.size != 1
puts ("-"*80).console_purple
puts "Something is terribly wrong with delayed job!".console_red
puts "Running_pid: #{pid_from_file}"
puts "Running delayed job processes: #{capture("ps -ef | grep [d]elayed_job")}"
puts ("-"*80).console_purple