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
r = Redis.new(url: 'redis://foo:bar@foo.com:123') | |
queries = r.slowlog('get', 1000) | |
puts queries.map{|q| "#{Time.at(q[1])} - #{q[2]/1000}ms - #{q[4].first} : #{q[4][1..-1]}"}.join("\n") |
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 'httparty' | |
class Wink | |
include HTTParty | |
CLIENT_ID = 'CHANGE_ME' | |
CLIENT_SECRET = 'CHANGE_ME' | |
base_uri 'https://winkapi.quirky.com' | |
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 | |
require 'httparty' | |
require 'blink1' | |
class PagerDuty | |
include HTTParty | |
TOKEN = "YOUR_PAGERDUTY_API_TOKEN" | |
PAGERDUTY_DOMAIN = "YOUR_PAGERDUTY_DOMAIN" | |
base_uri "https://#{PAGERDUTY_DOMAIN}.pagerduty.com/api/v1" |
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
### Keybase proof | |
I hereby claim: | |
* I am slemiere on github. | |
* I am slemiere (https://keybase.io/slemiere) on keybase. | |
* I have a public key whose fingerprint is 2B47 E503 DCF4 124B 9DB8 214D 12F1 E851 633A F5BD | |
To claim this, I am signing this object: |
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
define_method("hello_yield") { yield } | |
define_method("hello_block_call") { |&block| block.call} | |
hello_yield { puts "hello Yield"} | |
# LocalJumpError: no block given (yield) | |
hello_block_call { puts "Hello Block Call"} | |
# Hello Block Call |
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
module Mongoid | |
module Document | |
def instantiate(attrs = nil, criteria_instance_id = nil) | |
attributes = attrs || {} | |
doc = allocate | |
doc.criteria_instance_id = criteria_instance_id | |
doc.instance_variable_set(:@attributes, attributes) | |
doc.apply_defaults | |
IdentityMap.set(doc) if identity_map_set_possible?(criteria_instance_id) | |
doc.run_callbacks(:initialize) unless doc._initialize_callbacks.empty? |
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
all_queues = ["test", "schedule", "process"] | |
QUEUES = "*" | |
# ["test", "schedule", "process"] | |
QUEUES = "test,schedule" | |
# ["test", "schedule"] | |
QUEUES = "*~test" | |
# ["schedule", "process"] |
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
(function(){function Asteroids(){function Vector(x,y){if(typeof x=='Object'){this.x=x.x;this.y=x.y;}else{this.x=x;this.y=y;}};Vector.prototype={cp:function(){return new Vector(this.x,this.y);},mul:function(factor){this.x*=factor;this.y*=factor;return this;},mulNew:function(factor){return new Vector(this.x*factor,this.y*factor);},add:function(vec){this.x+=vec.x;this.y+=vec.y;return this;},addNew:function(vec){return new Vector(this.x+vec.x,this.y+vec.y);},sub:function(vec){this.x-=vec.x;this.y-=vec.y;return this;},subNew:function(vec){return new Vector(this.x-vec.x,this.y-vec.y);},rotate:function(angle){var x=this.x,y=this.y;this.x=x*Math.cos(angle)-Math.sin(angle)*y;this.y=x*Math.sin(angle)+Math.cos(angle)*y;return this;},rotateNew:function(angle){return this.cp().rotate(angle);},setAngle:function(angle){var l=this.len();this.x=Math.cos(angle)*l;this.y=Math.sin(angle)*l;return this;},setAngleNew:function(angle){return this.cp().setAngle(angle);},setLength:function(length){var l=this.len();if(l)this.mul(lengt |
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 'text' | |
def compute_friends(word, words) | |
words.reject{|potential_friend| Text::Levenshtein.distance(word, potential_friend) > 1} | |
end | |
def naive_word_social_network(word, non_friend_words) | |
last_social_network_step = [] | |
new_friends = [word] | |
current_social_network_step = [word] |
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
# written by Pradeep Gatram, www.masplantiz.com | |
# no restrictions whatsoever on usage. | |
require 'rubygems' | |
require 'mq' | |
EM.run do | |
def replicate source, destination, topic | |
source_q = MQ::Queue.new(source, "replicator for #{topic}") | |
source_q.bind(MQ::Exchange.new(source, :topic, topic)) |
NewerOlder