Skip to content

Instantly share code, notes, and snippets.

View bhgomes's full-sized avatar
☀️
solar-powered

Brandon H. Gomes bhgomes

☀️
solar-powered
View GitHub Profile

Keybase proof

I hereby claim:

  • I am bhgomes on github.
  • I am bhgomes (https://keybase.io/bhgomes) on keybase.
  • I have a public key whose fingerprint is 48E9 34D5 A710 B6EB 94DB B6D0 C642 70EA B633 02DC

To claim this, I am signing this object:

@bhgomes
bhgomes / classproperty.py
Created March 26, 2019 22:52
classproperty
class classproperty(property):
"""Class Property."""
def __get__(self, obj, objtype=None):
"""Wrap Getter Function."""
return super().__get__(objtype)
def __set__(self, obj, value):
"""Wrap Setter Function."""
return super().__set__(type(obj), value)
@bhgomes
bhgomes / try_import.py
Created April 12, 2019 17:24
Try Import
from importlib import import_module
def try_import(
name, package=None, *exceptions, log_error=passf, log_success=passf, default=None
):
"""
Attempt Package Import With Automatic Exception Handling.
:param name:
:param package:
@bhgomes
bhgomes / line_reader.py
Last active June 27, 2020 06:09
Line Reader
class LineReader:
"""
Read a static file with smart line access.
WARNING: This implementation assumes that the file does not change between
calls of the `clear` function and never checks for valid file handlers.
"""
def __init__(self, file_handle=None, cache=None, offsets=None):
"""Initialize the LineReader."""
@bhgomes
bhgomes / keybase.md
Created October 29, 2019 16:54
Keybase Verification

Keybase proof

I hereby claim:

  • I am bhgomes on github.
  • I am bhgomes (https://keybase.io/bhgomes) on keybase.
  • I have a public key whose fingerprint is 7FBB 5AE3 B289 9EFC D644 72C2 3A75 F95C 4B85 7834

To claim this, I am signing this object:

@bhgomes
bhgomes / box_object.py
Last active October 11, 2020 04:03
Box Object
from wrapt import ObjectProxy
from box import Box
class BoxObject(ObjectProxy):
"""
Wrapper for any Python object with a Box as __dict__.
Simple Usage:
import requests
@bhgomes
bhgomes / .travis.yml
Created March 11, 2019 13:56
Conda Travis CI
sudo: false
language: python
dist: xenial
matrix:
include:
- python: 3.3
- python: 3.4
- python: 3.5
- python: 3.6
@bhgomes
bhgomes / bounded.py
Created January 18, 2019 05:07
Bounded Object Wrapper
from wrapt import ObjectProxy
class Bounded(ObjectProxy):
"""
Bounded Object Proxy.
"""
def __init__(self, wrapped, *, minimum=None, maximum=None):
"""Initialized Wrapped Bounded Object."""
@bhgomes
bhgomes / setup.py
Created January 16, 2019 17:06
Sample setup.py that reads from setup.json
# -*- coding: utf-8 -*-
#
# setup.py
#
SETUP_JSON = 'setup.json'
import io
import json
import os
@bhgomes
bhgomes / MakeDatabase.java
Last active October 11, 2020 04:04
JAQL Snippet Example 1: Creating a Database
import bhgomes.jaql.*;
public class MakeDatabase {
public static void main(String[] args) {
// Method 1
Database db1 = JAQL.open("db1", JAQL.SQLITE_DRIVER, "jdbc:sqlite:db1.db");
db1.info("Built a Database with JAQL convenience class");
// Method 2
Database db2 = new Database("db2").open(JAQL.SQLITE_DRIVER, "jdbc:sqlite:db1.db");