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 datetime import datetime | |
str_datetime = "2022-04-11" | |
_until_time_created_unaware = datetime.strptime(str_datetime, "%Y-%M-%d") if str_datetime!= "" else datetime.now() | |
until_datetime_created_unaware = _until_time_created_unaware.replace(hour=23, minute=59, second=59) | |
until_datetime_created_aware = pytz.utc.localize(until_datetime_created_unaware) |
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 torch | |
from torch import nn | |
from labml import experiment | |
from labml.configs import option | |
from labml_helpers.module import Module | |
from labml_nn.experiments.nlp_classification import NLPClassificationConfigs | |
from labml_nn.transformers import Encoder | |
from labml_nn.transformers import TransformerConfigs |
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 chardet | |
import codecs | |
infile = 'unreadable.txt' | |
outfile = 'readable.txt' | |
with open(infile,'rb') as raw_file: | |
result = chardet.detect(raw_file) | |
char_enc = result['encoding'] | |
with open(outfile, 'r', charenc): | |
read_as_utf = f.read() | |
out = codecs.open(outfile, 'w', 'utf-8') |
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 matplotlib.pyplot as plt | |
def label_prop_test(model, kernel, params_list, X_train, X_test, y_train, y_test): | |
plt.figure(figsize=(20,10)) | |
n, g = 0, 0 | |
roc_scores = [] | |
if kernel == 'rbf': | |
for g in params_list: | |
lp = model(kernel=kernel, n_neighbors=n, gamma=g, max_iter=100000, tol=0.0001) | |
lp.fit(X_train, y_train) | |
roc_scores.append(roc_auc_score(y_test, lp.predict_proba(X_test), multi_class='ovo')) |
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
# This is an application transferring csv data into database | |
# We choose a NoSQL database MongoDB since we have to store data and the logs of data GET requests# We prefer to choose PostgreSQL rather than MySQL(purely relation) or SQLite (no concurrency support) | |
import json | |
import csv | |
import pandas as pd | |
import os | |
from pymongo import MongoClient | |
cwd = os.path.dirname(__file__) | |
csvpath=os.path.join(cwd,'task_data.csv') |
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 itertools | |
def countPairs(arr): | |
# Write your code here | |
count = 0 | |
for i, j in itertools.combinations(arr, 2): | |
v = i & j | |
if v != 0 : | |
if (v % 2 == 0) | (v == 1): | |
count+=1 | |
return count |
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 numpy as np | |
from sklearn import linear_model | |
def desired_marketing_expenditure(marketing_expenditure, units_sold, desired_units_sold): | |
""" | |
:param marketing_expenditure: (list) A list of integers with the expenditure for each previous campaign. | |
:param units_sold: (list) A list of integers with the number of units sold for each previous campaign. | |
:param desired_units_sold: (integer) Target number of units to sell in the new campaign. | |
:returns: (float) Required amount of money to be invested. | |
""" |
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
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os" | |
"os/signal" |
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 os | |
import sqlite3 | |
import operator | |
from collections import OrderedDict | |
#path to user's history database (Chrome) | |
data_path = os.path.expanduser('~')+"/Library/Application Support/Google/Chrome/Default" | |
files = os.listdir(data_path) | |
history_db = os.path.join(data_path, 'history') | |
#querying the db |
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
CREATE TABLE accounts( | |
JE_ID serial PRIMARY KEY, | |
ACCOUNT_DR integer NOT NULL, | |
ACCOUNT_CR integer NOT NULL, | |
SUMM integer NOT NULL, | |
REVERSED integer NOT NULL, | |
USER_ID integer NOT NULL, | |
DATA integer NOT NULL, | |
DATE_DOC integer NOT NULL, | |
APPROVER_ID varchar(256) NOT NULL, |
NewerOlder