Skip to content

Instantly share code, notes, and snippets.

View pirate's full-sized avatar
🗃️
Archiving all the things!

Nick Sweeting pirate

🗃️
Archiving all the things!
View GitHub Profile
@pirate
pirate / react_base.html
Last active February 23, 2017 22:30
Base template for react pages
{% extends "ui/base.html" %}
{% block title %}{{title}}{% endblock %}
{% block inner %}
<div id="react">
<!-- Contents get replaced by mounted React.Component -->
<i class="fa fa-lg fa-spinner fa-spin"></i><br><br>
<i class="pending">Loading components...</i><br><br>
</div>
def autocast(func):
"""Tries to cast any parameters with type hints to the type defined.
Will not act if more than one type is defined.
Try to avoid using this, instead type-cast within your function to the desired types."""
def autocast_wrapper(*args, **kwargs):
sig = signature(func)
def convert(arg, param):
import os
import sys
def DOUBLE_FORK():
"""Perform a UNIX double-fork to detach, and re attach process to init so it's not a child of web worker"""
# do the UNIX double-fork magic, see Stevens' "Advanced
# Programming in the UNIX Environment" for details (ISBN 0201563177)
try:
pid = os.fork()
if pid > 0:
@pirate
pirate / fork
Created May 20, 2017 20:49
Fork a fish command using a bash subshell
#!/bin/bash
/usr/local/bin/fish -c "$*" > ~/tmp/fish_forks/last.log 2>&1 &
pid=$!
mv ~/tmp/fish_forks/last.log ~/tmp/fish_forks/$pid.log
disown $pid
.headerDesktop-container{background-color:#0d0d0d}.search-form-fieldset{background:#000}[class*="searchForm-action-button-"]{color:#fff}.searchForm-action-button-advanced:hover,.searchForm-action-button-toggle:hover{background:orange}.customRadio-input:checked+.customRadio-mask{box-shadow:inset 0 0 0 3px #fff,inset 0 0 0 10px orange;border-color:orange}.pm_button.primary,.pm_button.primary:active{color:#fff;background-color:#0d0d0d;border-color:#0d0d0d}.pm_button.primary:hover,.pm_button.primary:focus{background-color:#000;border-color:#000}.navigation>li.active,.navigation>li:hover{box-shadow:0 5px 0 0 orange inset}.navigation-link{color:#fff}.navigation-title:hover{color:orange}.pm_dropdown .navigationUser-logout{background-color:#0d0d0d !important;border-color:#0d0d0d !important;color:#fff !important}.pm_dropdown .navigationUser-logout:hover{background-color:#000 !important;border-color:#000 !important;color:#fff !important}.sidebar-btn-compose,.sidebar-btn-compose:active{color:#fff !important;background:o
def optional_arg_decorator(fn):
"""
wrap a decorator so that it can optionally take args/kwargs
when decorating a func
"""
# http://stackoverflow.com/a/32292739/2156113
@wraps(fn)
def wrapped_decorator(*args, **kwargs):
is_bound_method = args and hasattr(args[0], fn.__name__)
const immutify = (obj) => {
const obj = Object.keys(obj).reduce((acc, key) => {
Object.defineProperty(acc, key, { value: obj[key], writable: false, enumerable: true})
return acc
}, {})
const hash = hashObj(obj)
Object.defineProperty(obj, 'hash', { value: hash, writable: false, enumerable: false})
Object.preventExtensions(obj)
return obj
}
@pirate
pirate / event_listeners.js
Created October 6, 2017 10:36
Adding and removing reducers to redux dynamically using an event listener system
import {desktopNotify, requestDesktopNotify} from '@/util/browser'
// when user clicks "notify me" checkbox
requestDesktopNotify()
store.dispatch({
type: 'ADD_EVENT_LISTENER',
pattern: 'ALERT',
handler: (action) => {
if (action.alert.subtype == 'sit_in')
@pirate
pirate / carbon.sh.sublime-project.json
Last active October 14, 2017 00:12
Build shortcut to submit screenshot to carbon.now.sh, see https://gist.github.com/pirate/22438209f9ce5a7ece1813dac9014228 for submit-carbon-sh.js
{
...,
"build_systems":
[
{
...,
"variants":
[
...,
{
@pirate
pirate / merkel_fun.py
Last active November 3, 2017 09:10
Take a bookmark archive and turn it into a merkel tree blob index.
"""
Take a bookmark archiver folder structure and turn it into a deduped
merkel-tree blob index.
For example:
archive = {
'https://google.com': {
'index.html': 125, # arbitrary bytes as file content
'js': {