Skip to content

Instantly share code, notes, and snippets.

View kumikoda's full-sized avatar
🧎‍♂️
Summoning AI God

Anson Chu kumikoda

🧎‍♂️
Summoning AI God
View GitHub Profile
@kumikoda
kumikoda / timeout.html
Last active February 8, 2022 15:59
A simple example demonstrating how setTimeout(fn, 0) can be useful. This gist illustrates the answer given by DVK's on stackoverflow. http://stackoverflow.com/a/4575011/783478
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<button id='do'> Do long calc!</button>
<div id='status'></div>
<div id='result'></div>
<script>
$('#do').on('click', function(){

A love story written by me

Characters

Nick : an elevator engineer Laura : a beautiful girl Betsy : an intelligent elevator robot Shane : the simpleton

@kumikoda
kumikoda / backbone_memleak_free.coffee
Last active December 22, 2015 16:49
a memory leak FREE backbone template
class Item extends Backbone.Model
class ItemList extends Backbone.Collection
class ItemView extends Backbone.View
template : _.template '<%= text %>'
initialize : ->
@kumikoda
kumikoda / npm_version_patch.md
Last active January 4, 2016 06:58
How to bump version number for your own package (that you don't need to publish to npm)
  1. make your changes and merge your stuff into master
  git push origin master
  1. Bump your version number in package.json, add a new tag and commit
  npm version patch
@kumikoda
kumikoda / squash.md
Last active June 3, 2017 14:09
squashing your commits
  1. Make sure you have the latest code
git fetch --all 
git log
  1. start rebasing. If you have a feature branch you want to merge, you might rebase off dev. If you simply want to squash a few commits together, you might rebase off of a specific head location.
@kumikoda
kumikoda / return.js
Created May 12, 2014 23:49
returning callbacks early
function someAsyncFn (cb) {
if (somethingWrong) {
cb(err)
} else {
cb(null, 'yay')
}
...
// potentially some things happen here
@kumikoda
kumikoda / error.js
Created June 7, 2014 22:04
why you should not wrap callbacks inside of a try block
function getData (callback) {
try {
var data = JSON.parse('hello world!') // attempt something dangerous here
callback(null, data);
} catch (e) {
// we only want to catch errors if JSON.parse fails
console.log('i should never print since above parsing always works')
callback(e)
}
@kumikoda
kumikoda / 0_reuse_code.js
Last active August 29, 2015 14:13
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kumikoda
kumikoda / slices.go
Last active August 29, 2015 14:13
Golang tutorial two-dimensional slices
// https://tour.golang.org/moretypes/14
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
s := make([][]uint8, dy)
for x := range s {
s[x] = make([]uint8, dx)
@kumikoda
kumikoda / maps.go
Last active August 29, 2015 14:13
Golang tutorial maps
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
"fmt"
)
func WordCount(s string) map[string]int {
result := make(map[string]int)