Skip to content

Instantly share code, notes, and snippets.

View AJamesPhillips's full-sized avatar

Alexander James Phillips AJamesPhillips

View GitHub Profile
@AJamesPhillips
AJamesPhillips / pub_sub.ts
Created May 22, 2021 12:51
Type safe typescript PubSub
// try it out in the playground: https://www.typescriptlang.org/play?#code/LAKFoeggCAHBXARgfQM5OQMwIYGMAuA9gE4CeAdPquCJvAHYECWh9cG6KOBJp0APAFtssaAFMAHvjH0AJqmgB5RACsxBAHzQAFAEpQAb1DQT0XK1T5o2ADY20SVLmJNEY4qgBc0A9ADaANLQTGwA1mKkhJjQwrAAugD83tragmKoqNgA5mLesYFxutAAvFoAboRMsrp+cdAAviU+9TTGpnSM+CxsCIgCQZLScgrhkdGxWtpEsEy43gEANDHpmTl5IgX6IKY+bTsm5vSWMdikbg6ITi5uHsmpK9m5J7CbJeWV1bXQAD7QDLJiTAhMSyJq2eycK6udyoPzTWZxPb7Q7HSHOaEeJrCM5iC5Qm4KYpEv5yQHA0EJfx1dY4vHogk0famNHXGHkTAkACieAAFtoWRi3kidkZtkz9qgxPgACpMNKEeD4FJFUrQAU3e4ZR66JYABi24oaBtMLTAZp2HWYrDVSH64ikMnk0FGUWek3hc2gixtl3p7mSaS1a2er1VFSqxpMosNKKs2PO6phd0Dqye+QChTe0HDnzqv3+ZPoILBdjprI8cMIM1wiLFTNjPvxMKxpwTjj9mKJxRJAKBRYpVOgNLbvvL1HN4sTHnICFQfKnW2FpnBZYxsI9dW7U-HS5MxCl8GIbAYiaweCIZCmVdmSwXSNNjPaDCtx6O7dZZ54ZDtg0dIwiroTDoHrzLe74YgGDzBummZhh8ka7HW+z7vgh5sHoQpISKu7IhYcatri27JlBaYbBmKrvBGXz5qSfbFt2K7bpW1a1oaOwNtuLa0pxXY9oWxaUl8w6EeBDITmxZh4dARYAO6rgSTTbuyTA2NIxD8lmCgAITEneWHioxokwsxCJNLJ8kwjhpo7A+4nQChaE+OwiBgX0pq2Y+kAwNg9CEPgPLuFgKliJQO4gCEancGI0AAMI+WU2CoAAsqgWRJSIhh
@AJamesPhillips
AJamesPhillips / new_password.py
Last active August 31, 2021 08:24
Crypto random password
import random;
import string;
N = 10
''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(N))
N = 5
word_file = "/usr/share/dict/words" # only works in *nix, https://stackoverflow.com/a/18835426/539490
WORDS = open(word_file).read().splitlines()
''.join(random.SystemRandom().choice(WORDS).capitalize() for _ in range(N))
@AJamesPhillips
AJamesPhillips / video_speed.md
Last active October 1, 2020 13:21
Speed up videos

Add the following code as a bookmark:

javascript: var videos = Array.from(document.getElementsByTagName('video')); var v = document.querySelector('video');  if (v) videos.push(v);  var t = parseFloat(prompt('Set the playback rate')); videos.forEach(v => v.playbackRate = t);

Then click it to set the video playback speed.

# Takes text with the format:
#
# 00:05
# Some subtitles
# 00:12
# Some more text
# ...
#
# 61:20
# More subtitle at 61 minutes, 20 seconds
@AJamesPhillips
AJamesPhillips / redux in c sharp.cs
Last active August 29, 2019 23:07
C# Redux replica
using System;
//using System.Web.Extensions;
//using System.Web.Script.Serialization;
/************************************************
* State
***********************************************/
public abstract class State<SubClassState>
{
@AJamesPhillips
AJamesPhillips / chrome_history_by_date.py
Created August 23, 2019 23:47
Search google chrome history by date
# Your database is probably in: ~/Library/Application Support/Google/Chrome/Default/History
# Copy it to ./chrome_history
import sqlite3
conn = sqlite3.connect("./chrome_history")
# Manually exploring the db and foreign keys etc
# print(conn.execute("SELECT name FROM sqlite_master WHERE type='table';").fetchall())
@AJamesPhillips
AJamesPhillips / type safe nested redux reducers.ts
Last active January 10, 2020 17:28
Type safe nested redux reducers
// state/reducers/schema.ts or spread through sub reducers/schema.ts files.
interface SettingsState {
favouriteColor: string
}
interface UsersState {
count: number
settings: SettingsState
}
@AJamesPhillips
AJamesPhillips / killads.js
Created July 21, 2019 09:50
Kills some ads
// Based off: https://gist.github.com/jasonleonhard/177b67f135c443719fe8
function removeElement (element) {
element.parentNode.removeChild(element);
}
function removeElements (elements) {
for (var i = 0; i < elements.length; ++i) {
removeElement(elements[i]);
}
@AJamesPhillips
AJamesPhillips / reducer.js
Last active May 3, 2019 11:58
Small function for combining redux selectors
function wrap_selectors (selectors, state_path) {
const wrapped_selectors = {}
Object.keys(selectors).forEach(selector_key => {
wrappedSelectors[selectorKey] = (state, ...args) => selectors[selectorKey](state[statePath], ...args)
})
return wrapped_selectors
}
@AJamesPhillips
AJamesPhillips / lightweight_npm_dependency_scanner.py
Created January 4, 2019 00:42
Rough scan of node dependencies for lesser used packages
import requests
import time
THRESHOLD = 1000000
packages = ["babel-core","babel-loader","babel-plugin-transform-flow-strip-types","babel-plugin-transform-object-rest-spread","babel-preset-es2015","babel-preset-react","babel-register","chai","chai-enzyme","cheerio","codecov","css-loader","enzyme","expect","file-loader","flow-bin","json-loader","mocha","node-sass","nyc","react-addons-test-utils","sass-loader","style-loader","url-loader"]
for package in packages:
url = "https://api.npmjs.org/downloads/range/2018-11-12:2018-12-09/" + package
resp = requests.get(url)
data = resp.json()