Skip to content

Instantly share code, notes, and snippets.

View Juszczak's full-sized avatar

Adrian Juszczak Juszczak

View GitHub Profile
@Juszczak
Juszczak / localstorage-safari-private-shim.js
Last active August 29, 2015 14:23
Don't let localStorage/sessionStorage setItem throw errors in Safari Private Browsing Mode
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem
// throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem
// to avoid the entire page breaking, without having to do a check at each usage of Storage.
(function(){
if (typeof localStorage === 'object') {
try {
localStorage.setItem('localStorage', 1);
localStorage.removeItem('localStorage');
} catch (e) {
Storage.prototype._setItem = Storage.prototype.setItem;
@Juszczak
Juszczak / couchdb-cors.sh
Created July 6, 2015 20:23
Add some generic CORS configuration to your CouchDB using curl. You can always change the configuration by simply going to http://127.0.0.1:5984/_utils/config.html and updating the values. However, these default options are good for getting up and running.
HOST=http://name:password@127.0.0.1:5984 # or whatever you got
curl -X PUT $HOST/_config/httpd/enable_cors -d '"true"'
curl -X PUT $HOST/_config/cors/origins -d '"*"'
curl -X PUT $HOST/_config/cors/credentials -d '"true"'
curl -X PUT $HOST/_config/cors/methods -d '"GET, PUT, POST, HEAD, DELETE"'
curl -X PUT $HOST/_config/cors/headers -d '"accept, authorization, content-type, origin, referer, x-csrf-token"'
@Juszczak
Juszczak / disable-shadow.sh
Created October 26, 2015 22:21
Disable the Window Shadow on Screen Shots in Mac OS X
defaults write com.apple.screencapture disable-shadow -bool true
killall SystemUIServer
@Juszczak
Juszczak / s3copy-across-aws-accounts.js
Created November 18, 2015 20:18 — forked from raffi-minassian/s3copy-across-aws-accounts.js
Quick and dirty script to copy files in AWS S3 to an S3 bucket in another AWS account with Node.js.
/*
* This is a quick and dirty script for copying files in AWS S3 to other buckets.
* This is written so it can work across AWS accounts.
* You can hack in code to apply work or logic to each file.
*
* For each file, it downloads locally to a tmp file and then starts uploading as soon as possible
* and deletes the file immediately when the upload is done.
*
* Best way to use: Spin up a micro in EC2, install node.js,
* create a directory and install the dependencies with

Keybase proof

I hereby claim:

  • I am juszczak on github.
  • I am juszczak (https://keybase.io/juszczak) on keybase.
  • I have a public key ASDhgxSrsMgfIAUaa-q2s4hD_gtMUWmdOyo3lNlv9-a2zQo

To claim this, I am signing this object:

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
mQINBFicbNQBEADiIkNXvo26KhTKVfwiby+THPQRvaFYT6WN+zqc3/bAe8bYXGDV
AxRvdE1+2rjgtiUHFUEZ41CuMrS2W142kDVnY9RjbxBVw1Q2W+h+y+5UT21Xqtoi
RTV64mXYkRUpnmV7dWco6g+gO+imPNHR0bBlBDWrMtq5PNq40h5sRQmF/v9x8Pe3
8aWyFfmtRsV1lqRavkt/GwLoxyCDxdEKemApwjHanKw/Yu9g71tE8icwnYy1u8cn
86nw9y04K1AY93pgxu3XR80nWICs4D0rfPDH2SG9b86TIgENNXZBvrLTzRaRwN5l
aCmRR5NcLJcoZH7ydeZMOhX45irnnmEzmYlSKO7oLB0MFgXjFw8bQ9lmQ/gNnZr3
rH9BnTX4Sx2EGyL9tzO3+4DXuEmzaW8hN4+dNupoDSO5gfL3JmnPVYEhAeN5HBLR
@Juszczak
Juszczak / converter.js
Last active June 1, 2017 13:30
dirty `.json` <-> `.properties` converter
const fs = require('fs')
const path = require('path')
const PROPS_DELIMITER = '='
const readJSON = fileName => JSON.parse(fs.readFileSync(path.resolve(process.cwd(), fileName), 'utf8'))
const toJSON = data => {
const output = {}
data.split('\n')
@Juszczak
Juszczak / KeyCodes.ts
Created July 21, 2017 08:28
KeyboardEvent key codes enum
export enum KeyCodes {
Backspace = 8,
Tab = 9,
Enter = 13,
Shift = 16,
Ctrl = 17,
Alt = 18,
PauseBreak = 19,
CapsLock = 20,
Escape = 27,
@Juszczak
Juszczak / get_buffers_number.vim
Created September 7, 2017 14:55
Returns number of buffers in Vim
function! GetBuffersNumber()
return len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
endfunction
@Juszczak
Juszczak / watcher.sh
Created January 13, 2018 11:46
Fix FS Watcher on Ubuntu
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf ; sudo sysctl -p