Skip to content

Instantly share code, notes, and snippets.

View eculver's full-sized avatar
🧠
Braining

Evan Culver eculver

🧠
Braining
View GitHub Profile
@eculver
eculver / htpasswd.py
Created December 1, 2011 22:04
htpasswd script in python (no need to install apache utils)
#!/usr/local/bin/python
"""Replacement for htpasswd"""
# Original author: Eli Carter
import os
import sys
import random
from optparse import OptionParser
# We need a crypt module, but Windows doesn't have one by default. Try to find
@eculver
eculver / calculate bounding box coordinates
Created April 4, 2011 22:20
calculate bounding box coordinates
var BOTTOM_PADDING = 25;
// calculate the bounding box for the image
var containerNode = Y.one('#containerId');
// viewport height
var windowHeight = Y.one('body').get('winHeight');
// grab the box's width based on it's container
var boxWidth = parseInt(mediaPlayerNode.get('offsetWidth')) - 15; // 15px??
@eculver
eculver / replace_apt_sources.sh
Created December 26, 2013 00:02
Replace default Ubuntu apt repository URLs w/ DigitalOcean's
sudo sed -i "s/archive\.ubuntu/mirrors.digitalocean/g" /etc/apt/sources.list
@eculver
eculver / mples of how to implement inheritance with Django models
Created April 18, 2010 05:36
Examples of how to implement inheritance with Django models
"""Examples of how to implement inheritance with Django models.
Idea here is DRY (don't repeat yourself). If models are similar, let them
share functionality to the extent that its ancestrty makes sense.
It's important to note is that because of the "abstract = True", Django knows
not to create tables for those models, and instead only creates tables for
those models that implement those abstract base classes.
It can also be noted that instead of having one gigantic, monolithic models.py
@eculver
eculver / owning-account-assume-role.tf
Last active February 4, 2021 21:32
Chamber IAM Example
# this defines a role "role-name" in the account where this TF will be applied
resource "aws_iam_role" "role_name" {
name = "role-name"
description = "Allows role-name to do things in account"
assume_role_policy = "${data.aws_iam_policy_document.my_role.json}"
}
# this says that any one in a separate account with ID 123456789012 can assume the "role-name" role
data "aws_iam_policy_document" "role_name" {
statement {
@eculver
eculver / Python SMTP server one-liner
Created October 27, 2009 16:54
Python SMTP server one-liner
python -m smtpd -n -c DebuggingServer localhost:1025
@eculver
eculver / filter microsoft word special characters
Created April 18, 2010 04:30
convert microsoft word special characters to html entities
import re
def convert_1252_codes(text):
"""Convert windows-1252 characters to appropriate html entities.
@param str String to filter
@type string/unicode
@return unicode version of filtered string
Adapted from: http://effbot.org/zone/unicode-gremlins.htm
@eculver
eculver / batch.go
Created May 31, 2019 22:43
Divide slice into batches
// run at: https://play.golang.org/p/bhgYlgGbdHz
package main
import (
"fmt"
)
func main() {
total := 22
batch := 3
@eculver
eculver / .gitignore
Created October 21, 2011 21:35
.gitignore boilerplate
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc
@eculver
eculver / Makefile
Created November 21, 2018 02:02
Makefile capture
foo := a.o b.o c.o
bar := $(foo:%.o=%)
.PHONY: test
test:
echo $(bar)