Skip to content

Instantly share code, notes, and snippets.

@pohzipohzi
pohzipohzi / forexfactory_econcal.py
Created November 3, 2017 15:35
A scraper for forex factory economic calendar data
from bs4 import BeautifulSoup
import requests
import datetime
import logging
import csv
def setLogger():
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
filename='logs_file',
@pohzipohzi
pohzipohzi / vba_tableloop.bas
Created November 6, 2017 07:59
Simple template for looping through table objects in excel
Sub tableloop()
Dim tbl As ListObject
Set tbl = ThisWorkbook.Worksheets("wsname").ListObjects("tblname")
Dim i As Integer
For i = 1 To tbl.ListRows.Count
Dim col1val, col2val As String
col1val = Trim(tbl.ListColumns("col1name").DataBodyRange(i, 1).Value)
col2val = Trim(tbl.ListColumns("col2name").DataBodyRange(i, 1).Value)
'do stuff with column values here
Next i
@pohzipohzi
pohzipohzi / pandas_cheat.py
Created November 16, 2017 10:12
Cheat sheet for the python pandas library
import numpy as np
import pandas as pd
#### creating dataframes, adding and dropping columns
df = pd.DataFrame(np.arange(1,10).reshape(3,3),['A','B','C'],['w','x','y'])
df.columns = ['W','X','Y'] # change column names
df['Z']=df['X']+df['Y'] # new column with values X+Y
df['XX']=df.apply(lambda row: row['X']*2, axis=1) # new column with values twice of column X
df['YY']=1 # new column of ones
@pohzipohzi
pohzipohzi / useful_sql.txt
Created December 22, 2017 07:23
Some lesser known sql functions
Replace a table using data and structure from another one:
DROP TABLE IF EXISTS a
CREATE TABLE a LIKE b
INSERT INTO a SELECT * FROM b
Insert into table with possibility of duplicate:
INSERT INTO a(`f1`,`f2`) VALUES ('x','y') ON DUPLICATE KEY UPDATE `f2`='y'
or
@pohzipohzi
pohzipohzi / ipython-scrapy.ipynb
Last active July 26, 2018 05:47 — forked from kmike/ipython-scrapy.ipynb
kmike's ipython-scrapy proof of concept, updated for scrapy 1.5
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pohzipohzi
pohzipohzi / genreport.bas
Created January 11, 2018 02:22
Simple report generation by copy-pasting ranges and tables
Sub genreport()
Dim wb As Workbook
Set wb = Application.Workbooks.Add
Dim tbl As ListObject
Set tbl = ThisWorkbook.Worksheets("mainsheet").ListObjects("maintable")
Dim i, lastrow As Integer
lastrow = 1
For i = 1 To tbl.ListRows.Count
Dim val As String
val = Trim(tbl.ListColumns("Source").DataBodyRange(i, 1).Value)
@pohzipohzi
pohzipohzi / backup.sh
Created January 15, 2018 07:46
Simple shell script to backup .xlsm files in folder
#!/bin/bash
for filename in *.xlsm; do
cp "$filename" "backup/$(basename "$filename" .xlsm) $(date +'%Y%m%d%H%M%S').xlsm"
done
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pohzipohzi
pohzipohzi / redis-example.go
Last active March 22, 2022 15:59
Examples from redigo
// this is a file that puts together all redigo examples for convenience
// (see https://godoc.org/github.com/gomodule/redigo/redis#pkg-examples)
//
// start by ensuring that redis is running on port 6379 (`redis-server`)
// uncomment the main method as needed, and run the script (`go run main.go`)
package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
@pohzipohzi
pohzipohzi / tree_traversal.py
Last active November 27, 2018 18:11
Recursive and iterative implementations of basic tree traversals in python 3
class TreeNode:
def __init__(self, val):
self.val = val
self.left = None
self.right = None
def buildTree(arr):
nodes = [TreeNode(val) for val in arr]
for i in range(len(nodes)):
left, right = (i+1)*2-1, (i+1)*2