Skip to content

Instantly share code, notes, and snippets.

View scari's full-sized avatar
💭
sprinting on

Younggun Kim scari

💭
sprinting on
View GitHub Profile
@scari
scari / gist:5772280
Created June 13, 2013 09:00
post_action with named location
location / {
uwsgi_pass unix:app.sock;
post_action @post_action;
}
location @post_action {
proxy_pass http://dst_host:dst_port;
}
import httplib2, sys, os, base64, hashlib, hmac, time
import json as simplejson
from urllib import urlencode, quote_plus
aws_key = ''
aws_secret_key = ''
hostname = open('/etc/hostname').read().rstrip()
# XXX: For now, those two names are same. but should be distinguished.
instanceid = hostname
@scari
scari / make_data_vol.sh
Created September 25, 2013 17:07
Initialize ucloud data volume. (for default diskofferingid)
#!/bin/bash
sfdisk /dev/xvdb <<< "1,,8e" # one big Linux LVM type partition
if [ $? != 0 ]; then
echo "No data disk?"
exit 1
fi
pvcreate /dev/xvdb1
vgcreate VolGroup /dev/xvdb1
lvcreate -L 80g -n data00 VolGroup # Just try to create 80g vol.. Mostly failed
@scari
scari / get_evenly.py
Created January 8, 2014 12:12
get evenly parted image from a video
#!/usr/bin/env python
import sys, os, re
from subprocess import *
# get_evenly.py videofile #of_thumbnails - 1
try:
fvideo = sys.argv[1]
frames = float(sys.argv[2])
except:
@scari
scari / gist:21c297bf71ca4fa92bd1
Created March 10, 2014 09:07
get administrative name for given lat/lng
import psycopg2
from flask import Flask, request
app = Flask(__name__)
app.debug = True
conn = psycopg2.connect(host='', database='', user='', password='')
@app.route('/city', methods=['GET'])
def city():
print 'city'
@scari
scari / send_gmail.py
Created August 4, 2014 11:21
send gmail
def send_gmail(to = None, subject = '', content = ''):
gmail_user = ""
gmail_pwd = ""
message = u'\From: {}\nTo: {}\nSubject: {}\n\n{}'.format(gmail_user, to, subject, content)
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
@scari
scari / clock_realtime
Created December 4, 2014 02:01
using posix clock example
#include <time.h>
#include <stdio.h>
int
main(int argc, char* argv[]) {
struct timespec ts;
struct timespec delay = { .tv_sec = 0, .tv_nsec = 1000 };
int res = -1;
clockid_t clk = CLOCK_REALTIME;
@scari
scari / spiral.py
Created December 4, 2014 02:03
print NxM array in spiral form
#!/usr/bin/env python3
def change_direction(dx, dy):
# not allowed!
if abs(dx+dy) != 1:
raise ValueError
if dy == 0:
return dy, dx
if dx == 0:
return -dy, dx
@scari
scari / fibonachicken.py
Last active August 29, 2015 14:11
Find fibonachicken number
# Copyright (c) 2014, Younggun Kim
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@scari
scari / merge_to_sub.sh
Last active August 29, 2015 14:13
Import existing git repo into sub directory of another git repo.
#!/bin/bash
# NOTE:
# You couldn't track original branch (which would imported under current repo) history from current repo.
if [ "$#" -ne 2 ]; then
echo "Usage: $0 prefix url"
exit 0
fi
NAME=$1