Skip to content

Instantly share code, notes, and snippets.

View stretchkennedy's full-sized avatar
💭
git push -f #yolo

Tim Kennedy stretchkennedy

💭
git push -f #yolo
View GitHub Profile
@stretchkennedy
stretchkennedy / script.js
Last active March 29, 2023 00:15
Tampermonkey script to scroll through Google results with J/K
// ==UserScript==
// @name J/K through Google results
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Stretchkennedy
// @match https://www.google.com/search?*
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// ==/UserScript==
@stretchkennedy
stretchkennedy / check_source_age.sh
Created May 10, 2018 04:52
Check the age of all your js files before committing (using husky)
#!/bin/bash
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd)"
FILES="$(find "$DIR"/src -type f -name '*.js' -not -name '*.test.js')"
IS_OLDER=false
for f in $FILES; do
if [[ "$f" -nt bundle.js ]]; then
echo "$f is newer than bundle.js"
IS_OLDER=true
@stretchkennedy
stretchkennedy / connect.js
Last active July 26, 2017 04:32
react state management idea
const schema = {
view: {
selectedUser: null
},
data: {
users: {
$id: ({ id }, state, path) => fetch(`/api/users/${id}`).then(res => res.json())
}
}
};
@stretchkennedy
stretchkennedy / persist-turbolinks.js
Last active March 25, 2018 22:30
persist turbolinks position in vanilla js

Using python:

  • Find 4096 divided by 4.
  • Write a program that
    • takes a number from the command line and divides it by 4.
    • solves a thing called "FizzBuzz" up to the number 20. (hint: to get the remainder of a division, you need a thing called the modulo operator)
    • takes a number and runs through the steps of the Collatz conjecture.
    • takes a number, or numbers, and applies a formula that's actually useful to them. (if you're stuck for ideas, the quadratic formula could be interesting)
    • takes a list of numbers and adds them together. (hint: first use a for loop, then look at map from https://docs.python.org/2/tutorial/datastructures.html#functional-programming-tools)
  • takes a list of names and outputs something like Hello Ted, John, Alice, and Jane!.
# bash one-liner to run a simple (and possibly non-compliant) http server
ncat -l 2000 -k -c '/bin/echo -e "HTTP/1.0 200 OK\r\n\r\n<html><body><h1>Test page</h1></body></html>"'
# more comprehensive version that sets Content-Type and Content-Length
CONTENT='<html><body><h1>Test page</h1></body></html>'; ncat -l 2000 -k -c '/bin/echo -e "HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: '${#CONTENT}'\r\n\r\n'$CONTENT'"'
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- This file was created with the aha Ansi HTML Adapter. http://ziz.delphigl.com/tool_aha.php -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xml+xhtml; charset=UTF-8" />
<title>stdin</title>
</head>
<body style="color:white; background-color:black">
<pre>
@stretchkennedy
stretchkennedy / README.md
Last active June 28, 2016 00:13
Coding challenge

Coding challenge

Mockup

Mockup of a google maps view

Requirements

function escape_chars {
sed 's/"/""/g'
}
function format {
date=$(git log -n1 --pretty=format:%cD "$1" | escape_chars)
author=$(git log -n1 --pretty=format:'%aN <%aE>' "$1" | escape_chars)
sha=$(git log -n1 --pretty=format:%h "$1" | escape_chars)
message=$(git log -n1 --pretty=format:%B "$1" | escape_chars)
echo "\"$date\",\"$author\",\"$sha\",\"$message\""
}
@stretchkennedy
stretchkennedy / parallel.sh
Created February 24, 2016 01:55
Run bash commands in parallel
function mycommand {
sleep 1
}
PIDS=()
for i in $(seq 1 10); do
mycommand & PIDS+=($(echo $! | sed 's/^\[[0-9]*\]//'));
done
wait ${PIDS[*]}