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
| const week = (date) => date.getDay()% 6 !== 0; | |
| console.log(week(new Date(2021, 0, 11))); // Result: true (Monday) | |
| console.log(week(new Date(2021, 0, 15))); // Result: false (Sunday) |
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
| const randomBoolean = () => Math.random() >= 0.5; | |
| console.log(randomBoolean()); |
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 | |
| start_time = time.time() | |
| for loop in range(1, 100000000): | |
| pass | |
| print('FINISHED EXECUTION') | |
| print("--- %s seconds ---" % round(time.time() - start_time, 4)) |
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
| // ==UserScript== | |
| // @name Geoguessr Cheat | |
| // @namespace https://www.leonbrandt.com | |
| // @version 2.0.0 | |
| // @description Press SHIFT + ALT + G and the location of your current geoguessr game will open in a new tab | |
| // @author Leon Brandt | |
| // @homepage https://www.leonbrandt.com | |
| // @updateURL https://gist.githubusercontent.com/leonbrandt/16b3a70ef70939359357c908e6b0f06d/raw/geoguessr-cheat.user.js | |
| // @match http*://*/* | |
| // @grant none |
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
| torch.save(model.state_dict(), 'model.ckpt') |
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
| with torch.no_grad(): | |
| correct = 0 | |
| total = 0 | |
| for images, labels in test_loader: | |
| images = images.to(device) | |
| labels = labels.to(device) | |
| outputs = model(images) | |
| _, predicted = torch.max(outputs.data, 1) | |
| total += labels.size(0) | |
| correct += (predicted == labels).sum().item() |
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
| # Train the model | |
| total_step = len(train_loader) | |
| for epoch in range(num_epochs): | |
| for i, (images, labels) in enumerate(train_loader): | |
| # Move tensors to the configured device | |
| images = images.to(device) | |
| labels = labels.to(device) | |
| # Forward pass | |
| outputs = model(images) |
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
| model.to(device) |
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
| optimizer = torch.optim.Adam(model.parameters(), lr=0.001) | |
| loss_function = nn.CrossEntropyLoss() |
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
| # MNIST dataset | |
| train_dataset = torchvision.datasets.MNIST(root='data', | |
| train=True, | |
| transform=transforms.ToTensor(), | |
| download=True) | |
| test_dataset = torchvision.datasets.MNIST(root='data', | |
| train=False, | |
| transform=transforms.ToTensor()) |