Skip to content

Instantly share code, notes, and snippets.

LZF Format

LZF is made of 1 or more "Chunks" that are simply concatenated to each other.

Chunk Layout

   "Z"   |  "V"   | Type   |compressed length| original length | payload
+--------+--------+--------+--------+--------+--------+--------+=================
|01011010|01010110|0000000C|LLLLLLLL|LLLLLLLL|BBBBBBBB|BBBBBBBB| L bytes of data
+--------+--------+--------+--------+--------+--------+--------+=================
Pending: (Failures listed here are expected and do not affect your suite's status)
1) AppNexus Advertiser writeme, testme, useme
# Not yet implemented
# ./spec/integration/advertiser_spec.rb:4
Failures:
1) AppnexusApi::Connection returns data from expiration
Failure/Error: fail "#{response.body['response']['error_code']}/#{response.body['response']['error_description']}"
@joshuawscott
joshuawscott / ruby_news_2016-07.md
Created July 21, 2016 16:03
Ruby News Rundown, July 2016

News

Rails 5.0 released

Deets:

  • ActionCable - websockets in rails!
  • API mode - strip out all the unneeded parts of rails when you just want an API
@joshuawscott
joshuawscott / redis_slowlog.rb
Last active August 6, 2017 10:01
Get Redis Slowlog Entries and parse them
# [[87283, 1442412746, 18052, ["hincrby", "191320:2015-09-16", "2015-09-16T13:39:00.000Z", "1"]], [87282, 1442411252, 22037, ["setex", "sifi_session:da34d588e031730b84a0462538022c60", "604800", "\u0004\b{\u0000"]], [87281, 1442410521, 81575, ["scan", "0", "MATCH", "CampaignStatistic:*", "COUNT", "1000"]], [87280, 1442409284, 12309, ["hincrby", "167569:2015-09-16", "2015-09-16T12:57:00.000Z", "1"]], [87279, 1442409279, 11073, ["hincrby", "163562:2015-09-16", "2015-09-16T12:55:00.000Z", "1"]], [87278, 1442409206, 14440, ["hincrby", "163558:2015-09-16", "2015-09-16T12:40:00.000Z", "1"]], [87277, 1442409198, 14750, ["hincrby", "187840:2015-09-16", "2015-09-16T12:34:00.000Z", "1"]], [87276, 1442409180, 11376, ["hincrby", "127478:2015-09-16", "2015-09-16T12:07:00.000Z", "1"]], [87275, 1442405559, 18445, ["hincrby", "182934:2015-09-16", "2015-09-16T11:13:00.000Z", "1"]], [87274, 1442405558, 57467, ["hincrby", "17342:2015-09-16", "2015-09-16T11:03:00.000Z", "1"]]]
require 'redis'
class Entry
attr_reader :log_numbe
@joshuawscott
joshuawscott / sequel_points.rb
Last active June 11, 2017 22:19
Polygons/Points/Arrays using Sequel for PostgreSQL
require 'sequel'
class Point
attr_accessor :long, :lat
def initialize(long, lat)
@long = long
@lat = lat
end
def self.from_str(str)
@joshuawscott
joshuawscott / curlsocket.js
Created December 9, 2014 19:21
curl to a unix socket. No external dependencies. tested on Nodejs 0.8 & 0.10
var http = require('http');
if (process.argv.length <= 3) {
console.error('USAGE: node curlsocket.js /path/to/unix.sock /request/path');
process.exit();
}
var options = {
method: 'GET',
hostname: 'localhost',
socketPath: process.argv[2],
@joshuawscott
joshuawscott / id and name indexes
Last active August 29, 2015 14:08
100,000,000 rows in postgres.
jscott=# \d t1
Table "public.t1"
Column | Type | Modifiers
--------+------------------------+-----------
id | integer |
name | character varying(255) |
Indexes:
"id_idx" btree (id)
"idx_name" btree (name)
@joshuawscott
joshuawscott / set_save_ex.lua
Last active August 29, 2015 14:08
Redis LUA stuff
-- Sets KEY to VALUE, preserving any existing TTL
-- Call with EVAL "..." 1 KEY VALUE
-- or
-- LOAD SCRIPT "..."
-- => <SHA1>
-- EVALSHA <SHA1> 1 KEY VALUE
local ttl = redis.pcall('ttl', KEYS[1])
if ttl == -1 then
return redis.pcall('set', KEYS[1], ARGV[1])

Compression

935MB nginx log (dpx)

MB/sec in both charts means:

orig. size - compressed size
____________________________
         real time
@joshuawscott
joshuawscott / prime.exs
Created August 4, 2013 20:40
Prime numbers Simple recursion to find primality up to 40,000
defmodule Prime do
def known_primes, do: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
def is_prime(n) when n > 9409, do: :cannot_calculate
def is_prime(n) when n < 2, do: false
def is_prime(2), do: true
def is_prime(n), do: check_primes(n, known_primes)
def check_primes(_,[]), do: true
def check_primes(n, [head|_tail]) when head*head > n, do: true
def check_primes(n, [head|tail]), do: rem(n, head) != 0 and check_primes(n, tail)