Skip to content

Instantly share code, notes, and snippets.

# -*- encoding=utf-8 -*-
import requests
import csv
from datetime import datetime
import pandas as pd
import json
SYMBOLS_FILE = 'nasdaq-listed-symbols.csv'
@dhke
dhke / hotp.py
Last active August 16, 2024 17:57
A pure Python 3 implementation of RFC4226 HOTP
# -*- encoding=utf-8 -*-
__all__ = ['HOTP']
import hashlib
import hmac
import unittest
class HOTP(object):
@dhke
dhke / resolve.py
Created March 13, 2017 16:02
little script to test getaddrinfo resolver
#! /usr/bin/env python
from __future__ import print_function
import argparse
import socket
import six
def parse_args():
@dhke
dhke / imap_parse.py
Last active November 30, 2016 21:36
Functions to parse imaplib2 responses into more pythonesque data
# -*- encoding=utf-8 -*-
from __future__ import print_function
from peekable import peekable
SP = b' '
CTL = b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0f' \
b'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1f'
# -*- encoding=utf-8 -*-
from copy import copy
import imaplib
class CyrusIMAPMixin(object):
"""
Mixin for imaplib.IMAP4 and imaplib.IMAP4SSL
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class ClassBasedMap<K, V> {
private final Map<Class<? extends K>, V> _cache = new HashMap<Class<? extends K>, V>();
private final Map<Class<? extends K>, V> _map = new HashMap<Class<? extends K>, V>();
@dhke
dhke / find_no_pkg.py
Last active August 29, 2015 14:27
FreeBSD pkg: find all files that are not associated with a package (not registered in the package database)
#! /usr/bin/env python2
import os
import re
import shlex
import subprocess
import sys
from contextlib import closing
from sqlite3 import dbapi2 as sqlite
@dhke
dhke / geo.py
Created August 13, 2015 13:41
Create metric buffers around arbitrary geoms
# -*- encoding=utf-8 -*-
import math
UTM_NORTHERN_BASE = 32600
UTM_SOUTHERN_BASE = 32700
DEFAULT_MAP_SRID = 3857
@dhke
dhke / decorator.py
Created August 13, 2015 13:39
Django automatic decorator
def decorator_on_class(decorator):
"""
Apply the supplied view decorator to the specified
class.
"""
def decorate_class(cls):
dispatch = cls.dispatch
@wraps(dispatch)
@method_decorator(decorator)
class CollectionsGenericAbstractTypeResolver
extends AbstractTypeResolver {
public CollectionsGenericAbstractTypeResolver()
{
}
@Override
public JavaType resolveAbstractType(DeserializationConfig config, JavaType type)
{