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 fileserver.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'haml'
require 'fileutils'
set :port, 25000
$pwd = ENV['PWD']
@sathish316
sathish316 / oneplus.scala
Last active Sep 20, 2015
Generate email ids for oneplus registration based on an amazon review (http://www.amazon.in/review/REA7WFX7PV3KO)
View oneplus.scala
object OnePlus {
def main(args: Array[String]) {
generate_aliases("typeyouremailhere@gmail.com").foreach(println)
}
def generate_aliases(email:String) = {
val email_pattern = """(\w+)@([\w\.]+)""".r
email match {
case email_pattern(address, domain) => {
interleave_all_with(address, '.').map {case address => s"$address@$domain"}
@sathish316
sathish316 / snakes_and_ladders.ex
Last active Sep 14, 2015
Snakes and Ladder - Elixir Game server
View snakes_and_ladders.ex
defmodule GameServer do
use GenServer
def start do
initial_state = {:players, [], :positions, Map.new, :snakes_and_ladders, [
{:ladder, 5, 15}, {:ladder, 10, 22}, {:ladder, 25, 45}, {:snake, 35, 15}, {:snake, 65, 55}]}
GenServer.start_link(__MODULE__, initial_state, name: __MODULE__)
end
def join(player), do: GenServer.cast(__MODULE__, {:join, player})
View init-scala.sh
#!/bin/bash
PROJECT_NAME="$1"
SCALA_VERSION="2.10.3"
SCALATEST_VERSION="2.2.1"
MOCKITO_VERSION="1.8.5"
mkdir $PROJECT_NAME
cd $PROJECT_NAME
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 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)