Skip to content

Instantly share code, notes, and snippets.

⌨️
keyboard shredding

Miguel Mota miguelmota

⌨️
keyboard shredding
Block or report user

Report or block miguelmota

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@miguelmota
miguelmota / complete.js
Last active Aug 29, 2015
Reusable module for Node.js and browser
View complete.js
;(function(root) {
var fglobal = typeof global === 'object' && global;
if (fglobal.global === fglobal || fglobal.window === fglobal) {
root = fglobal;
}
if (typeof define === 'function' && typeof define.amd === 'object') {
define([], function() {
return mymodule;
});
@miguelmota
miguelmota / .jshintrc
Last active Aug 29, 2015
.jshintrc boilerplate I use
View .jshintrc
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 4,
View redis.js
module.exports = {
DB1: redis.createClient(),
DB2: redis.createClient(),
DB3: redis.createClient(),
init: function(next) {
var select = redis.RedisClient.prototype.select;
require('async').parallel([
select.bind(this.DB1, 1),
select.bind(this.DB2, 2),
select.bind(this.DB3, 3)
@miguelmota
miguelmota / asyncSpec.js
Last active Aug 29, 2015
Jasmine async beforeEach()
View asyncSpec.js
define('Jasmine' , function () {
beforeEach(function(){
runs(function () {
getRemoteData(function(res){
this.data = res;
}.bind(this));
});
waitsFor(function() {
@miguelmota
miguelmota / dir.sh
Last active Aug 29, 2015
Current directory of script in bash.
View dir.sh
#!/bin/bash
DIR="$( cd "$( dirname "$0" )" && pwd )"
echo $DIR
@miguelmota
miguelmota / within-circle.js
Last active Aug 29, 2015
Check if coordinate is within circle
View within-circle.js
function withinCircle(x, y, centerX, centerY, radius) {
return Math.pow((x - centerX), 2) + Math.pow((y - centerY), 2) < Math.pow(radius, 2);
}
@miguelmota
miguelmota / distance.js
Last active Aug 29, 2015
Get distance from latitude and longitude in kilometers
View distance.js
// @credit http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points
function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1);
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
@miguelmota
miguelmota / loadavg.sh
Last active Aug 29, 2015
Get load average on Mac OSX
View loadavg.sh
# Method one - w
w | head -n1 | cut -d":" -f4
# Method two - uptime
uptime | cut -d":" -f4- | sed s/,//g
# Method three - loads.d
sudo loads.d | awk '/./ { printf "%.2f %.2f %.2f\n", $7, $8, $9 }'
@miguelmota
miguelmota / blacklist.json
Created Apr 24, 2014
List of blacklisted words
View blacklist.json
[
"2g1c",
"4chan",
"baccarat",
"betting",
"betting odds",
"betting line",
"blackjack",
"casino",
"craps",
@miguelmota
miguelmota / error.js
Created May 11, 2014
Custom error type in JavaScript
View error.js
function MyError(message) {
this.name = 'MyError';
this.message = message;
this.stack = (new Error()).stack;
}
MyError.prototype = new Error();
MyError.prototype.constructor = MyError;
try {
You can’t perform that action at this time.