Skip to content

Instantly share code, notes, and snippets.


Tuan rocketspacer

View GitHub Profile
rocketspacer /
Last active May 30, 2019 18:39
Which lookup method is faster on small dataset? switch or if or map?

Lookup Benchmark Results

$ go test -bench=. -benchtime=5s 
goos: darwin
goarch: amd64
BenchmarkLookUp/ValueExists@Head/Switch-8       1000000000               6.39 ns/op
BenchmarkLookUp/ValueExists@Head/IfElse-8       10000000000              1.86 ns/op
BenchmarkLookUp/ValueExists@Head/Map-8          1000000000               9.86 ns/op
View terraform_debug_log_1534130886787
$ TF_LOG=trace terraform apply
2018/08/13 11:26:22 [INFO] Terraform version: 0.11.7
2018/08/13 11:26:22 [INFO] Go runtime version: go1.10.1
2018/08/13 11:26:22 [INFO] CLI args: []string{"/usr/local/Cellar/terraform/0.11.7/bin/terraform", "apply"}
2018/08/13 11:26:22 [DEBUG] Attempting to open CLI config file: /Users/tuan.nguyenm/.terraformrc
2018/08/13 11:26:22 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2018/08/13 11:26:22 [INFO] CLI command args: []string{"apply"}
2018/08/13 11:26:22 [INFO] command: empty terraform config, returning nil
2018/08/13 11:26:22 [DEBUG] command: no data state file found for backend config
2018/08/13 11:26:22 [DEBUG] New state was assigned lineage "3e382eed-2144-5b18-36d9-9afd685f34b5"
rocketspacer /
Created July 17, 2018 10:32 — forked from swalkinshaw/
Designing a GraphQL API

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.

View gist:f0d755263c5aa0a169a9ff8aba7a29cf
#include <iostream>
#include <fstream>
using namespace std;
#define MAX_SIZE 65536;
struct Location {
int row, col;
View mongodb_errors_code
error_code("OK", 0)
error_code("InternalError", 1)
error_code("BadValue", 2)
error_code("OBSOLETE_DuplicateKey", 3)
error_code("NoSuchKey", 4)
error_code("GraphContainsCycle", 5)
error_code("HostUnreachable", 6)
error_code("HostNotFound", 7)
error_code("UnknownError", 8)
error_code("FailedToParse", 9)
rocketspacer /
Created January 15, 2017 17:35
Linux op works
ufw allow OpenSSH
ufw allow http
ufw allow https
ufw enable
ufw status
rocketspacer / client-app.js
Created December 28, 2016 08:55
Handle oauth token redirect front-end angular
View client-app.js
var app = angular.module('app', ['ui.router']);
function ($stateProvider) {
// UI-Router
// Application states
var applicationStates = [
// Pre-authenticated
rocketspacer /
Created December 13, 2016 13:50 — forked from rikukissa/
Unit testing Angular.js app with node.js, mocha, angular-mocks and jsdom

Testing Angular.js app headlessly with node.js + mocha

Lean unit tests with minimal setup

Code examples


  • Fake DOM (Everything works without a real browser)
  • Uses ngMocks to inject and mock Angular.js dependencies
  • I'm assuming you are already using browserify (but everything works fine without it)
View Example SPA
Project Structure
- index.js //Your NodeJs code
- /public // What in here is your tradition Angular App (like the one on Angular Tutorial)
- /css
- /js
- app.js // Your Angular code
- index.html
================= Server Side =============================
//Node index.js
View Answer2.html
<!DOCTYPE html>
<link rel="stylesheet" href="css/normalize.css"/>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<body style="background-color: gray;">
<div style="width: 960px; margin: 8px auto; background-color: white">