Skip to content

Instantly share code, notes, and snippets.

View himynameisdave's full-sized avatar
✌️
livin' the dream...

Dave Lunny himynameisdave

✌️
livin' the dream...
View GitHub Profile
@himynameisdave
himynameisdave / replace-all.js
Last active February 4, 2016 04:21
replaceAll function in JS
module.exports = (str, find, replace) => str.split(find).join(replace);
function curry(fn) {
var args = Array.prototype.slice.call(arguments, 1);
return function inner() {
var newArgs = Array.prototype.slice.call(arguments);
args = args.concat(newArgs);
if (args.length >= fn.length){
return fn.apply(null, args)
}
return inner;
}
@himynameisdave
himynameisdave / challenge.js
Last active January 25, 2016 21:28
A curry challenge in JS
// Write a curry function...
function curry(){
// your code here
}
// ...that will curry this function...
function sumABC( a, b, c ){
return a + b + c;
@himynameisdave
himynameisdave / isValidCreditCard.js
Created January 19, 2016 20:20
Checks if a credit card is valid - Visa or Mastercard
const isValidCreditCard = ( cardNumber ) => {
const testCard = {
visa() {
return /^(?:4[0-9]{12}(?:[0-9]{3})?)$/g.test(cardNumber);
},
mastercard() {
return /^5[1-5][0-9]{14}$/g.test(cardNumber)
}
}
return testCard.visa() && testCard.mastercard()
@himynameisdave
himynameisdave / stripNonNumbers.js
Created January 19, 2016 19:31
A simple function that strips all non-numbers from a string
const stripNonNumbers = ( str ) => {
return str.replace(/[^0-9]+/g, "");
};
@himynameisdave
himynameisdave / dogelife.djs
Last active January 11, 2016 16:46
I didn't choose the doge life...
quiet
This is my first ever dogescript program
Essentially it exports
loud
such fun much lifestyle
wow 'I didn't choose the '+lifestyle+', the '+lifestyle+'chose me.'
module.exports = fun;
@himynameisdave
himynameisdave / LolService.js
Last active December 30, 2015 20:19
make-me-lol microservice
module['exports'] = function echoHttp (hook) {
//console.log(hook.params.type)
var type = hook.params.type;
if (!hook.params.type)
type = "g";
hook.res.end(JSON.stringify(hook.params, true, 2 ));
};
@himynameisdave
himynameisdave / readme.md
Last active November 9, 2015 19:40
Dead Simple Watch+Compile a Less File

Dead Simple Watch+Compile a Less File

Simply watches a Less file and compiles it on save.

Wat/Why?

Sometimes installing something like Gulp or Grunt is annoying if all you want to do is have a simple watch+compile going on. This includes PostCSS for the sake of Autoprefixer but you can obviously also add other PostCSS plugins to this script with ease.

Install Deps

@himynameisdave
himynameisdave / promises.js
Last active October 30, 2015 20:12
❤️ My first ever promise! 💔
"use strict";
const makeProm = thisVar => {
return new Promise( res, rej => {
setTimeout(() => {
if(thisVar === "dave")
res("RESOLVED");
else
rej("REJECTED");
}, 1000)
});
@himynameisdave
himynameisdave / utilities.js
Last active November 10, 2015 20:30
Cross-browser jQuery-like utility functions
// Cross-browser jQuery-like Utility functions
module.exports = {
addClass: function( el, addedClass ){
// add the invalid class
if( el.classList ){
el.classList.add(addedClass);
}else{
el.className += ' '+addedClass;
}