Skip to content

Instantly share code, notes, and snippets.

View AnalyzePlatypus's full-sized avatar
🐏
Bah.

Michoel Samuels AnalyzePlatypus

🐏
Bah.
View GitHub Profile
@shapeshed
shapeshed / aws-cf-logs
Last active September 12, 2022 09:10
Fetch AWS Cloudfront Logs, decompress, combine into a single file and remove comments
#!/usr/bin/env bash
BUCKET=$1
CWD=$(pwd)
if [[ -n $1 ]]; then
aws s3 sync s3://$BUCKET/cf-logs .
cat *.gz > combined.log.gz
find $CWD ! -name 'combined.log.gz' -name '*.gz' -type f -exec rm -f {} +
gzip -d combined.log.gz
@rosenfeld
rosenfeld / thread-pool.rb
Created June 7, 2016 12:49
Simple thread pool implementation in Ruby
require 'thread' # for Mutex: Ruby doesn't provide out of the box thread-safe arrays
class ThreadPool
def initialize(max_threads = 10)
@pool = SizedQueue.new(max_threads)
max_threads.times{ @pool << 1 }
@mutex = Mutex.new
@running_threads = []
end
@ayamflow
ayamflow / gist:b602ab436ac9f05660d9c15190f4fd7b
Created May 9, 2016 19:10
Safari border-radius + overflow: hidden + CSS transform fix
// Add on element with overflow
-webkit-mask-image: -webkit-radial-gradient(white, black);
@tomysmile
tomysmile / memcached_macosx.md
Created April 26, 2016 13:27
Installing memcached on Mac with Homebrew and Lunchy

Installing memcached on Mac with Homebrew and Lunchy

This is a quick guide for installing memcached on a Mac with Homebrew, and starting and stopping it with Lunchy. I hope this tutorial will get your memcached up and running in no time.

Step 1 — Install Homebrew

Installing Homebrew is super easy. Just paste this in your terminal —

$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@james2doyle
james2doyle / vue.pretty-bytes.filter.js
Last active November 28, 2021 01:07
Vue.js pretty bytes filter. This filter formats bytes into human readable formats
// usage: {{ file.size | prettyBytes }}
Vue.filter('prettyBytes', function (num) {
// jacked from: https://github.com/sindresorhus/pretty-bytes
if (typeof num !== 'number' || isNaN(num)) {
throw new TypeError('Expected a number');
}
var exponent;
var unit;
var neg = num < 0;
@lgarron
lgarron / copyToClipboard.html
Last active December 20, 2023 12:53
Simple `navigator.clipboard.writeText()` polyfill.
<script>
// A minimal polyfill for copying text to clipboard that works most of the time in most capable browsers.
// Note that:
// - You may not need this. `navigator.clipboard.writeText()` works directly in all modern browsers as of 2020.
// - In Edge, this may call `resolve()` even if copying failed.
// - In Safari, this may fail if there is nothing selected on the page.
// See https://github.com/lgarron/clipboard-polyfill for a more robust solution.
//
// License for this Gist: public domain / Unlicense
function writeText(str) {
@runeb
runeb / js-exif-rotate.html
Created May 23, 2014 10:49
Auto-rotate images locally in the browser by parsing exif data
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input id="file" type="file" accept="image/*" />
<br/>
<h2>As read:</h2>
<img id="placeholder1" width=300/><br/>
<h2>Rotated by exif data:</h2>
<img id="placeholder2" width=300/>
<script>
@Kartones
Kartones / postgres-cheatsheet.md
Last active April 30, 2024 19:47
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@lovasoa
lovasoa / UTF8byteLength.js
Created April 27, 2014 23:23
Compute the length in bytes of a javascript string, when encoded in UTF8
function byteLength(str) {
// returns the byte length of an utf8 string
var s = str.length;
for (var i=str.length-1; i>=0; i--) {
var code = str.charCodeAt(i);
if (code > 0x7f && code <= 0x7ff) s++;
else if (code > 0x7ff && code <= 0xffff) s+=2;
if (code >= 0xDC00 && code <= 0xDFFF) i--; //trail surrogate
}
return s;
@evanscottgray
evanscottgray / docker_kill.sh
Last active November 7, 2023 03:40
kill all docker containers at once...
docker ps | awk {' print $1 '} | tail -n+2 > tmp.txt; for line in $(cat tmp.txt); do docker kill $line; done; rm tmp.txt