Skip to content

Instantly share code, notes, and snippets.

@4poc
4poc / gist:10953895
Created April 17, 2014 04:57
Use reflection to invoke callbacks in mixins that use metadata as annotation.
@MirrorsUsed(symbols: '', override: '*')
import 'dart:mirrors';
class ReflectionHelper {
static callMethodsByAnnotation(var object, var symbol) {
var mirror = reflectClass(object.runtimeType);
mirror.instanceMembers.forEach((name, method) {
for (var metadata in method.metadata)
if (metadata.hasReflectee && metadata.reflectee == symbol)
reflect(object).invoke(name, []);
@4poc
4poc / gist:c279d24157af06d12cbe
Last active June 23, 2022 09:53
GOZORK Text Adventure Game
/**
* GOZORK Text Adventure Game
* by apoc <http://apoc.cc>
*
* Inspired by the infamous beginning of Zork I.
* Reading the source will obviously spoil the game.
* The goal is to somehow kill the troll.
* Oh yeah and: This is my first GO program! Which would be
* my perfect excuse for the bad code quality1!
* Here is a solution/transcript:
@4poc
4poc / gist:5d90091db803f52b618d
Last active August 29, 2015 14:03
GO IRC Bot
package main
import (
"bufio"
"crypto/tls"
"fmt"
"io"
"net"
"reflect"
"regexp"
@4poc
4poc / gist:9c67a8ff27b429559986
Created September 19, 2014 00:49
Simplex noise in D (ported from java, DLang)
/**
* Simplex noise algorithm.
*
* This is a port of the public domain java implementation (see
* original header) and is public domain aswell.
* ported by Matthias Hecker <apoc.cc>.
* Links:
* http://webstaff.itn.liu.se/~stegu/simplexnoise/
* http://stackoverflow.com/a/18516731
*/

Keybase proof

I hereby claim:

  • I am 4poc on github.
  • I am apoc (https://keybase.io/apoc) on keybase.
  • I have a public key whose fingerprint is 6FCC 1EF0 3B42 A155 CE89 4962 C6E6 8A99 721F BC1E

To claim this, I am signing this object:

foo = {
'nested': {
'dict': 42
}
}
query = 'nested.dict'
# reduce:
from functools import reduce
@4poc
4poc / bintest.js
Created October 11, 2016 09:33
Buffer Schema Type in Mongoose: How to specify subtype
'use strict';
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ObjectId = Schema.Types.ObjectId;
const MongooseBuffer = mongoose.Types.Buffer;
const uuid = require('node-uuid');
const db = require('../lib/database');
// immutable object assignment:
const initialState = { products: {} };
export default function reducer(state = initialState, action = {}) {
switch (action.type) {
case PUT_PRODUCT:
return { ...state, products: { ...state.products, [action.product.id]: action.product } };
default:
return state;
}
}
@4poc
4poc / gist:6b41291bb1eef8f9720fa5344c4d8600
Last active November 4, 2016 12:36
Local SSL/TLS Sniffing
# Route local connections to the remote target to localhost port 4440:
iptables -t nat -A OUTPUT -p tcp --dport 443 -d [REMOTE_HOST] -j DNAT --to-destination 127.0.0.1:4440
# Route local connections to port 4441 to the original target:
iptables -t nat -A OUTPUT -p tcp --dport 4441 -d 127.0.0.1 -j DNAT --to-destination [REMOTE_HOST]:443
# Use sslsplit to proxy connections inbetween and save plaintext contents:
sslsplit -D -l connections.log -S logs -k ca.key -c ca.crt https 127.0.0.1 4440 127.0.0.1 4441
@4poc
4poc / wifibot.py
Last active December 1, 2016 10:45
#!/usr/bin/python
# Wifibot: Read station dumps from a router and shows new/dropped wifi clients in a matrix channel
# by john & matthias
import re
import sys
import time
import subprocess
import requests # pip install requests
from threading import Thread