Skip to content

Instantly share code, notes, and snippets.

View waitgroup_demo.go
func WaitGroupDemo() {
var wg sync.WaitGroup
var urls = []string{
"http://www.golang.org/",
"http://www.google.com/",
"http://www.somestupidname.com/",
}
for _, url := range urls {
// Increment the WaitGroup counter.
wg.Add(1)
@kratorado
kratorado / Dockerfile
Created Oct 30, 2015
Dockerfile for django
View Dockerfile
FROM ubuntu:trusty
MAINTAINER Krator <kratorado@gmail.com>
RUN (echo "deb http://cn.archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse" > /etc/apt/sources.list && echo "deb http://cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse" >> /etc/apt/sources.list && echo "deb http://cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list && echo "deb http://cn.archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse" >> /etc/apt/sources.list)
RUN apt-get update && apt-get install -y \
sqlite3 \
python3-pip \
--no-install-recommends && rm -rf /var/lib/apt/lists/*
@kratorado
kratorado / log4j.xml
Created Apr 11, 2014
log4j xml example
View log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>
@kratorado
kratorado / merge_sort.py
Created Mar 2, 2014
This is a demo for merge sort
View merge_sort.py
# This is a demo for merge sort
# Coded according to pseudocode from Introduction.to.Algorithm
INF = float('inf')
def merge(lst, p, q, r):
left = lst[p:q + 1]
left.append(INF)
right = lst[q + 1:r + 1]
@kratorado
kratorado / blog.py
Created Feb 11, 2014
auto select current user in Django admin site
View blog.py
# models.py
from django.db import models
class Blog(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
title = models.CharField(max_length=255)
content = models.TextField()
# forms.py