View fork
#!/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
View dump_pocket.py
#!/usr/bin/env python3
# Nick Sweeting 2017 | MIT License
# Usage:
# 1. Download pocket export from https://getpocket.com/export to ril_export.html
# 2. Run ./dump_pocket.py ril_export.html
# 4. Archive is saved in "pocket" folder
# Dependencies (chrome, python3, wget):
# wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
View double_fork.py
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:
View autocast.py
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):
View cockroach-django-orm.md

CockroachDB + Django ORM

TODO

  1. fork django/contrib/postgres driver
  2. patch blocking postgres compatibility issues
  3. review with cockroachdb team to see if any issues can be fixed by cockroach
  4. review with django team
  5. merge adapter as separate cockroachdb adapter
  6. write docs, any admin work, etc.
View templatetags.py
import bleach
import json as jsonlib
from django import template
register = template.Library()
@register.filter
def json(value):
"""safe jsonify filter, bleaches the json string using the bleach html tag remover"""
View ScopeTest.java
public class ScopeTest {
public static void main(String[] args) {
int result = 0;
addNumbers(12, 24);
System.out.println(result);
}
View leaderboard.py
from django.views import View
from django.shortcuts import render
class Leaderboard(View):
title = 'Leaderboard'
template = 'ui/react_base.html'
component = 'pages/leaderboard.js'
def get(self, request):
View leaderboard.js
import React from 'react'
import ReactDOM from 'react-dom'
const Leaderboard = ({users}) =>
<div>
<h1>Featured Players</h1>
{users.map(user =>
<a href={`/user/${user.username}/`}>
{user.username}
View react_base.html
{% 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>