Skip to content

Instantly share code, notes, and snippets.

@wejrowski
wejrowski / es5-6.js
Last active September 15, 2015 18:19
JS select comparisons
var params = { t: 123, type: 'mytype', channelId: 'mychan', badge:'thebadge' };
var allowedPersonParams = ["type", "channelId", "badge", "since", "until"];
// ES5
var result = {};
allowedPersonParams.forEach(function (paramName) {
if (currentParams[paramName]) {
result[paramName] = currentParams[paramName];
}
var input = [[2,6],[3,5],[7,21],[20,21]];
var expectedOutput = [[2,6],[7,21]];
var rangesOverlap = function(range1, range2) {
return (
(range1[1] >= range2[0] && range1[1] <=range2[1]) ||
(range1[0] <= range2[0] && range1[1] >= range2[0])
);
};
@wejrowski
wejrowski / path-val.js
Last active October 28, 2015 19:10
Get path value
// via http://www.redotheweb.com/2015/09/18/declarative-imperative-js.html
function getValue(object, propertyName) {
if (!propertyName) throw new Error('Impossible to set null property');
return typeof object === 'undefined' ? undefined : object[propertyName];
}
function getNestedValue(object, propertyName) {
return propertyName.split('.').reduce(getValue, object);
}
@wejrowski
wejrowski / benchmark-template.js
Last active March 23, 2016 18:34
Benchmark template
/**
* Simple benchmark copy paste for browsers using Benchmark.js
* See their documentation: https://benchmarkjs.com/
* Edit the different suite add() sections below to change your tests or add new ones.
*/
var Script = function(url) {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = url;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
@wejrowski
wejrowski / calculator.html
Last active March 14, 2021 18:59
Web component + shadow DOM
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<basic-calculator></basic-calculator>
<template id="basicCalcTemplate">
<style>
@wejrowski
wejrowski / data-loading-polymer.md
Last active September 16, 2016 21:33
Declarative data loading in Polymer

Declarative data loading in Polymer

  • Rather than writing a lot of imperative code how can we write more straightforward/simpler/consistent code, less prone to bugs.

Nextgen data loading components

  • Spawned off with needing to solve binding and data store issues when updgrading to Polymer 1.
    • Polymer 0.x used the Object observe to update bindings. We referenced a global store using basically an Object.assign function that updated elements referencing those objects.
  • Came up with an inf-store-observer component to listen for and bind updates
@wejrowski
wejrowski / branch-diff.sh
Last active October 21, 2016 17:56
Git diff branch changes
# Shoot.. this is pointless actually. You can do this by `git diff origin/development...HEAD`
# Do a git diff between development, only on your changes by finding
# the last commit hash in your branch which is in development and diffing on that.
origin_development_hashes=$(git log --pretty=format:'%H' origin/development | tail -300)
for hash in `git log --pretty=format:'%H' | tail -300`; do;
[[ $origin_development_hashes =~ "$hash" ]] && found=$hash && break;
done;
if [ $found != "" ]; then
@wejrowski
wejrowski / fibonacci.js
Last active April 3, 2017 20:15
Quiz: next fibonacci number
var getNextFibonacciAfter = (function() {
var fibonacciNumbers = [0, 1];
function nextFibonnacciIn(numbers) {
return numbers[numbers.length] + numbers[numbers.length - 1];
}
return function(number) {
var nextFibonacci;
import sys
import json
import httplib2
import os
from oauth2client.service_account import ServiceAccountCredentials
if sys.argv < 2:
print "Usage auth [path-to-json]"
else:
keyPath = sys.argv[1]
@wejrowski
wejrowski / auth.py
Created July 13, 2017 19:55
Get google auth tokens from json
# python auth.py /path/to/creds.json
# To install
# brew install python
# gcloud components install app-engine-python
# pip install --upgrade google-api-python-client
import sys
import json
import httplib2
import os