This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test = ['example'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../spec_helper' | |
class Foo | |
def self.hello | |
"hello" | |
end | |
end | |
class FooBar < Foo | |
def self.konnichiwa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer