Skip to content

Instantly share code, notes, and snippets.

View willwright82's full-sized avatar
👾
parsleybox.com

Will Wright willwright82

👾
parsleybox.com
View GitHub Profile

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
@willwright82
willwright82 / safari-flicker-fix.css
Created March 7, 2019 14:20
To fix Safari flickering force GPU acceleration by adding transform translate3d(0,0,0) to your element (via https://muffinman.io/ios-safari-scroll-position-fixed/)
/*
If you ever had to fix element on scroll,
you probably had an issue on iOS Safari
(and other mobile devices). Element will
usually flicker, and disappear until scrolling
has stopped completely.
Just force GPU acceleration by adding transform:
translate3d(0,0,0); to your element.
*/
@willwright82
willwright82 / mobileCheck.js
Last active January 29, 2019 15:13
Detects mobile devices — Usage: if ( mobileCheck.ios ) { // Code }
var mobileCheck = {
ios: (function(){
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
}()),
android: (function(){
return navigator.userAgent.match(/Android/i);
}()),
blackBerry: (function(){
return navigator.userAgent.match(/BB10|Tablet|Mobile/i);
}()),
@willwright82
willwright82 / chmod.sh
Created December 12, 2017 10:43
Recursive chmod for files or folders
# To recursively give directories read&execute privileges:
chmod 755 $(find /path/to/base/dir -type d)
# To recursively give files read privileges:
chmod 644 $(find /path/to/base/dir -type f)
#Or, to reduce chmod spawning:
find /path/to/base/dir -type d -print0 | xargs -0 chmod 755
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644
@willwright82
willwright82 / getLanguage.js
Created November 28, 2017 10:32
Get user language based on Locale
// To get the language of your visitor:
var language = window.navigator.userLanguage || window.navigator.language;
console.log(language);
@willwright82
willwright82 / randomSHA1.js
Created October 26, 2017 11:55
Generate a random SHA1 token in browser
// str byteToHex(uint8 byte)
// converts a single byte to a hex string
function byteToHex(byte) {
return ('0' + byte.toString(16)).slice(-2);
}
// str generateId(int len);
// len - must be an even number (default: 40)
function generateId(len) {
var arr = new Uint8Array((len || 40) / 2);
@willwright82
willwright82 / sakamoto-wday.rb
Created August 28, 2017 11:13
Sakamoto Weekday
def calc_wday(year, month, day)
a = (14 - month) / 12
y = year + 4800 - a
m = month + 12 * a - 3
wday = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 + 2
wday = wday % 7
return wday
end
@willwright82
willwright82 / upgradePostgreSQL.sh
Last active August 2, 2017 10:59 — forked from giannisp/gist:b53a76047b07751ed3ade3c1db1d2c51
Upgrade PostgreSQL 9.5.1 to 9.6.3 using Homebrew (macOS)
After automatically updating Postgres to 9.6.1 via Homebrew, the pg_ctl start command didn't work.
The error was something like "database files are incompatible with server".
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.1 and latest 9.5.x installed, and keep 9.6.1 as default
brew unlink postgresql
brew install postgresql95
brew unlink postgresql95
brew link postgresql
@willwright82
willwright82 / bogosort.js
Created July 13, 2017 16:48
Bogosort algorithm implementation in Javascript
shuffle = function(v) {
for (var j, x, i = v.length; i; j = Math.floor(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};
isSorted = function(v) {
for (var i = 1; i < v.length; i++) {
if (v[i - 1] > v[i]) {
return false;
}