Skip to content

Instantly share code, notes, and snippets.

View kitallis's full-sized avatar
🍣

Akshay Gupta kitallis

🍣
View GitHub Profile
@kitallis
kitallis / temporary-path-carrierwave.rb
Created December 19, 2013 06:28
create a temporary path for a file in carrierwave, location agnostic - s3/local, so it'll work with tests
def temporary_path
file = Tempfile.new(['temp-creative-image-', ['.', self.image.file.extension].join], :encoding => 'ascii-8bit')
file.write(image.read) if image.file.exists?
file.path
end
@kitallis
kitallis / mars-rover.clj
Created November 9, 2013 21:15
neena and kitallis delve into clj
(ns mars-rover.core)
;
; first: grid size
;
; rest: pairs of 2 lines each, containing rover agenda.
; 1st line for pair:
; rover starting position on the grid
; 2nd line for pair:
; all instructions to move
#!/usr/bin/env bash
# brew install flac
# this gives you flac2mp3
# mkdir ~/scripts
# vim flac2mp34all
for f in *.flac; do
flac2mp3 "$f" v0 && rm "$f"
@kitallis
kitallis / prepend_method.rb
Created February 27, 2013 07:40
Module#prepend replacing :alias_method
class Earphone
def left
puts "Playing on left."
play(0)
end
def right
puts "Playing on right."
play(1)
end
$ git bisect start
$ git checkout recent_known_buggy_commit
$ git bisect bad
$ git checkout old_known_good_commit
$ git bisect good
# run tests, check things, etc.
$ git bisect good/bad
Repeat last two steps until git finds the first bad commit. Then:
@kitallis
kitallis / test_mustache_compilation_engines.rb
Last active October 10, 2015 20:28
benchmarks for .} compilation engines, re-using a spec from temple-mustache
require 'bacon'
require 'temple'
require 'temple/mustache'
require 'benchmark'
require 'musterb'
require 'mustache'
require 'erubis'
class Bacon::Context
@kitallis
kitallis / migration.rake
Created August 28, 2012 15:12
rebase migrations
namespace :migrations do
DB_PATH = ActiveRecord::Migrator.migrations_path
SEPARATOR = " --- "
UPTO = ENV['upto']
def run_command(command)
%x(#{command}).tap do |result|
status = $?
unless status.success?
raise "Command Error -- (#{status.exitstatus}): [#{command}]"
@kitallis
kitallis / raskell.rb
Created August 16, 2012 14:32 — forked from andkerosine/raskell.rb
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@kitallis
kitallis / newal.rb
Created July 27, 2012 07:45
override instance_eval()
class Object
alias :old_instance_eval :instance_eval
def instance_eval(str, *args)
throw :evaling, [true, old_instance_eval(str)]
end
end
$result = catch(:evaling) do
<%= user_code %>
@kitallis
kitallis / newal.rb
Created July 22, 2012 03:02
override inner eval()
module Newal
def eval(str)
throw :evaling, [true, Kernel.eval(str)]
end
end
class << self
include Newal
end