Skip to content

Instantly share code, notes, and snippets.

View duncangh's full-sized avatar
💭
👨‍💻

Graham Duncan duncangh

💭
👨‍💻
View GitHub Profile
@duncangh
duncangh / controversy.js
Created May 9, 2019 19:45
Twitter find controversial replies
var root_tweet;
var tweets = new Array();
var scrollInterval = null;
var lastScrollHeight = 0;
function autoScroll() {
var sh = document.documentElement.scrollHeight;
from ftplib import FTP
from datetime import datetime

start = datetime.now()
ftp = FTP('your-ftp-domain-or-ip')
ftp.login('your-username','your-password')

# Get All Files
files = ftp.nlst()
var get_numeric_table_value = function(id) {
let element = document.getElementById(id);
return Number(element.textContent)
};
let ask = get_numeric_table_value('ask0');
let bid = get_numeric_table_value('bid0');
let avg = (bid + ask) / 2 ;
@duncangh
duncangh / deque.md
Created July 8, 2019 00:42
Data Structures Python deque

Recent Emojis

if the implementation is recent emojis, then we could use a deque. The deque will be instantiated with a max length of 30 which is consistent with what Apple uses.

from collections import deque

recent_emojis = deque([], maxlen=30)

def update_recent_emojis(emoji_used, recent_emojis : deque):
    if emoji_used in recent_emojis:
        recent_emojis.remove(emoji_used)
@duncangh
duncangh / picblast.sh
Created September 2, 2019 15:21 — forked from bwhitman/picblast.sh
Make an audio collage out of your live photos
mkdir /tmp/picblast; cd ~/Pictures/Photos\ Library.photoslibrary; for i in `find . | grep jpegvideocompl`;do ffmpeg -i $i /tmp/picblast/${i:(-8)}.wav; done; cd /tmp/picblast; ffmpeg -safe 0 -f concat -i <( for f in *.wav; do echo "file '$(pwd)/$f'"; done ) ~/Desktop/picblast.wav; rm -rf /tmp/picblast
@duncangh
duncangh / type_as_string.py
Created September 18, 2019 22:03
Python 'type' object to string.
# https://stackoverflow.com/questions/5008828/convert-a-python-type-object-to-a-string
type_variety_list : list = [
10,
'x',
lambda x: x,
set(),
dict(),
[]
@duncangh
duncangh / .bash_profile
Created September 19, 2019 01:03 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@duncangh
duncangh / happy_git_on_osx.md
Created September 19, 2019 02:07 — forked from trey/happy_git_on_osx.md
Creating a Happy Git Environment on OS X

Creating a Happy Git Environment on OS X

Step 1: Install Git

brew install git bash-completion

Configure things:

git config --global user.name "Your Name"

git config --global user.email "[email protected]"

@duncangh
duncangh / foreign_object_exploration.py
Created September 20, 2019 02:36
Explore the attributes and methods on a foreign object in python
def reduce_namespace_to_public_only(namespace_directory : list) -> list:
"""
returns: list of public attribute and or method names
"""
_is_public_facing = lambda x: not x.startswith('_')
public_namespace_only : list = sorted(
filter(_is_public_facing, namespace_directory)
)
@duncangh
duncangh / cache_example.py
Created October 6, 2019 02:18 — forked from treuille/cache_example.py
This demonstrates the st.cache function
import streamlit as st
import pandas as pd
# Reuse this data across runs!
read_and_cache_csv = st.cache(pd.read_csv)
BUCKET = "https://streamlit-self-driving.s3-us-west-2.amazonaws.com/"
data = read_and_cache_csv(BUCKET + "labels.csv.gz", nrows=1000)
desired_label = st.selectbox('Filter to:', ['car', 'truck'])
st.write(data[data.label == desired_label])