Skip to content

Instantly share code, notes, and snippets.

View AJamesPhillips's full-sized avatar

Alexander James Phillips AJamesPhillips

View GitHub Profile
@AJamesPhillips
AJamesPhillips / gist:04f3047ca8770f4a3a58
Created May 2, 2014 15:18
Integration testing Scrapy spiders
import subprocess
import unittest
from scrapy.crawler import Crawler
from scrapy.utils.project import get_project_settings
from twisted.internet import reactor, task
from my_project.spiders.spider1 import Spider1
from my_project.spiders.spider2 import Spider2
@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 / 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 / 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 / rsa.py
Last active February 10, 2020 12:21
Reorder arguments in bruteForceV1 signature
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Simple example of encrypting, sending and decrypting a message using RSA.
Also included is how a third party without permission, would need
to use a very time consuming (brute force) approach to decrypt
the message. This is done by finding the two prime numbers that make up
part of the public key so that you can read the encrypted message.
@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 / 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 / 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]);
}