Skip to content

Instantly share code, notes, and snippets.

View kyleshevlin's full-sized avatar

Kyle Shevlin kyleshevlin

View GitHub Profile
@kyleshevlin
kyleshevlin / SvelteClock.html
Last active December 5, 2016 07:01
A clock written in Svelte
<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 {
@kyleshevlin
kyleshevlin / gist:43584fc45e541fad438db4604db23693
Created December 15, 2016 00:19 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

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
@kyleshevlin
kyleshevlin / wespack.js
Last active February 7, 2017 21:35 — forked from wesbos/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 February 10, 2017 11:52
Help me create a better 2d array, please

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 February 15, 2017 00:44
Why can't I use a HOC this way?
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 February 25, 2017 21:09 — 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).

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).

<!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 April 6, 2017 21:07
Memoization in a rAF loop
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
}
@kyleshevlin
kyleshevlin / sudokuValidator.js
Last active May 22, 2017 23:28
Sudoku Validator
// 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 21:25
memoized fibonacci sequence for posterity
function memoizedFibonacci (n) {
if (!memoizedFibonacci.memo) {
memoizedFibonacci.memo = {}
}
if (memoizedFibonacci.memo[n]) {
return memoizedFibonacci.memo[n]
} else {
let value