Skip to content

Instantly share code, notes, and snippets.

@wiennat
wiennat / haproxy.service
Created December 16, 2017 06:26
haproxy unit file for ubuntu
[Unit]
Description=HAProxy Load Balancer
Documentation=man:haproxy(1)
Documentation=file:/usr/share/doc/haproxy/configuration.txt.gz
After=network.target rsyslog.service
[Service]
# You can point the environment variable HAPROXY_STATS_SOCKET to a stats
# socket if you want seamless reloads.
EnvironmentFile=-/etc/default/haproxy
@wiennat
wiennat / ForEachWhile.cs
Last active August 29, 2015 13:59
Comparison between foreach and while over IEnumerable
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace ForEachWhile
{
class Program
{
static IEnumerable<int> Foo(int n)
{
@wiennat
wiennat / gist:8936671
Created February 11, 2014 15:12
if (A xor B) xor (A xor C) === (B xor C)?
A = '00001111'
B = '00110011'
C = '01010101'
def to_bool(s):
return map(lambda c: True if c == '1' else False, s)
def xorTuple(el):
return el[0] != el[1]
def main():
function mkdir_if_not_exist(dirpath)
if dirpath(end) ~= '/', dirpath = [dirpath '/']; end
if (exist(dirpath, 'dir') == 0), mkdir(dirpath); end
end
@wiennat
wiennat / ExampleOfObject.js
Created August 3, 2012 08:30 — forked from punneng/ExampleOfPrivateMemberDeclaring.js
How to declare private properties/methods
function myPowerConstructor(x) {
var that = otherMaker(x);
var secret = f(x);
that.priv = function () {
... secret x that ...
};
return that;
}
@wiennat
wiennat / ExampleOfObject.js
Created August 3, 2012 08:29 — forked from punneng/ExampleOfPrivateMemberDeclaring.js
How to declare private properties/methods
function myPowerConstructor(x) {
var that = otherMaker(x);
var secret = f(x);
that.priv = function () {
... secret x that ...
};
return that;
}
@wiennat
wiennat / forloop.bat
Created November 1, 2011 02:53
For loop in bat file
for %%i in (*.txt) do echo %%i
Sometimes we want only filename. Use %~n1 instead
Ex.
for %%~ni in (*.txt) do echo %%~ni
class Point:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
def linear(a, b, t):
c = Point()
c.x = (b.x - a.x)*t + a.x
c.y = (b.y - a.y)*t + a.y
return c
def edict_to_dict(edict):
return dict([(key, val) for key, val in edict.iteritems()])
import simplejson
def json_response(request, obj):
return HttpResponse(simplejson.dumps(obj))