Skip to content

Instantly share code, notes, and snippets.

View spencerwi's full-sized avatar

Spencer Williams spencerwi

View GitHub Profile
@spencerwi
spencerwi / Java8Demo.java
Created February 21, 2014 15:21
Quick demo playing with Java 8 streams, lambdas, and aggregate operations.
import java.util.List;
import java.util.ArrayList;
import java.util.stream.*;
import java.util.Comparator;
import java.util.Collections;
import java.util.Optional;
import java.util.Random;
class Java8Demo {
private static final String[] poolOfFirstNames = { "Joe", "Paul", "John", "Samantha", "Amanda", "Karen" };
@spencerwi
spencerwi / ips.cl
Created January 19, 2015 02:55
Quick util to print out the IP addresses on a machine. Requires Quicklisp.
(ql:quickload :ip-interfaces)
(defun ip-as-string (interface)
(format nil "~{~A~^~.~}" (map 'list (lambda (x) x) (ip-interfaces:ip-interface-address interface))))
(defun print-interface-ip (interface)
(format t "~A: ~A~%" (ip-interfaces:ip-interface-name interface) (ip-as-string interface)))
(loop for interface in (ip-interfaces:get-ip-interfaces)
do (print-interface-ip interface))
@spencerwi
spencerwi / propsToEnvVars.hs
Last active August 29, 2015 14:14
Convert Java properties to environment variables (naively)
#!/usr/bin/env runhaskell
module JavaPropsToEnvVars where
import Data.List (break, stripPrefix)
type PropertyName = String
type PropertyValue = String
type Property = (PropertyName, PropertyValue)
@spencerwi
spencerwi / tmux.conf
Last active August 29, 2015 14:16
tmux.conf
#Colors
BACKGROUND=black
FOREGROUND=white
setw -g status-bg $BACKGROUND
setw -g status-fg $FOREGROUND
setw -g window-status-current-bg $FOREGROUND
setw -g window-status-current-fg $BACKGROUND
set -g pane-active-border-bg default
set -g pane-active-border-fg $FOREGROUND
@spencerwi
spencerwi / ips.ml
Last active September 9, 2015 02:11
Get IPs in OCaml (using only stdlib)
module StringSet = Set.Make(String)
let addr_to_string = function
| Unix.ADDR_UNIX s -> s
| Unix.ADDR_INET (iaddr, _) -> Unix.string_of_inet_addr iaddr
let get_local_ips () =
Unix.getaddrinfo "localhost" "" []
|> List.map (fun x -> x.Unix.ai_addr)
@spencerwi
spencerwi / gist:4180430
Created December 1, 2012 03:30
Python vimrc options
filetype plugin indent on
syntax on
set autoindent
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab
let person = filter (\x -> name x == "John Smith") people
age dob = getCurrentTime >>= return . (\now -> (diffDays now dob) `div` 365) . utctDay
in
[name person, dob person, age (dob person)]
SELECT
Name, DoB, (current_date - DoB) as Age
FROM
People
WHERE
Name = 'John Smith'
;
// BAD:
List<PersonEntity> pes = someFetcherFunction.findByAgeGreaterThan(18);
if (pes.contains(currentPE)) { return "Hello, sir/madam."; }
else { return "This method is for adults only!"; }
// GOOD:
static Integer LEGAL_ADULTHOOD_AGE = 18; // in class PersonEntity
//...
List<PersonEntity> attendees = conference.getAttendees();
Collections.sort(new Comparator<PersonEntity> {
@Override
public int sort(PersonEntity person1, PersonEntity person2) {
Date person1ArrivalDate = person1.getArrivalDate(),
person2ArrivalDate = person2.getArrivalDate();
if (person1ArrivalDate == null) person1ArrivalDate = DEFAULT_ARRIVAL_DATE;
if (person2ArrivalDate == null) person2ArrivalDate = DEFAULT_ARRIVAL_DATE;
int comparisonByArrivalDateResult = person1ArrivalDate.compareTo(person2ArrivalDate);
if (comparisonByArrivalDateResult == 0) {