Skip to content

Instantly share code, notes, and snippets.

@yarinb
yarinb / .osx.sh
Created July 29, 2012 12:04
OSX For Hackers - ML edition
# ~/.osx — http://mths.be/osx
###############################################################################
# General UI/UX #
###############################################################################
# Set computer name (as done via System Preferences → Sharing)
scutil --set ComputerName "MathBook Pro"
scutil --set HostName "MathBook Pro"
scutil --set LocalHostName "MathBook-Pro"
@yarinb
yarinb / SecretResource.java
Created June 22, 2012 18:49
Simple authentication for jax-rs resources
@Path("/secret")
public class SecretResource {
@GET
@Path("/secured")
public String showSecret(@Auth User user) {
return "Hello " + user.getUsername() + ". This is secret!";
}
@yarinb
yarinb / ServerFactory.java
Created June 1, 2012 08:11
add SessionManager to Dropwizard's Jetty
private Handler createExternalServlet(ImmutableMap<String, ServletHolder> servlets,
ImmutableMultimap<String, FilterHolder> filters,
ImmutableSet<EventListener> listeners) {
// set ServletContextHandler.SESSIONS option
final ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
// set a default SessionHandler
handler.setSessionHandler(new SessionHandler());
handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
handler.setBaseResource(Resource.newClassPathResource("."));
@yarinb
yarinb / gist:2727648
Created May 18, 2012 21:18
Rspec stubs are bad practice
require 'rspec/mocks/standalone'
class Service
def self.access_thirdparty_action
puts "communicating with the world!"
end
end
class ServiceManager
@yarinb
yarinb / database.yml.erb
Created May 2, 2012 09:35
Elegant (??) solution to database.yml passwords
# Since you already have ssh keypair on your deployment host, you may use it to decrypt
# database credentials at load time.
#
# The solution can be tweaked a bit to decrypt with capistrano at deployment time.
# In case where the private key is passphrase protected this won't work but it's pretty straight forward to fix it.
#
# Hope it's a nice starting point for a more mature solution.
#
# --Yarin
@yarinb
yarinb / gist:2510013
Created April 27, 2012 15:07
has_many :through
class User < ActiveRecord::Base
attr_accessible :name
has_many :bookings
has_many :events, :through => :bookings
end
class Event < ActiveRecord::Base
attr_accessible :title
@yarinb
yarinb / hack.sh
Created March 31, 2012 10:27 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@yarinb
yarinb / gist:2071032
Created March 18, 2012 12:13
LUA IS AWESOME
require "reactor"
require "net"
local buffer = {}
local server = net:server(function(c)
print("connected", c)
c:on("end", function()
print("disconnected")
end)
@yarinb
yarinb / jobs.json
Created January 8, 2012 09:35
XML vs. JSON?
{
"jobs":[
{
"jobname":"ServerPingJob.groovy",
"period":5,
"timeUnit":"SECONDS",
"jobMode":"ASYNCHRONOUS",
"disabled":true,
"params":[
{
@yarinb
yarinb / gist:1389255
Created November 23, 2011 17:15
compass config in config/compass.rb
# This configuration file works with both the Compass command line tool and within Rails.
# Require any additional compass plugins here.
project_type = :rails
sass_options = {:debug_info => true}
# Set this to the root of your project when deployed:
http_path = "/"
# You can select your preferred output style here (can be overridden via the command line):