Skip to content

Instantly share code, notes, and snippets.

View dnasca's full-sized avatar

Derrik dnasca

View GitHub Profile
@dnasca
dnasca / unselectable.css
Created December 7, 2015 20:15
make unselectable
.row {
-webkit-user-select: none; /* Chrome all / Safari all */
-moz-user-select: none; /* Firefox all */
-ms-user-select: none; /* IE 10+ */
user-select: none; /* Likely future */
}
@dnasca
dnasca / papaparseuploadpopulate.js
Created December 7, 2015 20:13
papa parse. upload parse and populate list
//parse and populate list
function handleFileSelect(e) {
var file = e.target.files[0];
Papa.parse(file, {
header: true,
dynamictyping: true,
complete: function (results) {
parsed = results; //remove on prod
@dnasca
dnasca / jqhover.js
Created December 7, 2015 20:12
jq .hover
$('.list-group-item').hover(function () {
$(this).addClass('list-group-item-info');
}, function () {
$(this).removeClass('list-group-item-info');
});
@dnasca
dnasca / bootstrapfileinput.html
Created December 7, 2015 20:11
bootstrap file input
<span class="btn btn-default btn-file">
Browse <input type="file">
</span>
<style>
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
@dnasca
dnasca / jsGettersAndSetters.js
Created October 20, 2015 07:57
Getters and Setters in JS, the easy way.
//getters and settings done easy
var Circle = function(radius) {
this._radius = radius;
};
Circle.prototype = {
set radius(radius) {this._radius = radius;},
get radius() { return this._radius;},
get area() { return Math.PI * (this._radius * this._radius);}
};
@dnasca
dnasca / test_immutable.js
Created October 6, 2015 04:35
an example of testing an immutable data structure
import {expect} from 'chai';
describe('immutability', () => {
describe('a number', () => {
function increment(currentState) {
return currentState + 1;
}
@dnasca
dnasca / filterVSfor.js
Created September 27, 2015 02:19
functional filtering > imperative iteration
//stop imperatively iterating!
var fictionalCharacters = [
{ name: 'Beavis', universe: 'Beavis and Butthead'},
{ name: 'Cartman', universe: 'Southpark'},
{ name: 'Stimpy', universe: 'Ren and Stimpy'},
{ name: 'Butthead', universe: 'Beavis and Butthead'},
{ name: 'Stan', universe: 'Southpark'},
{ name: 'Ren', universe: 'Ren and Stimpy'},
{ name: 'Ironman', universe: 'Marvel'}
@dnasca
dnasca / withisbad.js
Created September 25, 2015 03:09
with is bad. don't use it.
//the with statement is bad
with(o){
foo = bar;
}
//impossible to tell (in this context) what this statement will expand into
//1. o.foo = bar;
//2. o.foo = o.bar;
//3. foo = bar;
@dnasca
dnasca / classfreeoop.js
Created September 25, 2015 02:23
class free oop
//class free oop
function constructor(spec) {
let {member} = spec,
{other} = other_constructor(spec),
method = function() {
// member, other, method, spec
};
return Object.freeze({
method,
@dnasca
dnasca / es6-tailcall.js
Created September 25, 2015 02:00
es6 - the death of the while loop
//es5
function repeat(func) {
while (func() !== undefined) {
}
}
//es6 proper tail call
function repeat(func) {
if (func() !== undefined) {
return repeat(func);