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 |
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
// If you are using Java 7, Files (in the standard library) is the best approach: | |
/* You can get Path from file also: file.toPath() */ | |
Files.copy(InputStream in, Path target) | |
Files.copy(Path source, OutputStream out) |
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 fs = require("fs"); | |
// Sync | |
var array = fs.readFileSync(path).toString().split('\n'); | |
// Async | |
fs.readFile(path, function(err, f){ | |
var array = f.toString().split('\n'); | |
// use the array | |
}); |
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
class HelloWorldApp { | |
public static void main(String[] args) { | |
System.out.println("Hello World!"); // Display the string. | |
} | |
} |
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 ArrBlockingQueue { | |
final private Lock _lock = new ReentrantLock(); | |
final private Condition _notFull = _lock.newCondition(); | |
final private Condition _notEmpty = _lock.newCondition(); | |
final private Object[] _items; | |
private int _putptr, _takeptr, _count; | |
public ArrBlockingQueue(final int size) { |
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 a = 10; | |
function add() { | |
var b = 20; | |
return a + b; // a is bound to the global a when the function object add() is created. | |
} | |
// call add() -> 30 | |
(function() { | |
var a = 20; |
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
mvn help:evaluate -Dexpression=settings.localRepository | grep -v '\[INFO\]' |
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 fs = require('fs'); | |
var dir = './tmp'; | |
if (!fs.existsSync(dir)){ | |
fs.mkdirSync(dir); | |
} |
OlderNewer