Skip to content

Instantly share code, notes, and snippets.

@huytd
huytd / FizzBuzz.rb
Created July 24, 2016 20:32
FizzBuzz TDD implementation
module FizzBuzz
extend self
def run(n)
if n % 3 == 0 && n % 5 == 0
return "FizzBuzz"
elsif n % 3 == 0
return "Fizz"
elsif n % 5 == 0
return "Buzz"
@huytd
huytd / expect.js
Last active August 16, 2016 23:35
DIY assertion library
let ___expect_finish_timer = null;
const expect = function(input) {
if (___expect_finish_timer) {
clearTimeout(___expect_finish_timer);
}
___expect_finish_timer = setTimeout(() => {
console.log('\n\x1b[32m✓ All tests passed!\x1b[0m\n');
}, 200);
@huytd
huytd / colors.go
Created August 18, 2016 18:16
Color output for Go app
package colors
import (
"fmt"
"regexp"
)
var (
TERM_STYLE = []string{
// LIGHT

Keybase proof

I hereby claim:

  • I am huytd on github.
  • I am huytd (https://keybase.io/huytd) on keybase.
  • I have a public key whose fingerprint is 54E3 5C6D AD03 A654 3302 A05F 8294 9437 AB11 7366

To claim this, I am signing this object:

Secret Management with Vault

Problems

  • Cloud deployment problem: Where do we store our secrets (read: database username and password) and how to give them to the server when we deploy?
  • Secret sharing and auditing problem: If everybody in our team uses the same token, how can we audit when something wrong happend? Who is the last person logged in using the shared key?
  • Revocation problem: our ex-sysadmin have quitted, how we managed to remove his
@huytd
huytd / package.json
Created September 8, 2016 20:25 — forked from dghuy/package.json
Webpack Babel React SCSS PostCSS
"dependencies": {
"autoprefixer": "^6.4.1",
"babel": "^6.5.2",
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"css-loader": "^0.25.0",
"node-sass": "^3.9.3",
"postcss-loader": "^0.13.0",
@huytd
huytd / websocket.go
Created September 9, 2016 18:58
WebSocket in Go
package main
import (
"log"
"net/http"
"github.com/gorilla/websocket"
)
type Message struct {
@huytd
huytd / pause.m
Last active September 10, 2016 20:38
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Not enough memory" message:@"Guy! Look like your device doesn't have enough memory to run me! I'm gone now!" delegate:nil cancelButtonTitle:@"OK Bye!" otherButtonTitles:nil];
[alert show];
while ((!alert.hidden) && (alert.superview != nil))
{
[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];
}
let context = (UIApplication.shared.delegate as! AppDelegate).persistenContainer.viewContext
lazy var applicationDocumentsDirectory: NSURL = {
let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return urls[urls.count-1] as NSURL
}()
lazy var managedObjectModel: NSManagedObjectModel = {
let modelURL = Bundle.main.url(forResource: "YOUR_CORE_DATA", withExtension: "momd")!
return NSManagedObjectModel(contentsOf: modelURL)!
}()