Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle Shevlin kyleshevlin

View GitHub Profile
@kyleshevlin
kyleshevlin / SvelteClock.html
Last active Dec 5, 2016
A clock written in Svelte
View SvelteClock.html
<h2>Svelte Clock</h2>
<p>Look how fast Svelte goes!</p>
<p>{{hours}}:{{leftPad(minutes, 2, '0'}}:{{leftPad(seconds, 2, '0'}}:{{leftPad(milliseconds, 3, '0'}}</p>
<script>
import leftPad from 'left-pad'
export default {
View gist:43584fc45e541fad438db4604db23693

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
View wespack.js
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const javascript = {
test: /\.(js)$/,
use: [{
loader: 'babel-loader',
options: { presets: ['es2015'] }
}],
@kyleshevlin
kyleshevlin / README.md
Last active Feb 10, 2017
Help me create a better 2d array, please
View README.md

My request to the API returns an array of objects. I need to group each item in this array based on the value of one of its keys. Thus, I need to end up with a 2d array of arrays.

@kyleshevlin
kyleshevlin / onScreenHoc.jsx
Last active Feb 15, 2017
Why can't I use a HOC this way?
View onScreenHoc.jsx
import React, { Component, PropTypes } from 'react'
export default function onScreen (WrappedComponent) {
return class extends Component {
constructor () {
super()
this.handleScroll = this.handleScroll.bind(this)
this.isRefOnScreen = this.isRefOnScreen.bind(this)
this.state = {
isOnScreen: false
@kyleshevlin
kyleshevlin / gh-pages-deploy.md
Created Feb 25, 2017 — forked from cobyism/gh-pages-deploy.md
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).
View gh-pages-deploy.md

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@kyleshevlin
kyleshevlin / index.js
Created Apr 6, 2017
Memoization in a rAF loop
View index.js
const _this = this // the React Component
const ref = this.nodeRef // Using react to get a ref of my DOM element
const { width } = ref.getBoundingClientRect()
const scrollCoeffecient = 0.5 // this is retrieved from a config object in my app
const scrollSpeed = 1 * scrollCoefficient
function loop () {
if (!loop.aggregatedDistance) {
loop.aggregatedDistance = 0
}
View sudokuValidator.js
// Given the grid below, create a function that determines
// if the grid is a valid sudoku
const grid = [
['.', '.', '.', '1', '4', '.', '.', '2', '.'],
['.', '.', '6', '.', '.', '.', '.', '.', '.'],
['.', '.', '.', '.', '.', '.', '.', '.', '.'],
['.', '.', '1', '.', '.', '.', '.', '.', '.'],
['.', '6', '7', '.', '.', '.', '.', '.', '9'],
['.', '.', '.', '.', '.', '.', '8', '1', '.'],
@kyleshevlin
kyleshevlin / index.js
Created May 30, 2017
memoized fibonacci sequence for posterity
View index.js
function memoizedFibonacci (n) {
if (!memoizedFibonacci.memo) {
memoizedFibonacci.memo = {}
}
if (memoizedFibonacci.memo[n]) {
return memoizedFibonacci.memo[n]
} else {
let value