Skip to content

Instantly share code, notes, and snippets.

geraldstanje / json_to_map.go
Created Sep 20, 2019 — forked from cuixin/json_to_map.go
json to map[string]interface{} example in golang
View json_to_map.go
package main
import (
func dumpMap(space string, m map[string]interface{}) {
for k, v := range m {
if mv, ok := v.(map[string]interface{}); ok {
geraldstanje /
Created May 29, 2018 — forked from jfarcand/
Fixing broken ngrep with OS X Mavericks

Migrating to OS X Mavericks breaks the ngrep utility. Doing:

sudo ngrep -d lo0 -q -W byline port 8080

stopped working where the process exits immediately. I didn't dig into the ngrep code, but was able to find a simple workaround by doing

sudo ngrep -q -W byline -d lo0 '' 'port 8080'

You can call that a lazy hack, but it work!

geraldstanje / kms-vault
Created Mar 8, 2018 — forked from hassy/kms-vault
Encrypt/decrypt files using AWS KMS
View kms-vault
#!/usr/bin/env bash
# License: MIT -
# Usage:
# Encrypt a file:
# kms-vault encrypt My-Key-Alias some-file-i-want-encrypted.txt > topsecret.asc
geraldstanje / Makefile
Created Mar 7, 2018 — forked from ryu1kn/Makefile
Encrypt/decrypt with AWS KMS
View Makefile
# How to encrypt/decrypt your text/blob secret with AWS KMS with AWS cli
SECRET_TEXT="my secret text"
DECRYPTED_SECRET_AS_BLOB=decrypted_secret_blob # Result of decrypt-blob target
View main.go
package main
import (
_ ""
View valsort.go
package main
import "fmt"
import "sort"
func main() {
m := map[string]int{
"One": 1,
"Two": 2,
"Three": 3,
View gist:1e03be27760582deaad9
1. Dining philosopher
2. Given a random number generator that returns a number between [0,1], how would you build a RNG that accounted for weighting?
3. You have two arrays with N integers in them. Merge those arrays using a recursive algorithm so that the integers in the final array are sorted.
4. generators(in python) and about minesweeper.
5. given a query and a document, highlight the query in the document and return a snippet of the document itself. Don't use existing large 3rd party libraries.
6. Finding the longest palindrome in a given string.
7. query log, and how to get the top K most frequent ones
8. Maximum subarray problem
9. Generate all permutations of an alphanumeric string (lowercase/uppercase only if a letter) 10. How can you improve the service of Y?
11. Pick a random number from weighted list based on weight
# Method one - w
w | head -n1 | cut -d":" -f4
# Method two - uptime
uptime | cut -d":" -f4- | sed s/,//g
# Method three - loads.d
sudo loads.d | awk '/./ { printf "%.2f %.2f %.2f\n", $7, $8, $9 }'

This example is the second of three in the Path Transitions tutorial; see the previous example for context.

The desired pairing of numbers for path interpolation is like this:

M x0, y0 L x1, y1 L x2, y2 L x3, y3 L xR, y4
   ↓   ↓    ↓   ↓    ↓   ↓    ↓   ↓
M xl, y0 L x0, y1 L x1, y2 L x2, y3 L x3, y4

Where xl is some negative value off the left side, and xr is some positive value off the right side. This way, the first point ⟨x0,y0⟩ is interpolated to ⟨xl,y0⟩; meaning, the x-coordinate is interpolated rather than the y-coordinate, and so the path appears to slide off to the left. Likewise, the incoming point ⟨xr,y4⟩ is interpolated to ⟨x3,y4⟩.

View responsive_d3_example.html
<!DOCTYPE html>
<script src=""></script>
<script src=""></script>
body {
font: 10px sans-serif;
rect {
You can’t perform that action at this time.