Skip to content

Instantly share code, notes, and snippets.

View schmohlio's full-sized avatar

Matthew Schmohl schmohlio

View GitHub Profile
@schmohlio
schmohlio / build_diagnostic.log
Created January 27, 2016 14:52
vim-sharp logs
XBuild Engine Version 12.0
Mono, Version 4.2.0.0
Copyright (C) 2005-2013 Various Mono authors
Loading default tasks for ToolsVersion: 4.0 from /usr/local/Cellar/mono/4.2.0.179/lib/mono/4.5/Microsoft.Common.tasks
Build started 1/27/2016 9:48:30 AM.
__________________________________________________
Extension path '/Library/Frameworks/Mono.framework/External/xbuild' not found, ignoring.
Extension path '/Library/Frameworks/Mono.framework/External/xbuild' not found, ignoring.
Project "MYPROJECT.fsproj" (default target(s)):
@schmohlio
schmohlio / remove_empty_part_files.sh
Last active May 3, 2017 06:22
delete or warn on empty part files in hadoop, by extension.
#!/bin/bash -e
""" USAGE: ./remove_empty_part_files.sh <qualified hdfs dir path> """
HDFS=$1
echo "checking for empty files in $HDFS..."
IFS=$'\n'
for i in `hadoop fs -ls $HDFS/* | grep -e "$HDFS/.*" | awk '{print $0}'` ; do
file=$(echo $i | awk '{print $8}')
size=$(echo $i | awk '{print $5}')
if [ $size -eq 0 ]; then
@schmohlio
schmohlio / JsonFlatten.fs
Created April 29, 2016 03:38
flatten Json to arrays and primitive types
open Newtonsoft.Json
let rec private _flattenJson (delim:string) (pkey:string) (json:JsonValue): (string * JsonValue) seq =
json.Properties
|> Seq.collect (fun (k, v) ->
match v with
| JsonValue.Record r -> _flattenJson delim k (JsonValue.Record r)
| _ -> [(pkey + delim + k, v)] |> Seq.ofList
)
/// flatten a Json nested children and stop at primitive or Array. specify delimiter for nested key names.
@schmohlio
schmohlio / Json2JavaMap.scala
Created July 18, 2016 23:34
parse Json to Generic Java Map in Scala, similar to Jackson.
import com.google.gson.Gson
import java.util.{Map => JMap, LinkedHashMap}
type GenericDecoder = String => JMap[String, Object]
val decoder: GenericDecoder = {
// Gson instances are apparently thread-safe, so curry...
val gson: Gson = new Gson()
// LinkedHashMap preserves ordering. use HashMap if not required.
x => gson.fromJson(x, (new LinkedHashMap[String, Object]()).getClass)
@schmohlio
schmohlio / sortByteSlice.go
Created September 7, 2016 21:37
sort byte slices in Golang without needing to fmt as string. useful for Set hashes
package main
import (
"bytes"
"log"
"sort"
)
// implement `Interface` in sort package.
type sortByteArrays [][]byte
@schmohlio
schmohlio / sse.go
Last active August 21, 2024 05:00 — forked from ismasan/sse.go
Example SSE server in Golang
// v2 of the great example of SSE in go by @ismasan.
// includes fixes:
// * infinite loop ending in panic
// * closing a client twice
// * potentially blocked listen() from closing a connection during multiplex step.
package main
import (
"fmt"
"log"
@schmohlio
schmohlio / FriendCircles.java
Created January 18, 2017 22:10
"friend circles" brain teaser
package io.schmohl;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class FriendCircles {
/*
@schmohlio
schmohlio / StringChains.java
Created January 18, 2017 22:11
"String Chains" brain teaser
package io.schmohl;
import java.util.*;
public class StringChain {
// we can use depth first search for each word to calculate the length of the chain.
static int longestChain(String[] words) {
@schmohlio
schmohlio / BlockingQueue.java
Created February 16, 2017 05:04 — forked from dougnukem/BlockingQueue.java
Example Threadsafe BlockingQueue implementation in Java
public class BlockingQueue implements Queue {
private java.util.Queue queue = new java.util.LinkedList();
/**
* Make a blocking Dequeue call so that we'll only return when the queue has
* something on it, otherwise we'll wait until something is put on it.
*
* @returns This will return null if the thread wait() call is interrupted.
*/
@schmohlio
schmohlio / gist:4157d2fa82f3680fd08f1b111ed61515
Created April 10, 2017 03:16 — forked from mikepfeiffer/gist:4d9386afdcceaf29493a
EC2 UserData script to install CodeDeploy agent
#!/bin/bash
yum install -y aws-cli
cd /home/ec2-user/
aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' . --region us-east-1
yum -y install codedeploy-agent.noarch.rpm