Skip to content

Instantly share code, notes, and snippets.

@snydergd
snydergd / pb
Last active January 6, 2016 02:35
Bash completion for packagebuilder pb command
# bash completion for packagebuilder pb command
# (wrapper for pacman and aur on Arch Linux)
_pb() {
local word;
word=${COMP_WORDS[$COMP_CWORD]};
COMPREPLY=( $(pb -Ss "^${word}" 2>/dev/null | grep '^\S' | sed -e 's/^.*\/\(\S\+\)\s.*/\1/') );
return 0;
@snydergd
snydergd / vizhash.py
Created January 10, 2016 05:05
python VizHash using PIL
#!/bin/env python2
"""
Visual hash (see [html5 implementation](https://github.com/sametmax/VizHash.js) and
[original creator's website](http://sebsauvage.net/wiki/doku.php?id=php:vizhash_gd))
reimplemented using a Python script with PIL.
"""
from PIL import Image,ImageDraw
import hashlib
import sys
' If you've copied certain files from folder A to folder B
' And wanted to move them instead
' You can use this to remove files in B from A
' On windows just double click this script and you'll be prompted for folders
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim folderObj, arcFolder, cleanFolder, fileObj, filename
@snydergd
snydergd / findObjProperty.js
Created September 1, 2016 03:58
Javascript Cyclic Nested Object Property Search
/*
* Finds locations within data structure that a specific key/value can be found
* - Handles looping data structures (for instance window.window = window)
* - Flexible query format (provide key to match, value to match, or both)
* - Handy for reverse engineering and understanding javascript code on websites
* - Note, it's a little hack-ish, but it's just a tool anyway
* Examples:
* a = {b: 4, c: [1, 2, {d: 5, e: [0, 5, 2]}]};
* searchObj(a, {key: d}); // --> ["root.c.2.d"]
* searchObj(a, {value: 2}); // --> ["root.c.1", "root.c.2.e.2"]
@snydergd
snydergd / dateCopy.html
Created December 13, 2016 15:02
Entering a lot of dates as text? This little snippet lets you quickly pick a date and have it copied to the clipboard in a custom format. Relies on moment.js
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Date select copy</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script type="text/javascript">
if (typeof($) == "undefined") {
$ = document.getElementById.bind(document);
}
#!/usr/bin/env node
var tty = require('tty')
var readline = require('readline')
var util = require('util')
// Config
var keyBindings = {
"C-x": "quit",
"C-r": "draw-screen",
@snydergd
snydergd / uniqueFolderFinder.py
Created July 22, 2018 23:42
Just some experimentation that I wanted to save. No point to make it private.
"""
Looking for a way to reduce a list of 9 digits into a sum that is unique if the digits are those between 1 and 9 inclusively.
This is for a solution to a Sudoku problem, but it was fun to mess around with functional programming.
"""
import itertools, functools, inspect
def findAllSimilar(individualOperation, aggregationOperation):
# Note: doing range inverse to make sure operation is commutative
expected = functools.reduce(aggregationOperation, map(individualOperation, range(9, 0, -1)))
@snydergd
snydergd / hexDump.py
Created September 26, 2018 21:17
Python hex dump snippet
#!/bin/env python
import sys
import string
while True:
b = sys.stdin.read(16)
if not b:
break
print "".join(map(lambda x: "%02x " % x, map(ord, b))) + " " + "".join(map(lambda x: x if x in string.printable else chr(0xA7), b)).replace('\t',' ')
@snydergd
snydergd / dumpHttp.groovy
Created June 11, 2019 01:46
HTTP Dumper
import com.sun.net.httpserver.HttpServer
HttpServer.create(new InetSocketAddress(8899), 0).with {
createContext("/") { http ->
http.with {
println (requestMethod + " " + requestURI + " HTTP/1.1")
requestHeaders.each{
a,b -> b.each{
y -> println a + ": " + y
}
@snydergd
snydergd / tcpDump.groovy
Created June 11, 2019 02:57
TCP Dumper Groovy
/*
Quick and dirty way to see raw requests made, for debugging.
*/
import java.net.ServerSocket
def server = new ServerSocket(4444)
while(true) {
server.accept { socket ->
socket.withStreams { input, output ->
byte[] buf = new byte[256]