This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a pattern P, check if the string S follows that pattern. | |
// e.g. | |
// P = aab | |
// S = hellohelloworld | |
// -> true | |
// This a naive brute force solution that runs in O(2^N) where N is the size of S, | |
// I hope there's a better solution. | |
function followsPattern(P, S) { | |
function solve(i, complement) { | |
if (i === S.length) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dfs(root, fn) { | |
if (!(root instanceof HTMLElement)) { | |
throw new Error('`root` should be an HTML Element'); | |
return; | |
} | |
if (!(fn instanceof Function)) { | |
fn = function(element) { | |
console.debug(element); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rotatePicture(matrix) { | |
if (matrix.length == 0 || matrix.length != matrix[0].length) { | |
return []; | |
} | |
var n = matrix.length; | |
var center = parseInt(n/2); | |
for (var i = 0; i < center; i++) { | |
var start = i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, sys | |
""" | |
Checks your git commit with JSHint. Only checks staged files | |
""" | |
def jshint(): | |
errors = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomNumber(min, max) { | |
min = parseInt(min, 10); | |
max = parseInt(max, 10); | |
if (min !== min) { | |
min = 0; | |
} | |
if (max !== max || max <= min) { | |
max = (min || 1) << 1; //doubling | |
} else { | |
max = max + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# utils | |
# alias kp='pkill -f polyserve' - Kill all the `polyserve` processes | |
# alias p='~/polyserve.sh' - Polyserve | |
base=`basename "$PWD"` | |
port=$(( RANDOM % (1000) + 8000 )) | |
url="http://localhost:$port/components/$base/demo/index.html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function refresh() { | |
var SCROLL_DIRECTION_UP = -1; | |
var SCROLL_DIRECTION_DOWN = 1; | |
var SCROLL_DIRECTION_NONE = 0; | |
var direction = SCROLL_DIRECTION_NONE; | |
var ratio = 0.5; | |
var delta = this.scrollTop - this.scrollPosition; | |
this.scrollPosition = this.scrollTop; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Base.isLightDom = function (node) { | |
return Polymer.dom(node).getOwnerRoot() === Polymer.dom(this).getOwnerRoot(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
@license | |
Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | |
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | |
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | |
Code distributed by Google as part of the polymer project is also | |
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | |
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dom-module id="x-example"> | |
<style> | |
:host { | |
display: block; | |
} | |
</style> | |
<template> | |
<div id="text">x-example</div> |