Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
carymrobbins / ghci.hs
Last active December 19, 2015 02:19
Wrapper for the ghci interpreter to automatically set extensions based on your cabal file.
#!/usr/local/bin/runhaskell
{-
DECPRECATED - Currently cabal repl provides a much better solution to this problem.
Use this script as a "replacement" for the ghci interpreter to
automatically include extensions from your cabal file.
Be sure to set the cabalFile and (optionally) ghciInit values in this script.
You may also need to update the bang line to the path of runhaskell.
@carymrobbins
carymrobbins / wfauto.rb
Last active November 24, 2023 06:12
Wells Fargo Automation
#!/usr/bin/env ruby
require 'io/console'
require 'mechanize'
agent = Mechanize.new
# http://curl.haxx.se/ca/cacert.pem
agent.ca_file = 'cacert.pem'
puts 'Connecting to Wells Fargo...'
page = agent.get 'https://wellsfargo.com'
@carymrobbins
carymrobbins / iformat.py
Last active December 21, 2015 21:49
String interpolation in Python.
import inspect
def iformat(string):
frame = inspect.currentframe()
result = string.format(**dict(frame.f_back.f_globals, **frame.f_back.f_locals))
del frame
return result
class Object(object): pass
@carymrobbins
carymrobbins / git-pull-each.bash
Last active December 22, 2015 05:39
Adds the git pull-each feature to easily pull multiple branches.
#!/bin/bash
# Adds the git pull-each feature to easily pull multiple branches.
# Place this in a directory on your path (e.g. ~/bin).
set -e
ORIG_BRANCH=$(git branch | grep '*' | cut -c3-)
if [ -z "$1" ]; then
@carymrobbins
carymrobbins / psql_group_by_pk_bug.sql
Created September 30, 2013 15:58
PostgreSQL - Group By Primary Key Bug
-- Test Data
drop table if exists x, y, z;
create temporary table x(id serial primary key, a int);
insert into x(a) values (1), (2);
create temporary table y(id serial primary key, x_id int, b int);
insert into y(x_id, b) values (1, 1), (2, 2), (3, 3);
create temporary table z(id serial primary key, x_id int, c int);
insert into z(x_id, c) values (1, 3), (1, 4), (2, 5);
-- Example - unable to group by primary key from subquery
with cte as (
@carymrobbins
carymrobbins / lazy_method.py
Created October 28, 2013 18:52
Lazy method decorator that allows you to cache the results of function calls with unhashable arguments.
class lazy_method(object):
""" Allows you to cache unhashable arguments. """
@classmethod
def truncate(cls, obj):
""" Removes method cache from obj. """
if hasattr(obj, '_lazy_items'):
del obj._lazy_items
def __init__(self, f):
def wrapped(self, *args, **kwargs):
@carymrobbins
carymrobbins / iindex.py
Created October 29, 2013 19:46
Index function for iterables. Particularly handy when dealing with infinite iterables.
from itertools import islice
def iindex(iterable, index):
""" Indexing for all iterables. Translates to iterable[index]. """
return next(islice(iterable, index, index + 1))
def example():
def fibs():
@carymrobbins
carymrobbins / custom_manager.py
Last active December 16, 2022 14:11
Simple custom Model Manager for Django. Allows you to easy override QuerySet and EmptyQuerySet
from django.db import models
from django.db.models.query import EmptyQuerySet, QuerySet
class CustomManager(models.Manager):
"""
Easily override QuerySet by setting the QuerySet and EmptyQuerySet
inside of the class using inheritance.
"""
EmptyQuerySet = EmptyQuerySet
#!/bin/bash
HOST=$1
if [ -z "$HOST" ]; then
echo "Enter host IP:"
read HOST
fi
sudo service denyhosts stop
@carymrobbins
carymrobbins / subclass_tuple.py
Created November 6, 2013 16:24
Subclassing tuple
class Choice(tuple):
def __new__(cls, name, description, permissions):
return super(Choice, cls).__new__(cls, tuple((name, name)))
def __init__(self, name, description, permissions):
super(Choice, self).__init__(name, description, permissions)
self.description = description
self.permissions = permissions
self.name = name