Skip to content

Instantly share code, notes, and snippets.

@haradreborn
haradreborn / index.html
Created August 25, 2016 21:31
Material Design Spinner
<svg class="spinner" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
<circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
</svg>
@haradreborn
haradreborn / args.py
Created December 24, 2014 07:25
Print args per option
#!/usr/bin/python
import sys, getopt
def main(argv):
login = ''
password = ''
try:
opts, args = getopt.getopt(argv, "l:p", ["log=", "pas="])
except getopt.GetoptError:
@haradreborn
haradreborn / delete_dir.py
Created December 5, 2014 08:52
clear directory
def file_clear(self, dir):
retry = True
while retry:
try:
retry = False
if (os.name == "nt"):
try:
shutil.rmtree(dir)
except exceptions.WindowsError, e:
if e.winerror == 5: # No write permission
@haradreborn
haradreborn / export_csv
Created December 4, 2014 14:09
postgresql - export to csv, import from csv
COPY triplet_original TO '/tmp/triplet_original.csv' DELIMITER E'\t' CSV HEADER;
COPY "STA_apps" FROM '/var/www/tmp/sta/sta_cod.txt' WITH (FORMAT csv, DELIMITER E'\t', NULL 'NULL', HEADER);
@haradreborn
haradreborn / add_column
Last active August 29, 2015 14:10
postgresql - add column, add date with now() default
ALTER TABLE "STA_apps" ADD COLUMN "date" timestamp without time zone NOT NULL DEFAULT now();
@haradreborn
haradreborn / file_list.py
Created December 2, 2014 12:45
Get list of files
from os import listdir
from os.path import isfile, join
def get_file_list(self, tmp_path):
files = [ f for f in listdir(tmp_path) if isfile(join(tmp_path,f)) ]
return files
@haradreborn
haradreborn / fetch_rows.py
Created November 14, 2014 07:30
fetch rows from postgresql
try:
conn_string = "host='106.109.7.91' dbname='smarttvanalyzer' user='samson' password='samson'"
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
cursor.execute("""SELECT * FROM "IMS" WHERE CAST(date AS DATE) = '""" + ts + "'")
rows = cursor.fetchall()
conn.commit()
for row in rows:
print(row)
@haradreborn
haradreborn / select date
Created November 14, 2014 06:57
postgres - select date
SELECT * FROM "IMS" WHERE CAST(date AS DATE) = '2014-11-14'
@haradreborn
haradreborn / change_encoding.py
Last active August 29, 2015 14:08
Change file encoding
import codecs
def change_code(self, file_from, file_to):
BLOCKSIZE = 1048576 # or some other, desired size in bytes
with codecs.open(file_from, "r", "utf-16") as sourceFile:
with codecs.open(file_to, "w", "utf-8") as targetFile:
while True:
contents = sourceFile.read(BLOCKSIZE)
if not contents:
break
@haradreborn
haradreborn / replace_in_file.py
Last active August 29, 2015 14:08
Replace characters in file
def replace(self, file_from, file_to):
data = open(file_from, 'rb')
res = open(file_to, 'wb')
for line in data:
res.write(line.replace('"', '\''))