Skip to content

Instantly share code, notes, and snippets.

@jay-zhuang
jay-zhuang / gist:5251548
Last active December 15, 2015 11:18
sudo previous command
# sudo the previous command
sudo !!
# for example, apt-get will failed because current user is not root
apt-get install vim
sudo !!
# !! will be replaced with previous command, enter enter again to run
@jay-zhuang
jay-zhuang / gist:5289978
Last active December 15, 2015 16:29
Effective grep
# show more lines with -C
grep -C 2 "test" temp.log
# If there's a match, it will show two more lines before and
# after the match line.
# -A is for after, -B is for before
# -n : show the line number
# -l : just show the filename
# -i : case insesentive search
# -w : match the word
# -c : show the count number
str = "This is Jason, I'm a programmer."
if str.find("Jason") != -1:
foundYou = True
# Here is the Python way to do that:
if "Jason" in str:
foundYou = True
a = foo();
b = bar();
if myName:
# myName is exist and not empty
print "Hello " + myName
else:
print "Please input your name"
class customersSystem
def say_hello():
if customer_name and customer_name in customer_list:
print "hello " + customer_name
# the code needs to be change and it is longer than 80
if customer_name and customer_name in system_database.get_customer_list():
print "hello" + customer_name
# To format this code, "=" will not help you.
# overrider the class functions for test only
MyClass.ConnectServer = lambda *a, **kw: None
# simple lambda functions to override real function
def test_connection():
run_connection_fun(lambda: False)
run_connection_fun(lambda: True)
def run_connection_fun(connect_fun)
pass
sorted(customers, key=lambda c: c.name.last)
reduce(lambda x, y: x.balance + y.balance, customers)
map(lambda x: x*x*x, range(1, 11))
# [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
filter(lambda x: x%2 != 0 and x%3 != 0, range(2, 25))
# [5, 7, 11, 13, 17, 19, 23]
.
|-- prj1
|-- prj2
|-- prj3
|-- prj4
`-- tags
Processing response from /ip1 | 5497 | SharedPool-Worker-318
Sending read-repair-mutation to /ip1 | 5628 | SharedPool-Worker-380
Sending READ_REPAIR message to /ip1 | 5681 | MessagingService-Outgoing-/ip1
READ_REPAIR message received from /ip1 | 5809 | MessagingService-Incoming-/ip1
Timed out while read-repairing after receiving all 6 data and digest responses | 2005779 | SharedPool-Worker-380