Skip to content

Instantly share code, notes, and snippets.

View dnasca's full-sized avatar

Derrik dnasca

View GitHub Profile
@dnasca
dnasca / fatarrowandspread.js
Created October 1, 2016 21:00
fat arrow and spread use case
var a = (...n) => {
console.log(n[1])
};
a([1,2,3],[3,4,5],[6,7,8]) // -> [3,4,5]
@dnasca
dnasca / fatarrows.js
Last active October 1, 2016 21:01
a real use case of fat arrow functions
//when function scope sucks, and you have to cache 'this'
let a = function() {
let that = this;
this.val = 1;
setTimeout(function() {
that.val++;
console.log(that.val)
}, 1)
};
@dnasca
dnasca / purefunction.js
Created September 23, 2016 20:58
Pure Function
// pure function
// evaluates the same result given the same args
// doesn't depend on and doesn't modify the states of variables outside it's scope
// no side effects (mutations, async reqs)
var foods = ['beans', 'rice', 'pizza', 'pineapple']
// slice (shallow modified copy of array) vs splice (modifies original array)
foods.slice(0,3) //returns ['beans', 'rice', 'pizza']
@dnasca
dnasca / index.js
Last active July 16, 2016 07:24
web_modules / LayoutContainer / index.js
<Helmet
meta={ [
{
name: "generator", content: `${
process.env.PHENOMIC_NAME } ${ process.env.PHENOMIC_VERSION }`,
},
{ property: "og:site_name", content: pkg.name },
{ name: "twitter:site", content: `@${ pkg.twitter }` },
] }
script={ [
@dnasca
dnasca / createStore.js
Created June 10, 2016 03:41
createStore
const createStore = (reducer) => {
let state;
let listeners = [];
const getState = () => state;
const dispatch = (action) => {
state = reducer(state, action);
listeners.forEach(listener => listener());
};
@dnasca
dnasca / classes.js
Created April 25, 2016 19:26
Classes in JS
class Animal {
constructor(race) {
this.race = race;
}
}
class Cat extends Animal {
constructor(race) {
super(race);
}
{
"always_show_minimap_viewport": true,
"args":
{
"name": "Packages/Babel Snippets/react_wrap.sublime-snippet"
},
"bold_folder_labels": true,
"color_scheme": "Packages/User/SublimeLinter/Material-Theme-OceanicNext (SL).tmTheme",
"command": "insert_snippet",
"detect_indentation": false,
:first-child i === 0
:last-child i === arr.length - 1
:only-child arr.length === 1
:nth-child(even) i % 2
:nth-child(odd) !(i % 2)
:nth-child(n) i === n - 1
:nth-last-child(n) i === arr.length - n
@dnasca
dnasca / cte_2.sql
Last active January 27, 2016 12:50
--multiple CTEs per statement
WITH
ProductQty AS (
SELECT
ProductId,
LocationId,
Shelf,
Bin,
Quantity
@dnasca
dnasca / cte_1.sql
Created January 27, 2016 12:37
Common Table Expressions - multiple references to the same CTE
WITH
ProductQty (PID, LID, Shelf, Bin, Qty) AS
(SELECT
ProductId, LocationId, Shelf, Bin, Quantity
FROM
Production.ProductInventory)
SELECT
p1.PID,
SUM(p1.Qty) AS ShelfQty_A,