This file contains hidden or 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 scala.io.Source | |
var filea = Source.fromFile("filea").mkString | |
var fileb = Source.fromFile("fileb").mkString | |
var merged = filea + fileb | |
print(merged) | |
This file contains hidden or 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
<ul> | |
<li>Install <a href="http://chocolatey.org/">Chocolatey</a></li> | |
<li>Open powershell (as admin) and enter "cinst git.commandline"</li> | |
<li>Environment variable: GIT_SSH = C:\git\bin\ssh.exe</li> | |
<li>Put your keys into ~/.ssh</li> | |
</ul> | |
Optional steps:<br /> | |
Add C:\git\bin to your PATH, if needed<br /> | |
SSH stuff can be found in C:\git\bin |
This file contains hidden or 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 get_random(collection, query={}): | |
'''Gets a random record from a mongo collection''' | |
random_num = random.random() | |
query.update({'random' : {'$gte' : random_num}}) | |
result = collection.find_one(query) | |
if not result: | |
query.update({'random' : {'$lt' : random_num}}) | |
result = collection.find_one(query) | |
return result |
This file contains hidden or 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
rsync -avz /path/to/local/sync/folder -e "ssh -i /path/to/ssh/key" ubuntu@ec2instance:/path/to/remote/sync/folder |
This file contains hidden or 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
# Download and unzip spark to your home directory | |
# You may want to run update if it's on a fresh OS | |
sudo apt-get update | |
# Install dependencies (& verify) | |
sudo apt-get install default-jdk scala git | |
java -version; javac -version; scala -version; git --version | |
# Configure - run these in your open terminal and add them to ~/.bashrc |
This file contains hidden or 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
from __future__ import print_function | |
import sys | |
import time | |
print('Executing...', end='') | |
sys.stdout.flush() | |
time.sleep(2) | |
print('Done.') |
This file contains hidden or 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 multiprocessing | |
import StringIO | |
# function to be run on each line of file | |
def f(x): | |
print x, | |
# Create mock file | |
mock_file = StringIO.StringIO() | |
for i in range(20): |
This file contains hidden or 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 StringIO | |
# Create mock file | |
mock_file = StringIO.StringIO() | |
for i in range(20): | |
mock_file.write("{}\n".format(i)) | |
mock_file.seek(0) | |
# Do something | |
for line in mock_file: |
This file contains hidden or 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
other_var = 42 | |
try: | |
print 1/0 | |
except Exception as e: | |
print "\nError encountered. Other var = {}\n".format(other_var) | |
raise e | |
print 'You will not see this text' |
This file contains hidden or 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 time | |
from progress.bar import Bar # sudo pip install progress | |
bar = Bar('Processing', max=20, suffix='%(index)d/%(max)d - %(percent).1f%% - %(eta)ds') | |
for i in range(20): | |
time.sleep(.05) # Do some work | |
bar.next() | |
bar.finish() |