Skip to content

Instantly share code, notes, and snippets.

View duythinht's full-sized avatar
💭
I may be slow to respond.

Thinh Tran duythinht

💭
I may be slow to respond.
View GitHub Profile
@duythinht
duythinht / file_to_bytes.c
Created March 7, 2016 18:09
Write integer as bytes
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int n = 1000000;
int i = 0;
@duythinht
duythinht / example.nomad
Last active April 20, 2016 21:34
Nomad job specification
# There can only be a single job definition per file.
# Create a job with ID and Name 'whereami'
job "whereami" {
# Run the job in the global region, which is the default.
# region = "global"
# Specify the datacenters within the region this job can run in.
datacenters = ["dc1"]
# Service type jobs optimize for long-lived services. This is
@duythinht
duythinht / index.js
Created September 7, 2016 08:32
Restart on demand
const cluster = require('cluster')
var logger = require('log4js').getLogger()
var locator = require('consul-locator')
locator.use({host: '10.60.3.231'})
logger.info('Start workers')
function startWorker(name) {
@duythinht
duythinht / app.py
Created November 11, 2016 07:08
What is jsonp?
from bottle import *
import json
@get('/users/:id')
def get(id):
# Check if request has callback query, return jsonp
if request.query.callback:
return request.query.callback + "(%s);" % json.dumps(user_by_id(id))
# else return json p
return user_by_id(id)
@duythinht
duythinht / concept.go
Created November 22, 2016 05:08
Try, error handling with Go.
func func1(returnError bool) (&bool, error);
result, error := Do(func(try) {
result0 := try.F1(func1(false))
result1 := try.F1(func1(!result0))
result2 := try.F1(func1(result1))
})
@duythinht
duythinht / test.js
Created November 23, 2016 04:37
AlertXSS
alert('hello world');
@duythinht
duythinht / main.go
Created December 2, 2016 08:54
println! still done!
package main
import (
"fmt"
"os"
"time"
)
func println(id int, done chan bool, messages <-chan string, result chan int) {
for message := range messages {
with open("values.txt") as f:
key_pairs = (line.split("=") for line in f.readlines())
values = {item[0]: item[1] for item in key_pairs}
@duythinht
duythinht / buffers.Image.go
Last active March 29, 2018 14:32
Flatbuffers for mirage
// automatically generated by the FlatBuffers compiler, do not modify
package buffers
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type Image struct {
_tab flatbuffers.Table
@duythinht
duythinht / README.MD
Last active June 10, 2019 16:36
That was a thing, which I want.
  • Must have Dockerfile inside project, that able to run docker built -t test:1.0.0 ./
  • Image must be expose port as 80
  • Image after build could run directly without any config file, config only accept to inject by environment variables
docker run -e "MYSQL_HOST=127.0.0.1" -e "MYSQL_USERNAME=root" test:1.0.0
  • Must have Jenkins file follow this pattern
pipeline {
    agent any