Skip to content

Instantly share code, notes, and snippets.

View u8sand's full-sized avatar

Daniel J. B. Clarke u8sand

View GitHub Profile
@u8sand
u8sand / no-proofpoint
Last active February 18, 2019 16:38
Online Office at my work likes to modify urls of raw text.. This script reverses the process.
#!/usr/bin/env python3
# Usage:
# no-proofpoint < broken_file.txt > fixed_file.txt
import re, sys
proofpoint_re = re.compile(r'https?://.+?/url\?u=(.+?)&d=.+?&e=')
encode_re = re.compile(r'-(\w{2})')
stdin = sys.stdin.read()
prev = 0
for match in proofpoint_re.finditer(stdin):
@u8sand
u8sand / pyswagger_wrapper.py
Last active October 5, 2018 19:49
A wrapper around pyswagger to make it easier to use.
''' Usage:
from pyswagger_wrapper import SwaggerClient
client = SwaggerClient('your_swagger_url', headers={'auth': 'whatever', 'if': 'necessary'})
client.actions.your_op_id.call(your=params)
'''
import json
from urllib import request
from pyswagger import App
@u8sand
u8sand / merging.py
Created October 5, 2018 19:49
A useful helper script for merging dict attributes. Helps identify and resolve duplicates in (for instance) databases
import json
import pprint
from jsondiff import diff
def prompt_merge_attr(*attrs_list):
''' Given multiple versions of an attribute dictionary,
facilitate merging them into a single version.
'''
final_attrs = {}
all_attrs = set([
@u8sand
u8sand / tape_it.js
Last active December 8, 2018 18:05
Convert tape tests into mocha assertions!
var test = require('tape')
var assert = require('assert')
/**
* Convert tape tests into mocha assertions!
*
* @example
* tape_it('my mocha tape test assertion', function (test) {
* test('my tape test', function (t) {
* t.equal(1, 1)
@u8sand
u8sand / matrix.js
Created January 7, 2019 20:30
Matrix numpy-style slice manipulations in Javascript
export function slice(left, right) {
return {
left,
right,
}
}
export function resolve_slice(s, l) {
if (s === null) {
return slice(0, l)
import { matrix_flatten, matrix_slice, slice } from './matrix'
import { range } from './range'
export function count_first_na(L) {
for (let i = 0; i < L.length; i++) {
if (L[i] != null)
return i
}
throw new Error('NaNs not identified')
}
@u8sand
u8sand / range.js
Created January 7, 2019 20:33
A pythonic `range` function for javascript
export function range(start, end) {
if (end === undefined) {
end = start
start = 0
}
function *_range() {
for(let i = start; i < end; i++) {
yield i
}
@u8sand
u8sand / Dockerfile
Last active February 7, 2019 18:04
Simple nginx proxy config with environment variables
FROM nginx
RUN rm /etc/nginx/nginx.conf
ADD ./setup.sh /setup.sh
ENTRYPOINT [ "/bin/bash", "/setup.sh" ]
CMD [ "nginx", "-g", "daemon off;" ]
@u8sand
u8sand / react-fitty.js
Created February 16, 2019 17:28
A demo of fitty with react for contained numbers
import React from 'react'
import fitty from 'fitty'
class Fitty extends React.Component {
fitty_props = ['minSize', 'maxSize', 'multiLine']
constructor(props) {
super(props)
this.init = this.init.bind(this)
@u8sand
u8sand / duplicate_image_map.py
Last active February 24, 2019 19:48
A python script for dealing with duplicate images
#!/usr/bin/env python3
import os
import sys
import glob
import imagehash
from PIL import Image
from functools import reduce
from itertools import chain