Skip to content

Instantly share code, notes, and snippets.

View ephekt's full-sized avatar

Mike R ephekt

  • maker of things
  • California
View GitHub Profile
@ephekt
ephekt / irbrc.rb
Created July 2, 2013 20:04
Enable ActiveRecord to output raw queries in Rails Console
# In your active `rails c` session type
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
# or, in your ~/.irbrc add the following
require 'rubygems'
if ENV.include?('RAILS_ENV') && ENV["RAILS_ENV"] == 'development'
# encoding: utf-8
require 'tmpdir'
require 'stringio'
require 'zip/zipfilesystem'
# Base class for all other types of spreadsheets
class Roo::GenericSpreadsheet
include Enumerable
@ephekt
ephekt / server.js
Created October 17, 2012 00:30
loggly nodejs code
var http = require('http'),
director = require('director'),
loggly = require('loggly');
var loggly_client = loggly.createClient({
subdomain: "delphi",
json: true
});
var send_to_loggly = function(json_package) {
@ephekt
ephekt / server.js
Created October 12, 2012 22:52
nodejs+director
var http = require('http'),
director = require('director');
var router = new director.http.Router({
'/add_log': {
post: function () {
console.log(this.req.body);
this.res.writeHead(200, { 'Content-Type': 'application/json' });
@ephekt
ephekt / rb_array_iterate.rb
Created August 2, 2012 02:27
array iteration problem
def add1(arr, val, n)
# how many times are we going to increment
increment_count = n == 0 ? arr.length : n.abs
# are we going up or down the array
indices = n < 0 ? (-1..-arr.length) : (0...arr.length)
# iterate and update the array in place
indices.each do |index|
if (arr_value = arr[index]) == val
arr[index] = arr_value + 1
# decrement and check the count all in one go
@ephekt
ephekt / array_iteration.rb
Created August 2, 2012 02:20 — forked from DanKnox/array_iteration.rb
Array iteration interview question
def add1(arr, val, n)
stop = arr.length - 1
count = 0
(0..stop).each do |i|
index = n < 0 ? stop - i : i
if arr[index] == val
arr[index] += 1
@ephekt
ephekt / gist:2587605
Created May 3, 2012 17:56
asynchronous goofba
Asynch Recursion
setInterval(function(){ doStuff(); },100);
// bad... but better is this
(function loop(){
doStuff();
setTimeout(loop,100);
})();
@ephekt
ephekt / interval.js
Created April 25, 2012 20:02 — forked from manast/interval.js
Accurate Javascript setInterval replacement
function interval(duration, fn){
this.baseline = undefined
this.run = function(){
if(this.baseline === undefined){
this.baseline = new Date().getTime()
}
fn()
var end = new Date().getTime()
this.baseline += duration
@ephekt
ephekt / gist:1953043
Created March 1, 2012 20:33
Rewrite this using ghost methods, and any other fun variations you wish
=begin
The task: Rewrite this class in multiple ways (at least 2). Currently, on class
instantiation a bunch of methods are defined. What are some other ways you could
have written this and what are the trade-offs?
I'll give you one: You can rewrite this using ghost methods (method_missing)
and dynamically handle the method call. There are multiple variations in which
you can write/handle the method call so pick one or two and give it a shot.
For each variation you should note a pro and a con to the solution. For example,