Skip to content

Instantly share code, notes, and snippets.

@sathish316
sathish316 / DropwizardAsyncResource.java
Created Feb 9, 2016
Dropwizard AsyncResponse usage
View DropwizardAsyncResource.java
package com.xyz.dw.resource;
import com.codahale.metrics.annotation.Timed;
import com.google.common.base.Optional;
import com.google.common.util.concurrent.SettableFuture;
import com.xyz.dw.model.Greeting;
import org.glassfish.jersey.server.ManagedAsync;
import rx.Observable;
import rx.schedulers.Schedulers;
View gist:5377340
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
# Resize Bindings - cmd+alt for resizing
bind right:alt;cmd resize +10% +0
bind left:alt;cmd resize -10% +0
bind up:alt;cmd resize +0 -10%
bind down:alt;cmd resize +0 +10%
View fileserver.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'haml'
require 'fileutils'
set :port, 25000
$pwd = ENV['PWD']
View rover_golf.rb
D,N,E,S,W,R,L,M=%w{NESW y+=1 x+=1 y-=1 x-=1 d+=1 d-=1 e.(D[d%4])}
r=->(x,y,d,s){e=->(a){eval eval(a)};s.scan(/./){|a|e.(a)};[x,y,D[d%4]]}
p r.(1,2,D.index('N'),"LMLMLMLMM")
p r.(3,3,D.index('E'),"MMRMMRMRRM")
@sathish316
sathish316 / alphametric_solver.rb
Created Sep 18, 2012
Alphametric solver golf
View alphametric_solver.rb
s=->(e){c=e.scan(/\w/).uniq;('0'..'9').to_a.permutation(c.size).each{|p|o=c.zip(p).inject(e){|e,d|e.gsub(*d)};p o if o !~/\b0/&&eval(o)}}
s.("SEND + MORE == MONEY")
View csv.rb
def show
@results = Foo.all
respond_to do |format|
format.csv { render_csv "report"}
end
end
private
def render_csv(filename = nil)
@sathish316
sathish316 / golbits.rb
Created May 17, 2012
Game of life bit twiddling
View golbits.rb
=begin
........ 0x00
........ 0x00
..XX.... 0x30
..XX.... 0x30
....XX.. 0xC0
....XX.. 0xC0
........ 0x00
........ 0x00
=end
@sathish316
sathish316 / gol.rb
Created Feb 9, 2012
Game of life golf
View gol.rb
d=[-1,0,1] n=->(w,i,j){(d.product(d)-[[0,0]]).map{|x,y|w[[i+x,j+y]]}.count(true)} t=->(w){Hash[w.map{|k,v|c=n.(w,*k);[k,(v&&c==2)||c==3]}]}
@sathish316
sathish316 / alphametric_solver.rb
Created Jan 29, 2012
Alphametric solver for equations like SEND + MORE = MONEY (Golf version)
View alphametric_solver.rb
def s(e)
c=e.scan(/\w{1}/).uniq
d=('0'..'9').to_a
d.permutation(c.size).each{|p|o=c.zip(p).inject(e){|e,d|e.gsub(*d)};return o if o !~/\b0/ && eval(o)}
end
puts s("SEND + MORE == MONEY")