Skip to content

Instantly share code, notes, and snippets.

View maxpert's full-sized avatar

Zohaib Sibte Hassan maxpert

View GitHub Profile
@maxpert
maxpert / results.txt
Created July 15, 2012 12:24
JSON vs MsgPack using Gzip + LZ4
Original tweet size in JSON 2624 Msgpack = 1817 Gzip + Json = 1058 Gzip + Msgpack = 1116 LZ4 + Json = 1628 LZ4 + Msgpack = 1361
Original tweet size in JSON 1863 Msgpack = 1443 Gzip + Json = 0783 Gzip + Msgpack = 0835 LZ4 + Json = 1153 LZ4 + Msgpack = 1040
Original tweet size in JSON 2074 Msgpack = 1670 Gzip + Json = 0842 Gzip + Msgpack = 0894 LZ4 + Json = 1229 LZ4 + Msgpack = 1139
Original tweet size in JSON 2025 Msgpack = 1617 Gzip + Json = 0845 Gzip + Msgpack = 0895 LZ4 + Json = 1238 LZ4 + Msgpack = 1143
Original tweet size in JSON 2069 Msgpack = 1663 Gzip + Json = 0846 Gzip + Msgpack = 0901 LZ4 + Json = 1243 LZ4 + Msgpack = 1164
Original tweet size in JSON 2035 Msgpack = 1634 Gzip + Json = 0852 Gzip + Msgpack = 0907 LZ4 + Json = 1247 LZ4 + Msgpack = 1167
Original tweet size in JSON 1988 Msgpack = 1464 Gzip + Json = 0804 Gzip + Msgpack = 0862 LZ4 + Json = 1220 LZ4 + Msgpack = 1061
Original tweet size in JSON 1910 Msgpack = 1502 Gzip + Json = 0775 Gzip + Msgpack = 0832 LZ4 + Json = 1154 LZ4 + Msgpack = 1060
@maxpert
maxpert / .htaccess
Last active October 29, 2017 06:40
PHP Long shadow icon generator.
# for neater URLS like /{text}/{size}/{bg}
RewriteEngine on
RewriteRule ^img/([^/]+)/(\d+)/([a-fA-F0-9]{6})$ i/index.php?text=$1&size=$2&bg=$3 [NC,QSA]
RewriteRule ^img/([^/]+)/(\d+)$ i/index.php?text=$1&size=$2 [NC,QSA]
RewriteRule ^img/([^/]+)$ i/index.php?text=$1 [NC,QSA]
RewriteRule ^img/([^/]+)/.+$ i/index.php?text=$1 [NC,QSA]
@maxpert
maxpert / Brainfuck.js
Last active December 21, 2017 12:21
Minimal BrainF*ck implementation in JS
/**
* Copyright 2017 Zohaib Sibte Hassan
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWAR
@maxpert
maxpert / Results.txt
Created February 15, 2018 07:02
Redis compressed values benchmark
Slow network time in seconds (100Mbps):
LZ4/Write takes: 0.2853062963485718
LZ4/Read takes: 0.3265376162528992
QLZ/Write takes: 0.31065379858016967
QLZ/Read takes: 0.4505005311965942
ZSTD/Write takes: 0.1596823501586914
ZSTD/Read takes: 0.2516604351997376
ZLIB/Write takes: 0.3231374764442444
ZLIB/Read takes: 0.2478048324584961
UC/Write takes: 0.7657859945297241
@maxpert
maxpert / nosqlite.py
Last active May 18, 2018 22:21
A really simple Document store built on top of SQLite3 using Python
'''
Copyright (c) 2013 Zohaib Sibte Hassan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
@maxpert
maxpert / README.md
Last active July 30, 2018 08:40
51873 Blockchain

A toy blockchain implementation made for fun.

Implements:

  • Basic in-memory blockchain
  • Basic Proof of work
  • Methods to serialize/deserialize complete chain

Again none of this is supposed to be production ready.

@maxpert
maxpert / param_call.php
Created July 1, 2012 12:31
PHP named parameter calling
<?php
$x = function($bar, $foo="9") {
echo $foo, $bar, "\n";
};
class MissingArgumentException extends Exception {
}
function call_user_func_named_array($method, $arr){

Javascript #router. Features:

  • Just 70 lines of code.
  • Router scope can be bound to any object (default window); just change first parameter
  • Triggers custom DOM (Level 2) events on window.document.
  • IE 9+, FF, and Webkit based browsers [Tested only in Chrome and FF].
@maxpert
maxpert / REDIS_PING.kt
Created October 5, 2020 19:13
Redis PING Implementation for JGroups
package luna.lib
import io.lettuce.core.RedisClient
import io.lettuce.core.RedisException
import io.lettuce.core.cluster.RedisClusterClient
import io.lettuce.core.cluster.api.sync.RedisClusterCommands
import org.jgroups.Address
import org.jgroups.annotations.MBean
import org.jgroups.annotations.Property
import org.jgroups.conf.ClassConfigurator
@maxpert
maxpert / Stopwatch.kt
Created March 16, 2016 04:16
A really simple stopwatch for Kotlin
object Stopwatch {
inline fun elapse(callback: () -> Unit): Long {
var start = System.currentTimeMillis()
callback()
return System.currentTimeMillis() - start
}
inline fun elapseNano(callback: () -> Unit): Long {
var start = System.nanoTime()