Skip to content

Instantly share code, notes, and snippets.

View J3698's full-sized avatar
๐Ÿ›
Inch Worm

Anti J3698

๐Ÿ›
Inch Worm
  • Working
  • Working
View GitHub Profile
@J3698
J3698 / deleter.js
Last active April 23, 2020 06:24
Deletes the SIO popup
function deletePopup() {
// check if the backdrop exists
var dialogBox = document.getElementsByClassName("gwt-DialogBox");
if (dialogBox.length != 0) {
dialogBox = dialogBox[0];
// if backdrop exists, check if message matches "have you spoken..."
caption = dialogBox.getElementsByClassName("Caption")[0].innerHTML;
if (caption == "Have You Spoken to Your Advisor?") {
// remove!!!!!!!!
dialogBox.parentNode.removeChild(dialogBox);
@J3698
J3698 / manifest.json
Created April 23, 2020 06:21
Manifest for ISpokeToMyAdvisor
{
"name": "ISpokeToMyAdvisor",
"version": "1.0",
"description": "Hide the \"Have you spoken to your advisor?\" message on SIO.",
"permissions": ["activeTab"],
"content_scripts": [
{
"matches": ["https://s3.andrew.cmu.edu/*"],
"js": ["deleter.js"]
}
@J3698
J3698 / queries-setup.js
Created May 24, 2020 16:45
Setup pg in node
const assert = require('assert');
const Pool = require('pg').Pool;
const pool = new Pool({
user: 'me',
host: 'localhost',
database: 'urlmem',
password: 'password',
port: 5432,
});
/*
* Create a shortening and return the shorturl if successful. Returns null if
* the shorturl already exists and is not the requested shortening, or if the
* longurl already has a random shortening and this shortening is also random.
*
* May throw other db errors.
*/
const addShortening = async (shortUrl, longUrl, isRandom) => {
let addShorteningQuery = 'INSERT INTO shortenings (shorturl, longurl, israndom) VALUES ($1, $2, $3)';
@J3698
J3698 / create_stylized_image.py
Created January 28, 2021 01:28
create stylized image
def create_stylized_image(decoder, content_features, style_features):
stylized_content_features = adain(content_features[-1], style_features[-1])
stylized_image = decoder(stylized_content_features)
return stylized_image, stylized_content_features
@J3698
J3698 / get_batch_style_transfer_loss.py
Created January 28, 2021 01:55
get batch style transfer loss
def get_batch_style_transfer_loss(encoder, decoder, style_image, content_image):
style_features = encoder(style_image)
content_features = encoder(content_image)
stylized_image, stylized_features = create_stylized_image(decoder, content_features, style_features)
features_of_stylized = encoder(stylized_image)
style_loss = compute_style_loss(features_of_stylized, style_features)
content_loss = compute_content_loss(features_of_stylized, stylized_features)
@J3698
J3698 / login.py
Last active February 2, 2021 19:00
Duo
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
def login_to_autolab(wd, username, password):
wd.get("https://autolab.andrew.cmu.edu")
class IterableStyleTransferDataset(IterableDataset):
def __init__(self, coco_path, coco_annotations, \
wiki_path, length = 100000, transform = None, rng_seed = 1, exclude_style = False):
self.wiki = ImageFolder(wiki_path, transform = transform)
self.coco = CocoCaptions(coco_path, coco_annotations, transform = transform)
self.length = length
self.exclude_style = exclude_style
self.seed = rng_seed
def get_transforms(crop):
if crop:
return Compose([Resize(512), RandomCrop(256), ToTensor()])
return Compose([Resize((256, 256)), ToTensor()])
def main():
transforms = get_transforms()
dataset = StyleTransferDataset("datasets/coco/train2017", "datasets/coco/annotations/captions_train2017.json", "datasets/wikiart", transform = transforms)
print(f"Dataset length: {len(dataset)}, Wiki length: {len(dataset.wiki)}, COCO length: {len(dataset.coco)}")
content, style = dataset[0]
print(f"1st content img: {type(content)}, {content.shape}")
print(f"1st style img: {type(style)}, {style.shape}")