Skip to content

Instantly share code, notes, and snippets.

View sktt's full-sized avatar

Johannes Wikner sktt

View GitHub Profile
@sktt
sktt / task_runner.js
Last active November 27, 2016 13:05
This is a pretty clean way to run sync and async tasks using Promise and a reducer func
module.exports = run
// Run tasks in sequence or async can be done in a very expressive way using
// Promise and a reducer
function run(tasks) {
return tasks.reduce(
(acc, task) => acc.then(lastResult => {
if (typeof task === 'function') {
// A task is a function that takes a result from a previous task and returns
// a promise executor function
@sktt
sktt / promisify.js
Last active July 29, 2016 01:51
Tiny promisify function
/**
* Promisify a node style async func.
*
* @param {function} f Function to with a node callback as its last argument.
* @param [{object}] scope Scope to run `f` in, if necessary.
* @return {Promise}
*
* @example ```
* const read = promisify(fs.readFile, fs);
* read('./file')

Keybase proof

I hereby claim:

  • I am sktt on github.
  • I am jwknr (https://keybase.io/jwknr) on keybase.
  • I have a public key whose fingerprint is 978C 6F9A 69CB CE2F 915D AD0A 5846 66DF 8F0E AAF4

To claim this, I am signing this object:

@sktt
sktt / keystone_hacks.js
Last active September 4, 2017 01:17
How to add support for pre updateItem hook for keystone.List.
// Naturally this has to be done before creating List instances!!
// monkey patching List constructor to add hooks support
(function () {
var grappling = require('grappling-hook');
var List = keystone.List;
keystone.List = function (name, options) {
List.apply(this, arguments);
@sktt
sktt / 130717 redux_rxjs.md
Last active September 30, 2017 18:40
Simple state mgmt using rxjs for redux fans
date title descr
Thu 13 Jul 2017 10:41:19 AM CEST
Roll your own redux
Simple state mgmt using rxjs for redux fans

Roll your own redux

using rxjs

@sktt
sktt / newmac
Last active September 4, 2017 01:12
Generates a new mac address. You know why it's useful :)
#!/bin/sh
set -e
IF=$1
if [ -z "$IF" ] ; then
echo "Usage: $0 <interface>"
exit 1
fi
ifconfig $IF > /dev/null # stop execution if the interface doesn't exist
@sktt
sktt / websocket.js
Last active October 12, 2017 22:25
Skeleton code for setting up a websocket server, with a route for piping stdin to the websocket. So you could for instance do `ping google.com | node websocket.js` and maybe plot the results in the browser.... :D
const URL = require('url')
const Rx = require('rxjs/Rx')
const WebSocketServer = require('ws').Server
/** pipe stdin out on websocket */
function pipe (conn) {
process.stdin.setEncoding('utf8')
return Rx.Observable.create(obs => {
process.stdin.on('data', obs.next.bind(obs))
@sktt
sktt / list.c
Created May 11, 2018 16:27
1337 lists... kernel style
#include <stdio.h>
/* 1337 linked list, kernel style */
#define MEMBER_OFFSET(type, member) \
(unsigned long)(&(((type *)0)->member))
#define LIST_ENTRY(ptr, type, member) \
((type *)(((char *)(ptr)) - MEMBER_OFFSET(type, member)))
#define LIST_INIT(list) \
(list).next = &(list);\
sudo apt-get update
sudo apt-get install build-essential curl libz3-dev z3 libboost-dev libcapstone-dev libpython-dev cmake python-z3
curl -L http://software.intel.com/sites/landingpage/pintool/downloads/pin-2.14-71313-gcc.4.4.7-linux.tar.gz| tar xzf -
cd pin-2.14-71313-gcc.4.4.7-linux/source/tools/
curl -L https://github.com/JonathanSalwan/Triton/archive/v0.4.tar.gz | tar xzf -
cd Triton-0.4/
mkdir build
cd build
cmake -DPINTOOL=on -DKERNEL4=on ..
make -j4
@sktt
sktt / android.sh
Last active September 13, 2018 13:21
all the stuff without any android-studio!
# make sure to not have conflicts..
sudo apt remove android-sdk{,-platform-tools,-build-tools} adb
sudo apt autoremove
mkdir ~/GREEN_LAB
cd ~/GREEN_LAB
# https://developer.android.com/studio/#command-tools
wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip -O android-sdk-tools.zip