Skip to content

Instantly share code, notes, and snippets.

@shime
shime / tracking.rb
Created December 21, 2012 19:04
Tracking request durations in Rails. Courtesy of @stathat
if Rails.env.production?
slow_logfile = File.open(Rails.root.join("log", "slow.log"), 'a')
slow_log = Logger.new(slow_logfile)
slow_log.level = Logger::INFO
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload|
duration = (finish - start) * 1000
StatHat::API.ez_post_value("rails request duration", "info@stathat.com", duration)
view_time = 0
db_time = 0
@shime
shime / test.coffee
Created January 16, 2014 22:27
testing Ember.RSVP with QUnit
test "the Ember.RSVP.Promise works", ->
promise = new Ember.RSVP.Promise((resolve, reject) ->
Ember.run(null, resolve, "value")
)
Ember.run =>
promise.then (actual) ->
equal(actual, 'value', 'promise resolved with "hello"')
@shime
shime / _readme.md
Last active October 24, 2016 04:42
describes redirection issue from stackoverflow.com/a/9627796/726020
source 'https://rubygems.org'
gem "minitest"
@shime
shime / eighth.rb
Last active June 6, 2016 14:08
my codility solutions
def solution(a)
counter = [0] * a.length
a.each do |element|
if ! (1 <= element && element <= a.length)
return 0
else
if counter[element-1] != 0
return 0
else
counter[element-1] = 1
@shime
shime / _readme.md
Created November 28, 2013 14:25
easier renaming and moving of files in vim

Simple function that makes moving and renaming files in Vim much easier.

Usage

Place it in your ~/.vimrc.

I'm calling it with N here, map it to anything you like.

@shime
shime / artists.json
Created November 2, 2013 10:29
some good electroswing artists
{
"artists": [
"parov stelar",
"proleter",
"goldfish",
"tape five",
"movits",
"odjbox"
]
}
var express = require('express')
, app = express()
, http = require('http')
, server = http.createServer(app)
, io = require('socket.io').listen(server);
server.listen(4000);
app.get('/', function(request, response){
response.sendfile(__dirname + "/index.html");
@shime
shime / .gitignore
Last active December 24, 2015 17:39 — forked from uu59/.gitignore
socket.io and sinatra in action
vendor/
.bundle/
node_modules/
Gemfile.lock
@shime
shime / _app.rb
Last active December 23, 2015 20:39
DCI implementation of OAuth with Github in Sinatra
require "sinatra"
get "/oauth/github" do
OAuthingWithGithub.start(self)
end
get "/oauth/github/callback" do
OAuthingWithGithub.finish(self)
end