Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@4poc
4poc / LimitStream.js
Created December 10, 2011 03:41
Node.js: LimitStream (Bandwidth limited Readable+Writable Stream)
var fs = require('fs'),
util = require('util'),
Stream = require('stream').Stream;
/**
* Create a bandwidth limited stream
*
* This is a read+writeable stream that can limit how fast it
* is written onto by emitting pause and resume events to
* maintain a specified bandwidth limit, that limit can
@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:6281388
Last active July 1, 2021 13:53
Minecraft supports querying the MOTD, player count, max players and server version via the usual port, this ruby class implements this. Works with ruby >= 1.9.3/2.0.0
require 'socket'
##
# Pings a minecraft server and returns motd and playercount.
# Works with ruby >=1.9.3/2.0.0
#
# More information and sample code here:
# http://wiki.vg/Server_List_Ping
##
class MinecraftPing
@4poc
4poc / gist:3155033
Created July 21, 2012 07:56
C++11 variadic template printf with boost::format
#include <boost/format.hpp>
void LogMessage(boost::format& message) {
std::cout << message.str() << std::endl;
}
template<typename TValue, typename... TArgs>
void LogMessage(boost::format& message, TValue arg, TArgs... args) {
message % arg;
LogMessage(message, args...);
@4poc
4poc / gist:3155832
Created July 21, 2012 13:30
C++11 Callbacks with function and lambda
#include <iostream>
#include <vector>
#include <functional>
class WorkingClass {
public:
typedef const std::function<void (int)> handler_t;
void AddHandler(handler_t& h) {
handlerList.push_back(&h);
}
@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');
@4poc
4poc / gist:1565186
Created January 5, 2012 13:06
ffmpeg / mpeg-ts / m3u8 / HLS
ffmpeg \
-i INPUT_FILE \
-re \
-r 23.976 \
-s 480x204 \
-aspect 2.35 \
-acodec libfaac \
-ac 2 \
-ar 44100 \
-ab 128k \
from uuid import uuid4
from time import time
from datetime import datetime, timedelta
import lmdb
def get_random(size):
def get_bytes():
return bytearray(size)
return get_bytes
@4poc
4poc / gist:5761b0cdfd6d903d31a73c36aff22b90
Created February 23, 2017 16:41
python 3.4 vs. 3.5 incompatibility
def fun(a=0, b=0):
print(a, b)
fun(**{'b': 2}, a=1) # <--- breaks in 3.4
fun(a=1, **{'b': 2}) # works in 3.5
@4poc
4poc / 1_encrypt.py
Last active December 13, 2016 10:31
Is this secure? (encrypted and signed(?))
import jose
from json import dumps
from Crypto.PublicKey import RSA
key = RSA.generate(2048)
private_key = key.exportKey('PEM').decode('utf-8')
public_key = key.publickey().exportKey('PEM').decode('utf-8')
from jwcrypto import jwk, jwe
from jwcrypto.common import json_encode