Skip to content

Instantly share code, notes, and snippets.

@nvasilakis
nvasilakis / hex.py
Last active August 29, 2015 14:01
Encoding in Python
# + http://stackoverflow.com/questions/11826054/valueerror-invalid-literal-for-int-with-base-16-x0e-xa3-python
encodeByte(3, 42)
#-84
n = '\x03'
n
#'\x03'
len(n)
#1
int(n)
#Traceback (most recent call last):
package main
import "fmt"
func fmap( f (func(int) int), a []int) []int {
for i:= range a {
a[i] = f(a[i])
}
return a
}
#!env bash
# Xilinx tools: http://www.xilinx.com/support/documentation/boards_and_kits/xtp044.pdf
# Bluespec: http://www.bluespec.com/forum
# Xilix ISE:http://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/design-tools/v2012_4---14_6.html
# This is for bash -- if using interactively with zsh, consider
# setting sh_word_split on, or using $=<PARAM> instead of $PARAM
# TODO: Make sure all updates to $PATH are written to .${SHELL}rc
@nvasilakis
nvasilakis / 100.txt
Last active August 29, 2015 14:04
A synthetic memory allocation benchmark
1000 8 985 8 0
2000 0 999 0 0
3000 1 996 1 0
4000 14 981 14 0
5000 32 964 32 0
6000 40 955 40 0
7000 33 963 33 0
8000 39 956 39 0
9000 36 959 36 0
10000 36 960 36 0
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
@nvasilakis
nvasilakis / object.js
Created July 18, 2015 20:14
A mini tutorial on JavaScript objects and inheritance
/**
* A mini tutorial on JavaScript Object Inheritance
*
* API myPerson = person.create() creates a person object
* myPerson.id set/get ID
* myPerson.name set/get name
* myPerson.age set/get age
* myPerson.salute() return a salute (incl. name)
* person.staticSalute() returns a static salute (no name)
*
/*
A simple new-line delimited JSON protocol with upgrades.
Receiving Usage:
protocol = require('./frame-protocol');
// parsing data
parser = protocol.Parser();
@nvasilakis
nvasilakis / Dockerfile
Created January 10, 2017 05:49 — forked from christianberg/Dockerfile
Sharing a unix socket between a Docker container and it's host
FROM ubuntu
RUN apt-get update
RUN apt-get install -y socat
VOLUME /foo
CMD socat UNIX-LISTEN:/foo/bar.sock -
@nvasilakis
nvasilakis / memoize.js
Last active February 26, 2017 00:23
Cool prototype patching
function memoize(fun) {
// memoize a function with arbitrary arguments
var memo = {}
var name = fun.name || "anonymous";
return function memoize_fun() {
this.name = this.name + "__" + name;
var args = arguments;
var sargs = JSON.stringify(args);
if (memo[sargs]) {
return memo[sargs];
@nvasilakis
nvasilakis / cc.js
Created July 31, 2017 00:05
color-console.js
// http://stackoverflow.com/questions/7505623/colors-in-javascript-console
// https://github.com/adamschwartz/log
// color-console
(function() {
var exportedLog, ffSupport, formats, getOrderedMatches, hasMatches, isFF,
isIE, isOpera, isSafari, log, makeArray, operaSupport, safariSupport,
stringToArgs, _log;
if (!(window.console && window.console.log)) {
return;