Skip to content

Instantly share code, notes, and snippets.

@willurd
willurd / web-servers.md
Last active July 26, 2024 13:45
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@suxue
suxue / Makefile.am.coverage
Created August 4, 2014 07:11
autoconf common files
# Coverage targets
if HAVE_GCOV
.PHONY: clean-gcda
clean-gcda:
@echo Removing old coverage results
-find -name '*.gcda' -print | xargs -r rm
.PHONY: coverage-html generate-coverage-html clean-coverage-html
@suxue
suxue / .gitignore
Last active August 29, 2015 14:05
qemu qcow2 format kernel testing image
linux.img
.lock
record
.gdbinit
@freemo
freemo / TitanGods.java
Last active March 22, 2018 03:23
Example for working with TitanGraph
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.TitanKey;
import com.thinkaurelius.titan.core.attribute.Geoshape;
import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.ElementHelper;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
@hyper0x
hyper0x / tcp_demo.go
Last active August 15, 2023 12:34
The interaction demo via TCP in Golang.
package main
import (
"bufio"
"bytes"
"fmt"
"io"
"log"
"net"
"os"
@joar
joar / jq-insert-var.sh
Last active July 25, 2024 00:55
Add a field to an object with JQ
# Add field
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
# {
# "hello": "world",
# "foo": "bar"
# }
# Override field value
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
{
@EthanRosenthal
EthanRosenthal / ExplicitMF_ALS.py
Created March 13, 2016 20:38
Class for ALS training of an explicit matrix factorization model
from numpy.linalg import solve
class ExplicitMF():
def __init__(self,
ratings,
n_factors=40,
item_reg=0.0,
user_reg=0.0,
verbose=False):
"""
@msmfsd
msmfsd / es7-async-await.js
Last active February 4, 2024 17:38
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@dusenberrymw
dusenberrymw / spark_tips_and_tricks.md
Last active June 28, 2024 12:37
Tips and tricks for Apache Spark.

Spark Tips & Tricks

Misc. Tips & Tricks

  • If values are integers in [0, 255], Parquet will automatically compress to use 1 byte unsigned integers, thus decreasing the size of saved DataFrame by a factor of 8.
  • Partition DataFrames to have evenly-distributed, ~128MB partition sizes (empirical finding). Always err on the higher side w.r.t. number of partitions.
  • Pay particular attention to the number of partitions when using flatMap, especially if the following operation will result in high memory usage. The flatMap op usually results in a DataFrame with a [much] larger number of rows, yet the number of partitions will remain the same. Thus, if a subsequent op causes a large expansion of memory usage (i.e. converting a DataFrame of indices to a DataFrame of large Vectors), the memory usage per partition may become too high. In this case, it is beneficial to repartition the output of flatMap to a number of partitions that will safely allow for appropriate partition memory sizes, based upon the