Skip to content

Instantly share code, notes, and snippets.

View kangfend's full-sized avatar
🏠

Sutrisno Efendi kangfend

🏠
View GitHub Profile

Writing better python code


Swapping variables

Bad code

#!/bin/bash
NAME="hello_app" # Name of the application
DJANGODIR=/webapps/hello_django/hello # Django project directory
SOCKFILE=/webapps/hello_django/run/gunicorn.sock # we will communicte using this unix socket
USER=hello # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=hello.settings # which settings file should Django use
DJANGO_WSGI_MODULE=hello.wsgi # WSGI module name
@kangfend
kangfend / helloworld-win32-service.py
Created December 15, 2015 08:53 — forked from drmalex07/helloworld-win32-service.py
An example Windows service implemented with pywin32 wrappers. #python #windows-service #pywin32
import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import time
import logging
logging.basicConfig(
filename = 'c:\\Temp\\hello-service.log',
@kangfend
kangfend / README.md
Created January 11, 2016 12:02 — forked from smileart/README.md
My ZSH Theme — Agnoster Mod

My modified fork of agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

Compatibility

@kangfend
kangfend / beautiful_idiomatic_python.md
Created July 1, 2016 12:45 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:

Multiple MySQL Versions with Homebrew

For homebrew version 0.9.5.

brew -v # => Homebrew 0.9.5

Install the current version of mysql.

# Install current mysql version

brew install mysql

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright © 2016 Sutrisno Efendi <kangfend@gmail.com>
# Auto download video from akhyar.tv
import argparse
import os
import re
import requests
<table class="MsoNormalTable"
style="background:white;border-collapse:collapse"
cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td style="border:none;border-left:solid #F8941C
2.25pt;padding:0in 0in 0in 6.0pt" valign="top">
<p class="MsoNormal"><span
style="font-size:11.5pt;font-family:&quot;Arial&quot;,sans-serif;color:#222222">Natasia Liu<o:p></o:p></span></p>
<p class="MsoNormal"><b><span
@kangfend
kangfend / nginx-tuning.md
Created December 14, 2017 07:08 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@kangfend
kangfend / gist:1e90caffb642cfa869266032860e1983
Created March 6, 2018 09:57 — forked from grandmanitou/gist:8863248
Place multiple markers with infowindow on Google Maps API v3, use external links to trigger click and center map on desired location.
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?language=fra&amp;sensor=false"></script>
<script type="text/javascript">
var map;
var Markers = {};
var infowindow;
var locations = [
[
'Samsung Store Madeleine',
'<strong>Samsung Store Madeleine</strong><p>5 Boulevard Malesherbes, 75008 Paris<br>10h – 20h</p>',
48.8701925,