Skip to content

Instantly share code, notes, and snippets.

View hokie-sam's full-sized avatar

sam hokie-sam

View GitHub Profile
@hokie-sam
hokie-sam / light-dark-theme.html
Created November 1, 2020 06:56
Simple javascript and css to allow user to chose between a light/dark theme on webpage, and save their choice with HTML5 localStorage, instead of using cookies.
<!DOCTYPE html>
<html>
<style>
/* By making the light/dark buttons 30px squares,
they will not need text labels,
but they'll still be large enough to easily click. */
.light-dark-button {
border-style: solid;
border-color: blue;
@hokie-sam
hokie-sam / tariff_viz.R
Last active March 11, 2018 17:45
Visualizing how tariff rates have changed around the world over the past few decades
library(ggplot2)
library(reshape2)
library(dplyr)
# First, we need to get the data from the World Bank website.
# I am using the "weight mean of tariffs applied on manufactored
# products". The .csv file is below, but here is the url...
# https://data.worldbank.org/indicator/TM.TAX.MANF.WM.AR.ZS
wbt <- read.csv(file = 'C://your//file//path//wb_tariff.csv', header = T, stringsAsFactors = F)
import requests
import uuid
import time
import json
from random import *
import hmac
import hashlib
import urllib3
import urllib.parse
from urllib.parse import urlparse
@hokie-sam
hokie-sam / orderviz.py
Last active March 7, 2018 21:01
Simple text-based limit order vizualizer
import math
def vizOr():
'''
The buy orders are shown as a plus (+) sign,
the sell orders are shown as a minus (-) sign.
Obviously, you would want to provide a live
market price and list of your orders to the
function.
'''
import time
from datetime import datetime
# It took me a while to figure out to convert
# a string timestamp to the number of seconds
# since the Unix epoch. Turns out it is pretty
# simple.
# Note: it only works for years >= 1900
my_td_string = 'Date: 2018-01-19 Time: 06:35:30.123'
@hokie-sam
hokie-sam / twitterbot_api.py
Last active March 6, 2018 16:59
Simple Pyton code for creating a Twitter bot using their API.
import requests
import json
from requests.auth import AuthBase
from requests_oauthlib import OAuth1
from requests_oauthlib import OAuth1Session
# This is very simple code to start a simple Twitter bot.
# At the moment, this is only for posting tweets to your
# page. Twitter offers additional actions (Liking, Replying,
# Retweeting, etc) on their (confusing) developer website.