Skip to content

Instantly share code, notes, and snippets.

View josfaber's full-sized avatar
🏠
Working from home

Jos josfaber

🏠
Working from home
View GitHub Profile
Verifying that +josfaber is my blockchain ID. https://onename.com/josfaber
#!/bin/bash -e
clear
# requirements
echo "Project folder name:"
read -e projectfolder
projectfolder=${projectfolder:-project}
# dependencies
npm init -y --prefix ./$projectfolder
@josfaber
josfaber / bash aliases
Last active January 30, 2020 07:32
Bash aliases for common git and grunt operations
alias l="ls -l"
alias gf="git fetch"
alias gs="git status"
alias gfs="git fetch && git status"
alias gi="git init && gac 'Initial commit'"
alias gp="git push" # + remote & branch names
alias gl="git pull" # + remote & branch names
alias gpo="git push origin" # + branch name
alias glo="git pull origin" # + branch name
alias gpom="git push origin master"
@josfaber
josfaber / docker-compose.yml
Created September 9, 2021 13:34
Docker LAMPP composer file
version: '3.7'
services:
php-httpd:
image: php:7.3-apache
ports:
- 80:80
volumes:
- "./DocumentRoot:/var/www/html"
@josfaber
josfaber / dist.js
Last active November 20, 2021 16:05
Geocoordinates lat long distance
/**
* returns the distance between two lat long coordinates
* (uses degToRad and radToDeg functions below)
*/
function latlongdist(lat1, long1, lat2, long2) {
var theta = long1 - long2;
var miles = (Math.sin(degToRad(lat1)) * Math.sin(degToRad(lat2))) + (Math.cos(degToRad(lat1)) * Math.cos(degToRad(lat2)) * Math.cos(degToRad(theta)));
miles = radToDeg(Math.acos(miles)) * 60 * 1.1515;
var feet = miles * 5280;
var yards = feet / 3;
@josfaber
josfaber / outcomes.js
Last active November 20, 2021 16:02
Number of possible combinations
/**
* returns the number of possible combinations for given number of participants
* (e.g. 6 soccer teams have to play 15 matches to have everyone playing every other once)
*/
function numCombinations(participants) {
return 0.5 * participants * (participants-1);
}
@josfaber
josfaber / string-utils.js
Last active November 20, 2021 16:01
string utils
/**
* return a random, unique-ish id
*/
function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
@josfaber
josfaber / number-utils.js
Last active November 20, 2021 16:01
number utils
/**
* return random int in range
*/
this.randInt = function (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* return random float in range
@josfaber
josfaber / array-utils.js
Last active November 20, 2021 16:01
array utils
/**
* return randomized array
*/
function randomized(arr) {
var array = arr.slice(0);
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
@josfaber
josfaber / raf.js
Last active November 20, 2021 16:00
requestAnimationFrame rAF
/**
* requestAnimationFrame polyfill
* Based on: https://gist.github.com/paulirish/1579671
* Tweaked by: Bradley - https://gist.github.com/bradley
*/
(function() {
var lastTime = 0,
vendors = ['ms', 'moz', 'webkit', 'o'],
x,
length,