Skip to content

Instantly share code, notes, and snippets.

@mdellavo
mdellavo / xls-dict-reader.py
Created October 21, 2010 18:59
XLS to Dict Reader using xlrd
try:
import xlrd
def XLSDictReader(f, sheet_index=0):
data = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
book = xlrd.open_workbook(file_contents=data)
sheet = book.sheet_by_index(sheet_index)
def item(i, j):
return (sheet.cell_value(0,j), sheet.cell_value(i,j))
import abc
from enum import unique
import json
import datetime
import dataclasses
from typing import Optional
from sqlalchemy import Column, Integer, String, DateTime, JSON, Index, select, create_engine, and_
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import registry, sessionmaker
import re
class AnyDict(dict):
"""
>>> AnyDict(foo=1) == {"foo": 1, "bar": 2}
True
>>> AnyDict(foo=2) == {"foo": 1, "bar": 2}
False
"""
@mdellavo
mdellavo / backbone-video.js
Created March 14, 2012 14:45
A Backbone app to render a youtube embed and list of thumbnails of videos responding to callbacks
var Video = Backbone.Model.extend({});
var VideoList = Backbone.Collection.extend({
model: Video,
url: '/videos'
});
var VideoPlayerView = Backbone.View.extend({
id: 'video-player',
className: 'video-player',
@mdellavo
mdellavo / sqlalchemy-mixins.py
Created March 8, 2012 14:13
A few SQLAlchemy mixins for common behaviors
class UTCDateTime(TypeDecorator):
impl = DateTime
def convert_bind_param(self, value, engine):
return value
def convert_result_value(self, value, engine):
return UTC.localize(value)
class StampedMixin(object):
SAFE = True
MASK = "*"
def mask(val):
return MASK * len(val)
def value(val):
return mask(val) if SAFE else val
@mdellavo
mdellavo / github-action-step-post-slack.yaml
Last active September 5, 2019 17:20
A simple host based step for github actions to post to slack, no docker needed
- name: Build failure
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL: ...
run: |
curl -X POST \
-H "Authorization: Bearer $SLACK_BOT_TOKEN" \
-d channel=$SLACK_CHANNEL \
-d text='[${{ github.repository }}] ${{ github.event.ref }} *FAILED*' \
$ python maze.py
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## # # # # ####### # ### # ### # # # # # # ### # # # ### ### ### ##### ### # ### # ##### ### ########### # # # # # # ###
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## # # ### # # # ##### # # # # # ##### ### # ### ##### # # ### ##### ##### ####### # # # # # ### ### # # # # # ### # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
## ##### # ### # ### # ### ##### # # ##### # # # ##### ### # ####### # # ##### # # ############# # ##### ##### #########
# # # # # # # # # # # #
@mdellavo
mdellavo / irc-connector.js
Created October 17, 2010 16:25
A RESTful IRC <-> HTTP Gateway
var postgres = require('/home/marc/Source/node_postgres/postgres'),
irc = require('irc'),
http = require('http'),
url = require('url'),
querystring = require('querystring'),
util = require('util');
function DB(conn) {
this.db = postgres.createConnection(conn);
try:
import openpyxl
def XLSXDictReader(f):
book = openpyxl.reader.excel.load_workbook(f)
sheet = book.get_active_sheet()
rows = sheet.get_highest_row()
cols = sheet.get_highest_column()