Skip to content

Instantly share code, notes, and snippets.

View LiamHz's full-sized avatar

Liam Hinzman LiamHz

View GitHub Profile
@LiamHz
LiamHz / powershell_grep.txt
Last active October 13, 2018 01:07
Search through current directory for any matches of specified text
# Search through current directory and all sub directories for text
dir -Recurse | Select-String -pattern "STRING"
# Recursive search and table formatting
dir -Recurse | Select-String -pattern "latest_net_G" | Select Path, LineNumber, Line | Format-Table
# Search through all files with the .EXT extension in the current directory
# and find any lines that match with STRING
from slackclient import SlackClient
slack_client = SlackClient(SLACK_OAUTH)
# Print a list of users and their respective IDs
request = slack_client.api_call("users.list")
if request['ok']:
for item in request['members']:
print("{}: {}".format(item['name'], item['id']))
# Trim ending characters of a filename of every file in a folder
Get-ChildItem 'FOLDER_NAME' | rename-item -newname { $_.name.substring(0, $_.name.length-N) }
# Trim beginning N characters of a filename of every file in a folder
get-childitem *.txt | rename-item -newname { [string]($_.name).substring(N) }
# Append a file extension to every file in a folder
Get-ChildItem 'FOLDER_NAME' | rename-item -NewName {$_.FullName + ".pdf"}
# Append text to every filename BEFORE the file extension
// Read authentication credentials from file
var fs = require('fs');
fs.readFile('credentials.txt', 'utf8', function(err, contents) {
var text = contents.split("\n")
text[1] = text[1].substring(0, text[1].length - 1);
text[2] = text[2].substring(0, text[2].length - 1);
username = text[1];
password = text[2];
});
@LiamHz
LiamHz / Voronoi.py
Last active August 29, 2018 17:13
Solution to S1 of the 2018 CCC
#Number of villages
N = int(input())
#List of village positions
villages = list()
for i in range(N):
villages.append(float(input()))
#List of distances between villages
distances = list()