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
########## | |
# Tweaked Win10 Initial Setup Script | |
# Primary Author: Disassembler <disassembler@dasm.cz> | |
# Original Version: 1.4, 2016-01-16 | |
# Tweaked based on personal preferences for @alirobe 2016-03-23 - v1.4.1 | |
# NOTE: MAKE SURE YOU READ THIS SCRIPT CAREFULLY BEFORE RUNNING IT + ADJUST COMMENTING AS APPROPRIATE | |
# This script will reboot your machine when completed. | |
########## | |
# Ask for elevated permissions if required |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
print('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
:%s/foo/bar/g | |
Find each occurrence of 'foo' (in all lines), and replace it with 'bar'. | |
:s/foo/bar/g | |
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'. | |
:%s/foo/bar/gc | |
Change each 'foo' to 'bar', but ask for confirmation first. | |
:%s/\<foo\>/bar/gc | |
Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation. |
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
# Wrtie to file (w write) | |
f = open('helloworld.txt','w') | |
f.write('hello world') | |
f.close() | |
# Write to BINARY file (wb write binary) | |
f = open('database_file','wb') | |
f.write('hello world') | |
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
# Import whole module | |
import subprocess | |
# Import selected calls from module | |
from subprocess import Popen, PIPE | |
process = Popen(['cat', 'test.py'], stdout=PIPE, stderr=PIPE) | |
stdout, stderr = process.communicate() | |
print(stdout) |
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
# Use this format | |
# username:value | |
# password:value | |
# Assuming no : characters in your usernames or passwords | |
with open('myfile.txt') as f: | |
credentials = [x.strip().split(':') for x in f.readlines()] | |
for username,password in credentials: | |
# your code here |
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
# Replacing shell pipeline | |
# output=`dmesg | grep hda` | |
# becomes: | |
p1 = Popen(["dmesg"], stdout=PIPE) | |
p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) | |
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. | |
output = p2.communicate()[0] | |
#Alternatively: |
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 module | |
import logging | |
# Logging to console | |
logging.warning('Watch out!') # will print a message to the console | |
logging.info('I told you so') # will not print anything | |
>>>WARNING:root:Watch out! | |
# Logging to a file | |
logging.basicConfig(filename='example.log',level=logging.DEBUG) |
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
exclude = ['dir1','dir2'] | |
def zipdir(path, ziph, exclude): | |
'''Zip up the directory excluding some subdirs''' | |
# ziph is zipfile handle | |
for dirname, subdirs, files in os.walk(path): | |
subdirs[:] = [d for d in subdirs if d not in exclude] | |
for file in files: | |
ziph.write(os.path.join(dirname, file)) |
OlderNewer