Skip to content

Instantly share code, notes, and snippets.

View tifletcher's full-sized avatar

Themba Fletcher tifletcher

  • CrunchBase
  • San Francisco, CA
View GitHub Profile

Build api responses. Hides the generic parameter behind the static method invocation.

@tifletcher
tifletcher / TypeCoersionJava.md
Last active September 23, 2015 06:41
Type Coercion for Java

Type Coercion for Java using Jackson

Obsolete. Use MAPPER.convertValue() instead

It's not quite as nice as C#'s as but it works well enough. Uses jackson serialization as a bridge between types, so make sure your types are annotated appropriately for (de)serialization. Jackson throws lots of detailed and potentially useful exceptions -- these are caught and made obscure by returning null instead.

Usage

Bar bar = new Bar();
@tifletcher
tifletcher / Cors.java
Created June 8, 2015 19:37
dropwizard CORS
package com.foo.bar.baz; //steal from FooApplication.java
import io.dropwizard.setup.Environment;
import org.eclipse.jetty.servlets.CrossOriginFilter;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import java.util.EnumSet;
public class Cors {
@tifletcher
tifletcher / gist:c919a20bc6a8059d0a57
Created May 18, 2015 20:53
unlimited bash history (@thabofletcher, @polynickglot)
# Undocumented feature which sets the size to "unlimited".
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%y%m%d %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
@tifletcher
tifletcher / euler.js
Created March 4, 2015 19:32
simple javascript generator without yield
// Project Euler problem 2
function makeFibSequence(a, b) {
// or ...
// var a = 0;
// var b = 1;
return function () {
var next = a + b;
a = b;
b = next;
return next;
@tifletcher
tifletcher / extract_hrefs_from_tab_outliner.js
Created June 23, 2014 16:00
get all saved tabs from Tabs Outliner in chrome
var makeArray = function (arrayLike) {
return Array.prototype.slice.call(arrayLike)
}
var mapNodes = function (fn, selector) {
var nodes = makeArray(document.querySelectorAll(selector))
nodes.forEach(function (el) {
el.href.match(/^http/) && fn(el.href)
})
// moved to https://github.com/tifletcher/backbone-event-spy
@tifletcher
tifletcher / update_canary.sh
Created February 10, 2014 20:29
chrome canary for linux
#!/bin/bash
#
# Update to latest chromium nightly on linux
# Script requires root to properly set up the sandbox
# https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment
#
# I use it with a line like the following in my .bashrc:
# alias canary='CHROME_DEVEL_SANDBOX="/home/tif/bin/chrome-linux/chrome_sandbox" /home/tif/bin/chrome-linux/chrome-wrapper'
#
# ----------------------------------------------------------------------
@tifletcher
tifletcher / gist:7113132
Last active December 26, 2015 07:09
Look at main() -- what's interesting is the three different ways of defining the bound value. This won't compile of course ...
object QuadraticPrimes {
import Primes._
def makeQuad(a: Int, b: Int): Int => Int =
(n: Int) => (n * n) + (a * n) + b
def primesLength(a: Int, b: Int): Int = {
val f = makeQuad(a, b)
Stream.from(0).takeWhile((x) => isPrime(f(x))).toList.length
}
@tifletcher
tifletcher / push_testing.sh
Created October 8, 2013 06:44
better sync
#!/bin/bash
DESTINATION='halbeta'
TARGETS=(
'www/haldeman'
'www/public_html'
)
echo Destination: $DESTINATION
echo Syncing ...