Skip to content

Instantly share code, notes, and snippets.

@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 / arithmetic.py
Created December 1, 2019 14:02 — forked from adamnew123456/arithmetic.py
Pratt Parser For Arithmetic Expressions
"""
This implements a fairly simple expression language via a Pratt-style parser.
The language supports fairly standard floating point literals, such as:
5
1.09
.16
12e7
  • 🎨 when improving the format/structure of the code
  • 🚀 when improving performance
  • ✏️ when writing docs
  • 💡 new idea
  • 🚧 work in progress
  • ➕ when adding feature
  • ➖ when removing feature
  • 🔈 when adding logging
  • 🔇 when reducing logging
  • 🐛 when fixing a bug
@yarinb
yarinb / styles.less
Created December 3, 2016 23:06 — forked from brandondurham/styles.less
Using Operator Mono in Atom
/**
* Using Operator Mono in Atom
*
* 1. Open up Atom Preferences.
* 2. Click the “Open Config Folder” button.
* 3. In the new window’s tree view on the left you should see a file called “styles.less”. Open that up.
* 4. Copy and paste the CSS below into that file. As long as you have Operator Mono SSm installed you should be golden!
* 5. Tweak away.
*
* Theme from the screenshot (http://cdn.typography.com/assets/images/blog/operator_ide2.png):
@yarinb
yarinb / config
Created December 21, 2012 20:19
Reuse SSH sessions
# put this in ~/.ssh/config
Host *
Compression yes
CompressionLevel 7
Cipher blowfish
ServerAliveInterval 600
ControlMaster auto
ControlPath /tmp/ssh-%r@%h:%p
@yarinb
yarinb / solve.rb
Created October 27, 2012 21:24
scrabble solve
#!/usr/bin/env ruby
dict = File.open('/usr/share/dict/words', 'r').read
letters = ARGV[0] unless ARGV.empty?
def can_make?(word, letters)
return letters.include? word if word.size == 1
letters.include? word[0] and
can_make?(word[1..-1], letters.sub(/#{word[0]}/, ""))
end
@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 / 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