Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# A copy of script that gets API usage from Librato.
# Some variables are replaced for security reasons - so it won't work as it is for you.
# It's a reference of my blog post on geckoboard blog.
class LibratoMetric
def initialize
@user = APP_CONFIG["librato"]["user"]
@api_token = APP_CONFIG["librato"]["api_token"]
require 'net/http'
require 'json'
class GeckoboardClient
def initialize(api_key)
@api_key = api_key
end
def url(widget_key)
"https://push.geckoboard.com/v1/send/#{widget_key}"
@ono
ono / test.md
Last active August 29, 2015 14:21
test = ['example']
#!/usr/bin/ruby
def t2m(target)
command = "./t2m.pl -d #{target}.td >> export.file"
p command
system command
end
"2007".upto("2009") do |y|
"01".upto("12") do |m|
require File.dirname(__FILE__) + '/../spec_helper'
class Foo
def self.hello
"hello"
end
end
class FooBar < Foo
def self.konnichiwa
namespace :security do
# ====
# Usage:
# rake security:add_attr_accessible => edit all models which are not called either attr_accessible or attr_protected.
# rake security:att_attr_accessible models="blog,article" => update only blog and article. it doesn't check whether there are attr_accessible or attr_protected.
desc "defines attr_accessible listing all attributes but associations into model(s)"
task :add_attr_accessible => :environment do
models = ENV["models"]
if models.to_s.size==0
models = risky_models
a = lambda {|src| src.map { |v| v.is_a?(Fixnum) ? v + 1 : v.is_a?(Array) ? a.call(v) : v } }
a.call [1, 2, 3, ["a", 1, 2, 3, ["a", 1, 2, 3], "a"]]
@ono
ono / resque_without_queue.rb
Created February 12, 2010 12:30
Allow you to develop codebase using Resque without running worker and setting up redis
# Some developers (or designers) in your project might not need resque running in local nor want to hasstle to set up redis.
# For helping such lazy people, I give you a option.
# Put and customize this code from Rails initializers, Sinatra configuration block, or wherever.
require 'resque'
if ENV["RAILS_ENV"]=="development" # <= Change this condition as you like
module Resque
# Performs job immediately without queueing.
def perform_immediately(queue, item)
item = decode(encode(item))
# BaseJob is a super class of Resque jobs which you want to track with RPM
class BaseJob
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
# This is called from Resque.
# To be wrapped with the common operation, please describe job in the instance's perform method.
def self.perform(*args)
NewRelic::Control.instance['forked_job'] = true
self.new.perform_wrapper(*args)
ensure