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
var Promise = require('bluebird'); | |
var funcs = Promise.resolve([500, 100, 400, 200].map((n) => makeWait(n))); | |
funcs | |
.each(iterator) // logs: 500, 100, 400, 200 | |
.then(console.log) // logs: [ [Function], [Function], [Function], [Function] ] | |
funcs | |
.mapSeries(iterator) // logs: 500, 100, 400, 200 |
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
typedef int (*MathFunc)(float, int); | |
int do_math(float arg1, int arg2) { | |
return arg2; | |
} | |
int call_a_func(MathFunc call_this) { | |
int output = call_this(5.5, 7); | |
return output; | |
} |
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 java.io.File; | |
import java.io.IOException; | |
public class TmpDirExample { | |
public static void main(String[] args) { | |
String tmpdir = System.getProperty("java.io.tmpdir"); | |
System.out.println("The default value of the java.io.tmpdir system property is: \"" | |
+ tmpdir + "\"\n"); |
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
public class Test { | |
private int num; | |
private String data; | |
public boolean equals(Object obj) { | |
if (this == obj) { | |
return true; | |
} | |
if ((obj == null) || (obj.getClass() != this.getClass())) { |
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
# HTML Encoding | |
try: | |
from html import escape # python 3.x | |
except ImportError: | |
from cgi import escape # python 2.x | |
print(escape("<")) | |
# HTML Decoding | |
try: |
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.x | |
import os.path | |
os.path.isfile(fname) | |
# Python 3.4 | |
from pathlib import Path | |
my_file = Path("/path/to/file") | |
if my_file.is_file(): | |
# file exists |
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 main_func.py | |
def main(): | |
print("Hello from main()") | |
if __name__ == '__main__': | |
main() |
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
## Open the file with read only permit | |
f = open('myTextFile.txt', "r") | |
## use readlines to read all lines in the file | |
## The variable "lines" is a list containing all lines | |
lines = f.readlines() | |
## close the file after reading the lines. | |
f.close() |
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 square(x): | |
return x**2 | |
squares = map(square, range(10)) |
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 re | |
testStr = "//gss0.baidu.com/6b1IcTe9R1gBo1vgoIiO_jowehsv/maps/services/thumbnails?width=525&height=295&quality=100&align=middle,middle&src=http://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/lvpics/pic/item/8cb1cb134954092315ec8fd29258d109b2de4991.jpg" | |
pattern = "http.*jpg" | |
m = re.search(pattern, testStr) | |
print(m.group(0)) | |
# http://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/lvpics/pic/item/8cb1cb134954092315ec8fd29258d109b2de4991.jpg |
OlderNewer