Skip to content

Instantly share code, notes, and snippets.

View sente's full-sized avatar

Stuart Powers sente

View GitHub Profile
anonymous
anonymous / test.go
Created January 5, 2018 02:39
Gitlab Available Two-Character Names Script
// This code is published under GNU GPL v3+. For more information, visit http://www.gnu.org/licenses/gpl.html
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
@magnetikonline
magnetikonline / README.md
Last active November 6, 2018 11:54
Bash file templating function.

File templating with Bash

Performs the application of given key/value pairs to a source template, with generated results written to an output file.

Functions applyTemplate accepts three arguments:

  • Source template file.
  • Target output file generated.
  • List of key/value pairs as an array.

Example

With the given source template:

#!/usr/bin/env python3
import sys
import subprocess as sp
from pathlib import Path
from argparse import ArgumentParser
from configparser import ConfigParser
def ssh(host, cmd):
return sp.check_output(['ssh', host, cmd]).strip().decode()
#!/usr/bin/env python3
from argparse import ArgumentParser
from pathlib import Path
from datetime import datetime, timedelta
import subprocess
from math import log10, sqrt
def prune(seq, key, dist):
pruned = []
@simonw
simonw / recover_source_code.md
Last active January 16, 2024 08:13
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@Glench
Glench / js_helpers_bookmarklet.js
Last active October 17, 2017 22:15
Utility functions for injecting into webpages to do scraping and fun things.
// Use http://bookmarklets.org/maker/ with no jQuery (sometimes there are SSL problems)
window.q = document.querySelectorAll.bind(document);
window.qq = document.querySelector.bind(document);
NodeList.prototype.map = function(func, debug) {
// A very useful function for reading and modifying a bunch of nodes on a web page.
// example usage: q('a').map(node => node.getAttribute('href')) -> ['http://glench.com/', 'closed-source/dictionaryofnumbers/', ...]
if (!func) { func = function(node) { return node;} }
anonymous
anonymous / sqlmitm.py
Created September 21, 2016 18:43
from scapy.all import *
import unicodedata
import sys, getopt
import time, datetime
import argparse
import socket
import fcntl
import struct
import threading
@protrolium
protrolium / terminal-gif.md
Last active February 15, 2024 09:09
convert images to GIF in Terminal

Install ImageMagick

brew install ImageMagick

Pull specific region of frames from video file w/ ffmpeg

ffmpeg -ss 14:55 -i video.mkv -t 5 -s 480x270 -f image2 %04d.png

  • -ss 14:55 gives the timestamp where I want FFmpeg to start, as a duration string.
  • -t 5 says how much I want FFmpeg to decode, using the same duration syntax as for -ss.
  • -s 480x270 tells FFmpeg to resize the video output to 480 by 270 pixels.
  • -f image2 selects the output format, a series of still images — make sure there are leading zeros in filename.
@PseudoSky
PseudoSky / export-style.js
Last active October 9, 2018 21:50
Javascript function that will export all current css arrtibutes on a dom element
Element.prototype.es = (function () {
// Mapping between tag names and css default values lookup tables. This allows to exclude default values in the result.
var defaultStylesByTagName = {};
// Styles inherited from style sheets will not be rendered for elements with these tag names
var noStyleTags = {"BASE":true,"HEAD":true,"META":true,"NOFRAME":true,"NOSCRIPT":true,"PARAM":true,"SCRIPT":true,"STYLE":true,"TITLE":true};
// This list determines which css default values lookup tables are precomputed at load time
// Lookup tables for other tag names will be automatically built at runtime if needed
@dropmeaword
dropmeaword / browser_history.md
Last active April 5, 2024 17:37
Playing around with Chrome's history

Browser histories

Unless you are using Safari on OSX, most browsers will have some kind of free plugin that you can use to export the browser's history. So that's probably the easiest way. The harder way, which seems to be what Safari wants is a bit more hacky but it will also work for other browsers. Turns out that most of them, including Safari, have their history saved in some kind of sqlite database file somewhere in your home directory.

The OSX Finder cheats a little bit and doesn't show us all the files that actually exist on our drive. It tries to protect us from ourselves by hiding some system and application-specific files. You can work around this by either using the terminal (my preferred method) or by using the Cmd+Shft+G in Finder.

Finder

Once you locate the file containing the browser's history, copy it to make a backup just in case we screw up.