Skip to content

Instantly share code, notes, and snippets.

View withtwoemms's full-sized avatar

Emmanuel I. Obi withtwoemms

View GitHub Profile
@withtwoemms
withtwoemms / run_secretary.py
Last active February 25, 2022 22:53
short script demonstrating the use of the actionpack lib
from datetime import datetime
from sys import exit
from actionpack.actions import ReadInput
from actionpack.actions import Pipeline
from actionpack.actions import Write
filename = 'fake.chat'
listen = ReadInput('What should I record? ')
@withtwoemms
withtwoemms / no_traceback.py
Last active February 11, 2022 20:26
a simple context manager for hiding tracebacks
import sys
from contextlib import contextmanager
from functools import partial
default_prefix = '\n -> '
def fully_qualified_exception(exc_type, exc_value, tb, prefix=default_prefix, show_full_name=False, buffer=sys.stdout):
"""An Exception hook that returns the fully-qualified name of the given exception.
@withtwoemms
withtwoemms / Makefile
Created August 21, 2020 09:16
A basic python Makefile. Run `make commands` to see available commands.
SYSTEM_PYTHON = $(shell which python3.8)
PROJECT_NAME = $(shell basename $(CURDIR))
VENV = $(PROJECT_NAME)-venv
VENV_PYTHON = $(VENV)/bin/python
TESTDIR = tests
.PHONY: all
all:
@make venv
@withtwoemms
withtwoemms / functional_read_csv.py
Created August 21, 2020 09:14
Doing the common task of reading .csv but with the python toolz library
from functools import partial
from operator import methodcaller
from pathlib import Path
from pprint import pprint
from sys import argv
from toolz import compose
from toolz.curried import map
if __name__ == '__main__':
from numpy import arange as range_about_zero, array, random
from math import exp
from scipy import special
def discrete_gaussian_kernel(fidelity, scale=1):
return exp(-scale) * special.iv(generate_range_about_zero(fidelity), scale)
def generate_range_about_zero(magnitude):
if magnitude % 2 == 0:
class LinkedList
attr_reader :schema, :head
def initialize(items)
@head = items.first.__id__
@schema = {}
items.each_with_index do |item, i|
unless items[i+1] == nil
@schema.update({item.__id__ => items[i+1].__id__})
else
@withtwoemms
withtwoemms / element_list.js
Last active January 26, 2016 08:51
Generate a List of React Components
import React from 'react';
import ReactDOM from 'react-dom';
class ListElement extends React.Component{
render() {
return <div>
<a href={this.props.href}>
{this.props.name}
</a>
import validators # may need to `pip install validators` first...
def mocked_response(url, **response_dict):
def validate_url(url):
try:
return validators.url(url)
except ValidationFailure as e:
return False
class Response(type):
@withtwoemms
withtwoemms / twitter_rest_api_rate_limits.json
Created January 4, 2016 00:50
Twitter REST API rate limits
{"application/rate_limit_status": {"app_limit": "180",
"resource_type": "application",
"user_limit": "180"},
"favorites/list": {"app_limit": "15",
"resource_type": "favorites",
"user_limit": "15"},
"followers/ids": {"app_limit": "15",
"resource_type": "followers",
"user_limit": "15"},
"followers/list": {"app_limit": "15",
@withtwoemms
withtwoemms / twitter_rest_api.json
Last active January 4, 2016 01:27
Twitter REST API surface area -- endpoint:params
{"GET": {"account/settings": {},
"account/verify_credentials": {"include_email": "None",
"include_entities": "None",
"skip_status": "None"},
"application/rate_limit_status": {"resources": "None"},
"blocks/ids": {"cursor": "None", "stringify_ids": "None"},
"blocks/list": {"cursor": "None",
"include_entities": "None",
"skip_status": "None"},
"direct_messages": {"count": "None",