Skip to content

Instantly share code, notes, and snippets.

View sunnycmf's full-sized avatar
🎯
Focusing

Sunny Chan sunnycmf

🎯
Focusing
  • Carousell
  • Hong Kong
View GitHub Profile
@sunnycmf
sunnycmf / Callback conventions in node.js, how and why.md
Created January 26, 2015 04:00
Callback conventions in node.js, how and why

When first confronted with node.js, you are not only presented with a completely new programming environment. You also encounter what is often referred to as callback hell accompanied by weird unfamiliar programming patterns. One of these is the way node treats callback functions.

The following post explains the conventions that node.js uses for its callback patterns (referred to as Continuation-passing style) and how you should implement them in order to comply.

First argument is an error object pattern

Node expects - almost - all callback functions to accept an Error object as the first argument. If no error occurred, the first argument should be null. If you use inline anonymous functions, this is a typical code snippet that you will encounter using node:

// include the filesystem module
var fs = require('fs');
@sunnycmf
sunnycmf / time_dimension.sql
Last active October 4, 2023 19:24
MySQL Time Dimension generation SQL
-- credit to Akom's Tech Ruminations
-- http://tech.akom.net/archives/36-Creating-A-Basic-Date-Dimension-Table-in-MySQL.html
CREATE TABLE IF NOT EXISTS time_d (
time_id INT NOT NULL auto_increment,
fulltime time,
hour int,
minute int,
second int,
ampm varchar(2),
PRIMARY KEY(time_id)
@sunnycmf
sunnycmf / date_dimension.sql
Last active October 4, 2023 19:24
MySQL Date Dimension generation SQL
-- Credit to http://www.dwhworld.com/2010/08/date-dimension-sql-scripts-mysql/
-- Small-numbers table
DROP TABLE IF EXISTS numbers_small;
CREATE TABLE numbers_small (number INT);
INSERT INTO numbers_small VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
-- Main-numbers table
DROP TABLE IF EXISTS numbers;
CREATE TABLE numbers (number BIGINT);
INSERT INTO numbers
@sunnycmf
sunnycmf / osx_setup.md
Created November 22, 2016 05:36 — forked from millermedeiros/osx_setup.md
Mac OS X setup.

Setup Mac OS X Mountain Lion or Mavericks

Edit: I few months ago I got a new laptop and did the same thing on Mavericks.

I just replaced the hard drive of my mbp and decided to do a clean install of Mountain Lion (10.8.5) since I was still using Snow Leopard (10.6.8).

I kinda regret for not using Boxen to automate the

@sunnycmf
sunnycmf / System Design.md
Created September 25, 2019 05:42 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@sunnycmf
sunnycmf / README.md
Created April 18, 2018 07:53 — forked from joyrexus/README.md
form-data vs -urlencoded

Nice answer on stackoverflow to the question of when to use one or the other content-types for POSTing data, viz. application/x-www-form-urlencoded and multipart/form-data.

“The moral of the story is, if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data. Otherwise, use application/x-www-form-urlencoded.”


Matt Bridges' answer in full:

The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value pairs to the server. Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. To understand why, you have to look at what each is doing

@sunnycmf
sunnycmf / ioslocaleidentifiers.csv
Created August 2, 2017 08:23 — forked from jacobbubu/ioslocaleidentifiers.csv
iOS Locale Identifiers
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
mr Marathi
bs Bosnian
ee_TG Ewe (Togo)
ms Malay
kam_KE Kamba (Kenya)
mt Maltese
ha Hausa
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
ro_MD Romanian (Moldova)
<?php
class PassAPI extends Plugin
{
# Registration
# register a device to receive push notifications for a pass
#
# POST /v1/devices/<deviceID>/registrations/<typeID>/<serial#>
# Header: Authorization: ApplePass <authenticationToken>
# JSON payload: { "pushToken" : <push token, which the server needs to send push notifications to this device> }
#
@sunnycmf
sunnycmf / postgres-cheatsheet.md
Created March 13, 2017 10:57 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@sunnycmf
sunnycmf / yosemite-setup.md
Last active March 7, 2017 06:02
Mac OSX Yosemite dev env setup script

Mac OSX softwares and env setup

install homebrew & cask

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install caskroom/cask/brew-cask
brew tap caskroom/versions
brew update && brew upgrade brew-cask && brew cleanup && brew cask cleanup

Dev tools