Skip to content

Instantly share code, notes, and snippets.

Karan Lyons karanlyons

Block or report user

Report or block karanlyons

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@karanlyons
karanlyons / README.md
Created Sep 25, 2017
Headspace Challenge
View README.md

Headspace Challenge

Requirements

  • Python >=3.5 (compiled with sqlite3 support)
  • That’s it.
  • This may have been a bad idea.

Get Started

@karanlyons
karanlyons / splatify.js
Created Aug 29, 2017
splatify.js: Add some venom to your coffee
View splatify.js
function splatify(func) {
args_string = func.toString().split('(')[1].split(')')[0].split(',').map(function(s) { return s.trim(); });
if (args_string.length && args_string[args_string.length - 1] === 'splat_args') {
pivot = args_string.length - 1;
return function () {
if (arguments.length > pivot + 1) {
args = Array.prototype.slice.call(arguments, 0, pivot);
args.push(Array.prototype.slice.call(arguments, pivot));
@karanlyons
karanlyons / solver.py
Last active Mar 8, 2020
Why PRNGs are not the same as CSPRNGs
View solver.py
import z3
def sym_xoroshiro128plus(solver, sym_s0, sym_s1, mask, result):
s0 = sym_s0
s1 = sym_s1
sym_r = (sym_s0 + sym_s1)
condition = z3.Bool('c0x%0.16x' % result)
solver.add(z3.Implies(condition, (sym_r & mask) == result & mask))
@karanlyons
karanlyons / method_missing.py
Last active Aug 7, 2017
method_missing for Python: All the headaches of Ruby, now with added whitespace!
View method_missing.py
import dis
import inspect
class MethodMissingMixin:
def __getattr__(self, attr):
if hasattr(getattr(self, '__methodmissing__', None), '__call__'):
parent_frame = inspect.currentframe().f_back
instructions = dis.get_instructions(parent_frame.f_code)
@karanlyons
karanlyons / parse.html
Created Jul 9, 2017
Javascript QTFF/MP4 Parser
View parse.html
<html>
<body>
<script>
'use strict';
ArrayBuffer.prototype.toSource = function(hex) {
var buf = this,
bytes = Array.prototype.slice.call(new Uint8Array(buf)),
i = buf.byteLength,
blank = true;
@karanlyons
karanlyons / sha512.cpp
Created Jul 4, 2017
SHA-512 in C“++”
View sha512.cpp
#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <cstring>
using namespace std;
const uint64_t k[] = {
UINT64_C(0x428a2f98d728ae22), UINT64_C(0x7137449123ef65cd), UINT64_C(0xb5c0fbcfec4d3b2f), UINT64_C(0xe9b5dba58189dbbc),
View locks.py
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, print_function, unicode_literals
from contextlib import contextmanager
from os import getpid
from random import getrandbits
View hide_meta_opts.py
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, print_function, unicode_literals
from copy import deepcopy
from django.db import models
@karanlyons
karanlyons / partial_range_update.sql
Last active May 19, 2020
Postgres: Update only portion of range, preserving other half and bounds.
View partial_range_update.sql
UPDATE <TABLE> SET
<COLUMN>=<RANGE_TYPE>(
lower(<COLUMN>), -- Swap out for actual value
upper(<COLUMN>), -- Swap out for actual value
concat(
CASE WHEN lower_inc(<COLUMN>) THEN '[' ELSE '(' END,
CASE WHEN upper_inc(<COLUMN>) THEN ']' ELSE ')' END
)
)
WHERE <CONDITION>;
@karanlyons
karanlyons / partial_object.py
Last active Aug 29, 2015
PartialObject (as functools.partial is to functions)
View partial_object.py
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
from __future__ import division, absolute_import, print_function, unicode_literals
import inspect
from collections import OrderedDict
class PartialManager(type):
You can’t perform that action at this time.