Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Blake VandeMerwe blakev

🎯
Focusing
View GitHub Profile
@blakev
blakev / gist.py
Last active Sep 26, 2017
Are we running in a docker container? (Python)
View gist.py
import os
import subprocess
def in_container():
# type: () -> bool
""" Determines if we're running in an lxc/docker container. """
out = subprocess.check_output('cat /proc/1/sched', shell=True)
out = out.decode('utf-8').lower()
checks = [
'docker' in out,
@blakev
blakev / only_if.py
Created Jul 19, 2017
Dinking around with decorators
View only_if.py
import time
import json
import random
from functools import wraps
def only_if(condition, args_=None, *, pass_value=False, cache=False):
_fn = condition if callable(condition) else lambda: condition
if args_ is None:
@blakev
blakev / cc_extras.py
Created Nov 17, 2016
cookiecutter helper function that will replace |FILENAME,filter,filter,..| patterns with the contents of FILENAME, each line being applied with filters.
View cc_extras.py
import os
import re
RE_CONTENT = re.compile(r'(\|[\w\.\,]+\|)', re.I)
fns = {
'blockquote': lambda s: '> ' + s,
'code': lambda s: ' ' + s,
'comment': lambda s: '# {}'.format(s).rstrip() + '\n',
'list': lambda s: ' - ' + s
@blakev
blakev / scratch.py
Last active Jul 1, 2016
selenium scratch on dynamic page objects
View scratch.py
import string
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
CSS = By.CSS_SELECTOR
def split_case(n):
ret = []
View social counter totals
import os
import re
import sys
import json
import time
import requests
from bs4 import BeautifulSoup
from requests_oauthlib import OAuth1Session
from jinja2.environment import Environment
View keybase.md

Keybase proof

I hereby claim:

  • I am blakev on github.
  • I am blakev (https://keybase.io/blakev) on keybase.
  • I have a public key whose fingerprint is E3B1 28F0 8A95 AAE9 8848 9EDE 5F45 7ACC AE59 619A

To claim this, I am signing this object:

View livestream
// Live video stream management for HTML5 video. Uses FFMPEG to connect to H.264 camera stream,
// Camera stream is remuxed to a MP4 stream for HTML5 video compatibility and segments are recorded for later playback
var liveStream = function (req, resp) { // handle each client request by instantiating a new FFMPEG instance
// For live streaming, create a fragmented MP4 file with empty moov (no seeking possible).
var reqUrl = url.parse(req.url, true)
var cameraName = typeof reqUrl.pathname === "string" ? reqUrl.pathname.substring(1) : undefined;
if (cameraName) {
try {
cameraName = decodeURIComponent(cameraName);
@blakev
blakev / JsonHash.js
Created Aug 18, 2014
JavaScript JSON Hashing
View JsonHash.js
var _ = require('underscore');
function hash(data) {
function innerHash(data) {
var hashStr = '';
if(_.isArray(data)) {
_.each(data, function(e) {
hashStr += innerHash(e) + ','
@blakev
blakev / unravel.py
Last active Aug 29, 2015
Uses itertools to add an "unravel" function...unravel takes iterables and cycles through them yielding the first element until all the elements are gone, or until a limit is reached.
View unravel.py
import itertools
def unravel(*iterables, limit = None):
yield from itertools.islice(
filter(None,
itertools.chain.from_iterable(
itertools.zip_longest(
*iterables))), limit)
# a = [x for x in range(10)]
@blakev
blakev / cache_decorator_example.py
Created Jul 18, 2014
Python Class @cache decorator
View cache_decorator_example.py
import time
import random
DEFAULT_CACHE_TIME = 5 # seconds
class A:
def __init__(self):
pass
def cache(*args):