Skip to content

Instantly share code, notes, and snippets.

View jketcham's full-sized avatar

Jack Ketcham jketcham

View GitHub Profile
@jketcham
jketcham / stringToNumber.js
Last active February 9, 2021 23:28
Convert a string to a number
// ASCII character codes
const ZERO_CHAR = 48;
const ONE_CHAR = 49;
const TWO_CHAR = 50;
const THREE_CHAR = 51;
const FOUR_CHAR = 52;
const FIVE_CHAR = 53;
const SIX_CHAR = 54;
const SEVEN_CHAR = 55;
const EIGHT_CHAR = 56;
@jketcham
jketcham / gist:c62a1f460c33c8da2d34499dd3536a6c
Created November 18, 2020 22:42 — forked from trongthanh/gist:2779392
How to move a folder from one repo to another and keep its commit history
# source: http://st-on-it.blogspot.com/2010/01/how-to-move-folders-between-git.html
# First of all you need to have a clean clone of the source repository so we didn't screw the things up.
git clone git://server.com/my-repo1.git
# After that you need to do some preparations on the source repository, nuking all the entries except the folder you need to move. Use the following command
git filter-branch --subdirectory-filter your_dir -- -- all
# This will nuke all the other entries and their history, creating a clean git repository that contains only data and history from the directory you need. If you need to move several folders, you have to collect them in a single directory using the git mv command.
@jketcham
jketcham / deploy-pipeline.yaml
Created August 26, 2020 06:37
Deploy Kubernetes to DigitalOcean cluster with skaffold and kustomize on new tag pushes
on:
push:
tags:
- '*'
jobs:
build:
name: Build, push, and deploy
runs-on: ubuntu-latest
steps:
@jketcham
jketcham / jigsaw.js
Last active July 10, 2019 01:24
A jigsaw puzzle implementation
// Node >= v2 required
const util = require('util');
const TOP = 0;
const RIGHT = 1;
const BOTTOM = 2;
const LEFT = 3;
const SIDES = [TOP, RIGHT, BOTTOM, LEFT];

Keybase proof

I hereby claim:

  • I am jketcham on github.
  • I am jketcham (https://keybase.io/jketcham) on keybase.
  • I have a public key whose fingerprint is 5075 540D A46A 5C23 74DE 6560 DC02 5880 B631 9C9D

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am jketcham on github.
  • I am jket (https://keybase.io/jket) on keybase.
  • I have a public key ASAi8gCBSQvkiDqlPPuPsB1_FaQX3s_stsxxg0V5MydeMgo

To claim this, I am signing this object:

@jketcham
jketcham / offline-indicator.js
Created May 8, 2017 17:37
React browser network status indicator
const React = require('react');
class OfflineIndicator extends React.Component {
constructor(props) {
super(props);
this.handleOffline = this.handleOffline.bind(this);
this.state = { offline: false };
}
@jketcham
jketcham / update.js
Last active November 22, 2016 18:21
Updating EmbeddedDocument in an array in MongoDB
db.collection.find({}).snapshot().forEach(function(item) {
for (i = 0; i < item.array.length; i++) {
item.array[i].newProp = item.array[i].oldProp;
delete item.array[i].oldProp;
}
db.collection.update({
_id: item._id
}, item);
})
@jketcham
jketcham / matchSearchTerm
Created January 27, 2016 23:26
highlight words in a string that match a given term
function matchSearchTerm(string, matchTerm) {
if (!matchTerm) return string;
var words = string.split(' ');
var final = '';
var parsedWords = [];
words.forEach((word, index) => {
if (word.toLowerCase().indexOf(matchTerm) > -1) {
if (final) parsedWords.push(final);
@jketcham
jketcham / gist:e8b4c88c130a2d4b2aae
Last active August 29, 2015 14:06
Mongoose Schema
var GameSchema = new Schema({
title: String,
description: String,
location: String,
created_on: { type: Date, default: Date.now },
active: { type: Boolean, default: true },
accepting_players: { type: Boolean, default: true },
players: [{
type: Schema.Types.ObjectId,
ref: 'User'