Skip to content

Instantly share code, notes, and snippets.

peekg

Block or report user

Report or block peekg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@peekg
peekg / record.js
Created Sep 16, 2019
Immutable Record with an immutable List member
View record.js
(() => {
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" ) }
@peekg
peekg / tree.js
Last active Sep 14, 2019
Convert a list of paths, into an immutable map of maps (tree structure)
View tree.js
(() => {
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 / immutable.map.loop
Created Jun 7, 2018
immutable.js iterate map
View immutable.map.loop
//@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 / git_list_remote_branches.sh
Created Apr 11, 2016
git - list remote branches with commit by $USER
View git_list_remote_branches.sh
#!/bin/bash
HEAD=origin
if [ -n "$1" ]; then
HEAD=$1
fi
CURRENT_IFS=$IFS
IFS=$'\n'
@peekg
peekg / MockRequestHandler.java
Created Sep 2, 2015
Test class for mocking HttpClient requests
View MockRequestHandler.java
class MockRequestHandler extends RequestHandler {
private GetMethod mockGetMethod;
private HttpClient mockHttpClient;
public MockRequestHandler(int responseStatus,
byte[] responseBody) throws HttpException, IOException,
SecurityException, IllegalArgumentException,
NoSuchMethodException, IllegalAccessException,
InvocationTargetException {
You can’t perform that action at this time.