Skip to content

Instantly share code, notes, and snippets.

View standbyme's full-sized avatar

Hongyu Cai standbyme

View GitHub Profile
import os
for i in range(1,10):
dir_name = str(i)
os.mkdir(dir_name)
os.chdir(dir_name)
open("question", 'a').close()
open("input", 'a').close()
open("output", 'a').close()
open("whatsup", 'a').close()
os.mkdir("code")
from string import Template
with open("template.md", 'r') as file:
templateFile = file.read()
with open("main.c", 'r') as file:
code = file.read()
template = Template(templateFile)
print(template.safe_substitute(code=code))
import sys
from PyPDF2 import PdfFileMerger
PDFMerger = PdfFileMerger()
filePathList = sys.argv[1:]
for filePath in filePathList:
PDFMerger.append(filePath)
with open("Report.pdf", "wb") as output:
PDFMerger.write(output)
@standbyme
standbyme / test.py
Created July 20, 2017 06:07
Python!!!!3!!!!!
import http.client
import urllib.request
import urllib.parse
import urllib.error
import base64
import json
sub_key = "ba0747d02f2a42ffbc0f0dd2cb1fba06"
KBID = "b49a4b5a-8a4e-4feb-9caa-604ea9a6ba82"
hbase(main):003:0> put 'alarm_mmdd','imeiTSE','r:stat','stat'
0 row(s) in 0.1400 seconds
hbase(main):004:0> put 'alarm_mmdd','imeiTSE','r:type','type'
0 row(s) in 0.0060 seconds
hbase(main):005:0> put 'alarm_mmdd','imeiTSE','r:viewed','viewed'
0 row(s) in 0.0020 seconds
hbase(main):006:0> put 'alarm_mmdd','imeiTSE','r:record','record'
@standbyme
standbyme / clean.py
Created November 7, 2018 11:54
FIle clean
import re
def solve_specific(line: str):
matched = re.match(r'\[(.*)\]\[(.*?)\]', line)
name = matched.group(1)
label = matched.group(2)
return '\n'.join(list(map(lambda x: '{} B-{}'.format(x[1], label) if x[0] == 0 else '{} I-{}'.format(x[1], label), enumerate(name))))
@standbyme
standbyme / pytorch_csv.py
Created July 20, 2019 02:24
PyTorch CSV
from torch.utils.data import Dataset, DataLoader
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
class CSVDataset(Dataset):
def __init__(self, x, y):
self.data = torch.tensor(x, dtype=torch.float, device=device)
self.target = torch.tensor(y, dtype=torch.long, device=device)
def tf__helper(self, inputs):
do_return = False
retval_ = ag__.UndefinedReturnValue()
inputs = ag__.converted_call('transpose', tf, ag__.ConversionOptions(recursive=True, force_conversion=False, optional_features=(), internal_convert_user_code=True), (inputs, [1, 0, 2]), None)
batch_size = ag__.converted_call('shape', tf, ag__.ConversionOptions(recursive=True, force_conversion=False, optional_features=(), internal_convert_user_code=True), (inputs,), None)[1]
hidden = ag__.converted_call('zeros', tf, ag__.ConversionOptions(recursive=True, force_conversion=False, optional_features=(), internal_convert_user_code=True), ([batch_size, hidden_size],), {'name': 'hidden'})
output = ag__.converted_call('zeros', tf, ag__.ConversionOptions(recursive=True, force_conversion=False, optional_features=(), internal_convert_user_code=True), ([batch_size, output_size],), {'name': 'output'})
def loop_body(loop_vars, hidden_1, output_1):
x_t = loop_vars
@standbyme
standbyme / Model_with_AutoGraph.py
Created July 30, 2019 07:24
Model Class with AutoGraph
class MyModel(tf.keras.Model):
def __init__(self, keep_probability=0.2):
super(MyModel, self).__init__()
self.dense1 = tf.keras.layers.Dense(4)
self.dense2 = tf.keras.layers.Dense(5)
self.keep_probability = keep_probability
@tf.function
def call(self, inputs, training=True):
y = self.dense2(self.dense1(inputs))