Skip to content

Instantly share code, notes, and snippets.

View isaacgr's full-sized avatar

Isaac isaacgr

View GitHub Profile
@isaacgr
isaacgr / genstring.sh
Created January 15, 2023 18:33
Generate 32 character random string from command line
head /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9' | head -c 32 && echo
@isaacgr
isaacgr / quanta_scrape.py
Last active March 13, 2021 05:17
Python with Selenium code to scrape quantamagazine.com and save articles to pdf using chromedriver
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import os
import json
import sys
import subprocess
SPECIAL_CHARS = ['\\', '/', ':', '?', '*', '<', '>', '|']
@isaacgr
isaacgr / twisted_trial.py
Created January 4, 2021 19:03
A basic twisted.trial setup
from twisted.internet import defer, reactor
from twisted.trial import unittest, runner, itrial, reporter
from argparse import ArgumentParser
import logging
FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s"
datefmt = "%Y-%m-%d-%H:%M:%S"
log = logging.getLogger(__name__)
class TestLoaderWithKwargs(runner.TestLoader):
@isaacgr
isaacgr / pdf_form_editor.py
Created July 19, 2020 14:31
A script to fillout/annotate a pdf form
from pdfrw import PdfReader, PdfWriter, PdfDict, PdfObject
ANNOT_KEY = '/Annots'
ANNOT_FIELD_KEY = '/T'
ANNOT_VAL_KEY = '/V'
ANNOT_RECT_KEY = '/Rect'
SUBTYPE_KEY = '/Subtype'
WIDGET_SUBTYPE_KEY = '/Widget'
def main():
pdf = PdfReader('qpdf.pdf')
@isaacgr
isaacgr / auth.py
Created March 9, 2020 10:29
Klein json api authentication class
from functools import wraps
import json
from klein import Klein
class JsonApi(object):
"""
Reusable class for composing a JSON API easily with minimal
repeated code.
"""
@isaacgr
isaacgr / _vimrc
Last active July 19, 2020 14:25
Windows _vimrc
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
@isaacgr
isaacgr / .vimrc
Last active July 19, 2020 14:24
My vimrc file
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by
" the call to :runtime you can find below. If you wish to change any of those
" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim
" will be overwritten everytime an upgrade of the vim packages is performed.
" It is recommended to make changes after sourcing debian.vim since it alters
" the value of the 'compatible' option.
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
@isaacgr
isaacgr / pci_restart.sh
Created October 31, 2019 10:27
Restart pci interface to fix dual boot ethernet issue
#!/bin/bash
#Get the PCI-Address of network card (Caution: This works ONLY with ONE NIC)
PCI=`/usr/bin/lspci | /bin/egrep -i 'network|ethernet' | /usr/bin/cut -d' ' -f1`
PCIPATH=`/usr/bin/find /sys -name *\${PCI} | /bin/egrep -i *pci0000*`
#echo "PCI =$PCI"
#echo "PCIPATH=$PCIPATH"
#ls -la $PCIPATH
@isaacgr
isaacgr / heroku-ws-example.js
Created September 15, 2019 14:51
Websocket configuration with express and Herkou
'use strict';
const express = require('express');
const SocketServer = require('ws').Server;
const path = require('path');
const PORT = process.env.PORT || 3000;
const INDEX = path.join(__dirname, 'index.html');
const server = express()
@isaacgr
isaacgr / server_factory.js
Created August 15, 2019 11:35
Client server using a protocol and a factory. Written in js, using the same principle as Pythons Twisted.
const net = require('net')
class ServerProtocol {
constructor(client){
this.client = client
this.buffer = ""
this.factory = null
}
handleData(){
this.client.on('data', (data) => {