Skip to content

Instantly share code, notes, and snippets.

@peekg
peekg / MockRequestHandler.java
Created September 2, 2015 15:41
Test class for mocking HttpClient requests
class MockRequestHandler extends RequestHandler {
private GetMethod mockGetMethod;
private HttpClient mockHttpClient;
public MockRequestHandler(int responseStatus,
byte[] responseBody) throws HttpException, IOException,
SecurityException, IllegalArgumentException,
NoSuchMethodException, IllegalAccessException,
InvocationTargetException {
@peekg
peekg / git_list_remote_branches.sh
Created April 11, 2016 19:12
git - list remote branches with commit by $USER
#!/bin/bash
HEAD=origin
if [ -n "$1" ]; then
HEAD=$1
fi
CURRENT_IFS=$IFS
IFS=$'\n'
@peekg
peekg / immutable.map.loop
Created June 7, 2018 17:50
immutable.js iterate map
//@flow
type Props = {
name: string
}
type MyRecord = RecordOf<Props>
type MyMap = Map<MyRecord,List<number>>
const create: MyRecordFactory<Props> = Record({name:""});
const myMap = Map().set(create({name:"hi"}), List([1]) )
//example 1
const arr = Seq(myMap.entries()).reduce( (list, map) => {
@peekg
peekg / tree.js
Last active September 14, 2019 01:59
Convert a list of paths, into an immutable map of maps (tree structure)
(() => {
const {Map, List} = require("immutable")
const list = List(
["archives",
"archives/arts",
"archives/history" ])
const tree = list.reduce( (map, it) => map.setIn( it.split( "/" ), Map() ), Map() )
@peekg
peekg / record.js
Created September 16, 2019 14:30
Immutable Record with an immutable List member
(() => {
const {List, Record} = require("immutable")
class Foo extends Record({ list: List() }) {
constructor( props ) {
const inst = super( props )
const list = inst.get( "list" )
if( list instanceof Array ) {
return inst.set( "list", List( list ) )
}
if( !List.isList( list ) ) { throw new Error ( "List member should be type List, or Array" ) }