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 / 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 / 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 / postactivate
Created March 1, 2016 04:10
.virtualenvs/postactivate
#!/bin/zsh
# This hook is sourced after every virtualenv is activated.
PS1="$_OLD_VIRTUAL_PS1"
_OLD_RPROMPT="$RPROMPT"
RPROMPT="%{${fg_bold[white]}%}「 %{${fg[green]}%}`basename \"$VIRTUAL_ENV\"`%{${fg_bold[white]}%} 」%{${reset_color}%}$RPROMPT"
[user]
name = Thinh Tran
email = [email protected]
[push]
default = current
[core]
excludesfile = /Users/duythinht/.gitignore_global
editor = /usr/bin/vim
[difftool "sourcetree"]
from flask import Blueprint
from flask import request
module = Blueprint('api_users', __name__)
@module.route('/', methods=['GET'])
def list():
pass
<?php
//This code read the necessary data form the standard input
function isPrime($n) {
if ($n == 1) return false;
if($n == 2) return true;
if ($n % 2 == 0) return false;
for($i = 3; $i <= ceil(sqrt($n)); $i = $i + 2) {
@duythinht
duythinht / .tmux.conf
Last active August 29, 2015 14:06
VIM working Environment
#set-option -g default-command "reattach-to-user-namespace -l bash"
set -g default-terminal "screen-256color"
set -g base-index 1
set -g pane-base-index 1
#### COLOUR (Solarized 256)
# default statusbar colors
@duythinht
duythinht / move.py
Created September 2, 2014 13:28
VIM moving
# Go to line 3
3 G
# Delete from line 3 to 6
3 G
d 6 G
# copy to clipboard
" + Y
# paste from clipboard
" + P
# Go to 3 words as begin
@duythinht
duythinht / upload_api.py
Created August 26, 2014 15:54
Upload file via flask with appengine
from flask import Blueprint
from flask import render_template as render
from flask import request, Response
import cloudstorage as gcs
from google.appengine.api import app_identity
from os import environ
from json import dumps
module = Blueprint('API_UPLOAD', __name__)

App Engine update cloudstorage using SDK and GAE production

This code shows how to read and write blobs and how to create a serving url.

The blobfiles can be images or other files like css, js and pdf's. We use the default bucket in Google Cloud Storage (GCS) to store the blobs.
From the docs: An application can use the default GCS bucket, which provides an already configured bucket with free quota.

This code still needs the blobstore.create_gs_key() for images.get_serving_url()
We use an image serving url for dynamic resizing and cropping.