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
#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() |
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
// 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]; | |
}); |
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
# 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 |
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
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'])) |
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
# 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 |
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 json | |
# Read variables from disk | |
with open('data.json', 'r') as json_file: | |
data = json.load(json_file) | |
a = data['a'] | |
b = data['b'] | |
c = data['c'] | |
d = data['d'] |
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 pickle | |
data = {} | |
# Read from disk | |
pickle_jar = open('data.pkl', 'rb') | |
data = pickle.load(pickle_jar) | |
# Write to disk | |
pickle_jar = open('data.pkl', 'wb') |
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
# Calculate the average squared error between two high-level layer activations | |
content_loss = torch.mean((target_features['conv4_2'] - content_features['conv4_2'])**2) |
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 gram_matrix(tensor): | |
# Get the batch_size, depth, height, and width of the Tensor | |
# Reshape it, so we're multiplying the features for each channel | |
_, d, h, w = tensor.size() | |
tensor = tensor.view(d, h*w) | |
# Calculate the gram matrix by multiplying the tensor with its transpose | |
gram = torch.mm(tensor, tensor.t()) | |
return gram |
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
show_every = 400 # Show target image every x steps | |
optimizer = optim.Adam([target], lr=0.003) # Optimizer hyperparameters | |
steps = 2000 # How many iterations to update content image | |
# Training Loop | |
for ii in range(steps): | |
# Calculate the content loss | |
target_features = get_features(target, vgg) | |
content_loss = torch.mean((target_features['conv4_2'] - content_features['conv4_2'])**2) |
OlderNewer