This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.6+ | |
# After Python 2.6, you can choose to use .format() function or the old %. | |
>>> '{0}, {1}, {2}'.format('a', 'b', 'c') | |
'a, b, c' | |
>>> '{2}, {1}, {0}'.format('a', 'b', 'c') | |
'c, b, a' | |
>>> '{2}, {1}, {0}'.format(*'abc') # unpacking argument sequence | |
'c, b, a' | |
>>> '{0}{1}{0}'.format('abra', 'cad') # arguments' indices can be repeated | |
'abracadabra' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.net.ssl.*; | |
import java.io.*; | |
import java.nio.ByteBuffer; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.zip.Deflater; | |
/* | |
* This is a simple implementation of the Lumberjack client. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# flask/config.py | |
def __repr__(self): | |
return '<%s %s>' % (self.__class__.__name__, dict.__repr__(self)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import subprocess | |
def available_cpu_count(): | |
""" Number of available virtual or physical CPUs on this system, i.e. | |
user/real as output by time(1) when called with an optimally scaling | |
userspace-only program""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Build Nginx 1.5.7 on Mac OS X Mavericks (10.9) | |
# This script was created by Kevin Worthington - http://kevinworthington.com/ - 12 December 2013 | |
# Original article at: http://kevinworthington.com/nginx-for-mac-os-x-mavericks-in-2-minutes/ | |
# This useful script is provided for free, but without warranty. Use at your own risk. | |
# By downloading this script you agree to the terms above. | |
# create, then go into the build directory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cluster and Node | |
# Note: We should always set the cluster name and nodes' name specifically. | |
# | |
cluster.name: elasticsearch_prod | |
node.name: elasticsearch_001 | |
#node.(attribute): (attibute_value) | |
# | |
# Index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import scipy.sparse as sparse | |
import numpy as np | |
def plsa(n_dw, n_z=2, iter_num=100): | |
""" | |
Fit a PLSA model on given data, | |
in which n_dw(d, w) is the number of occurrence of word w | |
in document d, d, n_z is the number of topic to be discovered | |
:param n_dw: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In Python 2.6 and earlier, the dict constructor can receive an iterable of key/value pairs: | |
d = dict((key, value) for (key, value) in iterable) | |
# From Python 2.7 and 3 onwards, you can just use the dict comprehension syntax directly: | |
d = {key: value for (key, value) in iterable} | |
# Of course, you can use the iterable in any way you want (tuples and lists literals, generator comprehensions, list comprehensions, generator functions, functional composition... feel creative) as long as each element is an iterable itself of two elements: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def echoWhatYouGiveMe(x: Any): String = x match { | |
// constant patterns | |
case 0 => "zero" | |
case true => "true" | |
case "hello" => "you said 'hello'" | |
case Nil => "an empty List" | |
// sequence patterns | |
case List(0, _, _) => "a three-element list with 0 as the first element" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Reference: http://stackoverflow.com/questions/418898/sqlite-upsert-not-insert-or-replace | |
-- Approach #1: Select original values before insertion. | |
-- demo table 'emplyee' | |
CREATE TABLE employee ( | |
id INTEGER PRIMARY KEY, | |
role TEXT, | |
name TEXT); | |
-- This will update 2 of the columns. When ID=1 exists, the NAME will be unaffected. When ID=1 does not exist, the name will be default (NULL). |
OlderNewer