Skip to content

Instantly share code, notes, and snippets.

@pazdera
pazdera / builder.py
Created August 2, 2011 20:35
Example of `builder' design pattern in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Example of `builder' design pattern
# Copyright (C) 2011 Radek Pazdera
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("start");
@inklesspen
inklesspen / README.md
Last active September 6, 2023 17:11
Fast and flexible unit tests with live Postgres databases and fixtures

(This gist is pretty old; I've written up my current approach to the Pyramid integration on this blog post, but that blog post doesn't go into the transactional management, so you may still find this useful.)

Fast and flexible unit tests with live Postgres databases and fixtures

I've created a Pyramid scaffold which integrates Alembic, a migration tool, with the standard SQLAlchemy scaffold. (It also configures the Mako template system, because I prefer Mako.)

I am also using PostgreSQL for my database. PostgreSQL supports nested transactions. This means I can setup the tables at the beginning of the test session, then start a transaction before each test happens and roll it back after the test; in turn, this means my tests operate in the same environment I expect to use in production, but they are also fast.

I based my approach on [sontek's blog post](http://sontek.net/blog/

@danielfrg
danielfrg / clean-html-solr-pipeline.py
Last active May 6, 2019 12:45
Luigi pipeline that: 1. Reads a tdf file using pandas with html on the 'content' column and created another tdf with just the text of the html (beautifulsoup) 2. Indexes the text into a Solr collection using mysolr
import re
import json
import luigi
import pandas as pd
from mysolr import Solr
from bs4 import BeautifulSoup
class InputText(luigi.ExternalTask):
@samuell
samuell / luigi_dynamic_dependency_graph_definition.py
Last active March 21, 2020 14:57
Dynamically specify luigi data flow
import luigi
class ATask(luigi.Task):
def output(self):
return luigi.LocalTarget("atask_output.txt")
def run(self):
with self.output().open("w") as outfile:
outfile.write("Test")
@amatellanes
amatellanes / pytest.sh
Last active April 20, 2024 08:31
Useful py.test commands.
py.test test_sample.py --collect-only # collects information test suite
py.test test_sample.py -v # outputs verbose messages
py.test -q test_sample.py # omit filename output
python -m pytest -q test_sample.py # calling pytest through python
py.test --markers # show available markers
anonymous
anonymous / config.json
Created December 16, 2014 13:16
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#fff",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#7bcc3a",
@ericremoreynolds
ericremoreynolds / client.html
Last active February 25, 2024 21:55
Flask-socket.io emit to specific clients
<html>
<body>
<h1>I feel lonely</h1>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8">
var socket = io.connect('http://' + document.domain + ':' + location.port);
socket.on('connect', function() {
socket.emit('connected');
@lebedov
lebedov / google_finance_intraday.py
Last active February 20, 2024 09:44
Retrieve intraday stock data from Google Finance.
#!/usr/bin/env python
"""
Retrieve intraday stock data from Google Finance.
"""
import csv
import datetime
import re
import pandas as pd
@kwmiebach
kwmiebach / pytest.md
Last active April 28, 2024 22:34 — forked from amatellanes/pytest.sh
pytest cheat sheet

Usage

(Create a symlink pytest for py.test)

pytest [options] [file_or_dir] [file_or_dir] ...

Help: