Skip to content

Instantly share code, notes, and snippets.

class GetData
@@logger = Logger.new('log.log')
def initialize
@yesterday = Date.today.prev_day
@token = xxx
end
def save_actions
with_database do |db|
require 'open3'
Open3.popen3 'bash' do |stdin, stdout, stderr, wait|
t=Thread.new{ stdout.each{|l| print l } }
stdin.puts 'ls'
stdin.puts 'exit'
wait.join
t.join
end
# Norwegian, norsk bokmål, by irb.no
"no":
support:
array:
sentence_connector: "og"
date:
formats:
default: "%d.%m.%Y"
short: "%e. %b"
long: "%e. %B %Y"
module ApplicationHelper
def labelled_form_for(*attrs, &proc)
options = attrs.last.is_a?(Hash) ? attrs.pop : {}
object = attrs.pop
options.reverse_merge!(
:builder => LabellingFormBuilder
)
module Kernel
def recurse(*a, &b)
send(caller(1).first[/`(.*?)'\Z/, 1], *a, &b)
end
end
class Foo
def bar(stop=false)
#Keeps a list of registered names associated with classes at a "base" class
#Example:
#
# class Base
# extend Registerable
# end
#
# class Foo < Base
# register :foo
# end
@toretore
toretore / README
Created April 9, 2011 23:23
Facebook Canvas apps, CSRF protection & session cookies
Facebook Canvas apps are loaded like this:
* User clicks link to app or tab ("page as tab")
* An iframe is inserted which loads content from the FB server (NOT yours, yet)
Something along the lines of:
<iframe src="http://facebook.com/page_proxy.php?appid=123">
* The FB server returns some HTML & JS with an automatically submitting form:
<form id="humbaba" target="http://you.com/facebook">
<input type="hidden" name="signed_request"/></form>
# Returns a set of hidden fields for params passed in the query string such that they are passed
# along with the form. Mostly for use with GET forms like search/filtering where you want to retain
# other state while adding another (<existing params>&q=pr0n)
#
# Options:
#
# :skip - An array of keys to leave out - Only works for first-level keys, i.e. not 'bar' in foo[bar]=baz
def hidden_fields_from_params(opts={})
#Use CGI.parse to get "raw" parameters that haven't been converted into arrays
#and hashes yet. This means it only has to concern itself with the one dimension
@toretore
toretore / explicit.rb
Created November 15, 2011 10:03 — forked from mikebaldry/gist:1366593
find subclasses
class PullSource
def self.implementations
@implementations ||= {}
end
def self.register(name)
implementations[name] << self
end
@toretore
toretore / gist:1922637
Created February 27, 2012 09:02
something like this in the contract model
class Contract < ActiveRecord::Base
has_paper_trail
acts_as_restful_list
CHANGE_FIELDS_MAP = {
'contract_status_id' => {
:association => 'contract_status'
:field => 'name'
}