View nyancat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
red='\e[31m' | |
green='\e[32m' | |
yellow='\e[33m' | |
blue='\e[34m' | |
bold='\033[1m' | |
normal='\e[0m' | |
lines=( |
View keep-recent.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Delete all but the most recent N files in the given dir (and its subdirs) | |
function keep_most_recent { | |
dir="$1" | |
n=$2 | |
offset=$((n+1)) | |
find "$dir" -type f -printf "%T+ %p\n" | | |
sort -r | | |
awk '{ print $2 }' | | |
tail -n +$offset | | |
xargs --no-run-if-empty rm -f |
View extract-google-photos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
if [[ $# -ne 2 ]] || [[ ! -f "$1" ]] || [[ ! -d "$2" ]]; then | |
echo "usage: extract-google-photos [tarfile] [dest-dir]" | |
exit 1 | |
fi | |
if ! command -v exiftool > /dev/null || ! command -v gawk > /dev/null; then |
View chrome-auto.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Easiest. If this doesn't work right, try manual.sh | |
# | |
docker run --rm -it -p=0.0.0.0:9222:9222 alpeware/chrome-headless-trunk | |
# Then open local Chrome go to localhost:9222, then to chrome://inspect. From there you can open new tabs and inspect them. |
View csp-strict-dynamic.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: node csp-strict-dynamic.js dist/index.html [path/to/nginx.conf] | |
* | |
* Replaces all external script tags in index.html with dynamic loaders, calculates their SHA 256 hashes, and adds those | |
* hashes as allowed script sources + strict dynamic. Also works for inline scripts. | |
* | |
* Your index.html and/or given nginx/apache config file should contain your CSP policy with a script-src section like below: | |
* | |
* script-src 'strict-dynamic' {{csp-strict-dynamic-sources}}; | |
*/ |
View Gemfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'activerecord', '~> 5.2', require: 'active_record' | |
gem 'sqlite3' | |
gem 'rake' |
View fizzbuzz.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizzbuzz(input) | |
input.map do |n| | |
fizz = n % 3 == 0 ? 'Fizz' : nil | |
buzz = n % 5 == 0 ? 'Buzz' : nil | |
if fizz or buzz | |
"#{fizz}#{buzz}" | |
else | |
n.to_s | |
end | |
end |
View loc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
find $@ -type f -print0 | wc -l --files0-from=- |
View sidekiq_csrf_token_fix.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'securerandom' | |
module Sidekiq | |
class CsrfTokenFix | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) |
View fax.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'libfax' | |
puts "Sending fax..." | |
attempts = mock_fax('555-555-5555', "Here's a fax!") | |
attempts.each_with_index do |status, i| | |
case status | |
when :sent | |
puts "Fax sent!" | |
break | |
when :busy |
NewerOlder