Skip to content

Instantly share code, notes, and snippets.

View jacobsvante's full-sized avatar

Jacob Magnusson jacobsvante

  • Hyperkliv AB
  • Hestra, Sweden
  • 00:44 (UTC +01:00)
View GitHub Profile

Keybase proof

I hereby claim:

  • I am jmagnusson on github.
  • I am jacobsvante (https://keybase.io/jacobsvante) on keybase.
  • I have a public key whose fingerprint is 872D C648 5739 1BD4 EDA4 AAA8 15BB 07D8 AB57 29C0

To claim this, I am signing this object:

@jacobsvante
jacobsvante / README.md
Last active August 29, 2015 14:27 — forked from inklesspen/README.md
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/

@jacobsvante
jacobsvante / README.md
Last active June 30, 2020 01:54 — forked from agnoster/README.md
My version of the Agnoster theme, with Virtualenv support

agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

For Mac users, I highly recommend iTerm 2 + Solarized Dark

@jacobsvante
jacobsvante / gist:122fb2272bd7feb83b31
Created April 23, 2015 09:20
Test case for flask-admin/flask-admin issue #846 (and usage of PR #808)
from flask import Flask
import sqlalchemy as sa
from sqlalchemy import orm
from sqlalchemy.ext.declarative import declarative_base
from flask.ext.admin import Admin
from flask.ext.admin.contrib import sqla
app = Flask(__name__)

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

<html>
<!--
This is an example of how to make browsers
offer to remember password and later fill in those passwords
for dynamic login forms.
To make the browser offer to remember passwords the form should be actually submitted.
Since we are handling login with AJAX we don't want the form to submit, so we are still submitting it
into a dummmy iframe with dummy URL.
It's good idea to actually create empty dummy.html file, otherwise you'll flood you error.log with 404s
@jacobsvante
jacobsvante / gist:08c337df3f3dca764da1
Created August 24, 2014 18:26
Vagrant downloading salt-minion
Using Bootstrap Options: -c /tmp
Bootstrapping Salt... (this may take a while)
stdin: is not a tty
%
T
o
t
$ sandmanctl postgresql+psycopg2://proj:proj@localhost/proj_v2
/Users/jacob/.venvs/proj-web-py2/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py:1802: SAWarning: Did not recognize type 'geography' of column 'point'
name, format_type, default, notnull, domains, enums, schema)
/Users/jacob/.venvs/proj-web-py2/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/base.py:1802: SAWarning: Did not recognize type 'geometry' of column 'location'
name, format_type, default, notnull, domains, enums, schema)
Traceback (most recent call last):
File "/Users/jacob/.venvs/proj-web-py2/bin/sandmanctl", line 9, in <module>
load_entry_point('sandman==0.7.6', 'console_scripts', 'sandmanctl')()
File "/Users/jacob/.venvs/proj-web-py2/lib/python2.7/site-packages/sandman/sandmanctl.py", line 63, in main
activate(name='sandmanctl')
brew remove pyqt
brew install pyqt #verify everything works fine
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
brew tap homebrew/science
brew install qgis --with-grass --with-postgis
[...migrations running...]
Running migrations for social_auth:
- Migrating forwards to 0002_auto__add_unique_nonce_timestamp_salt_server_url__add_unique_associati.
> social_auth:0001_initial
FATAL ERROR - The following SQL query failed: CREATE TABLE "social_auth_usersocialauth" ("id" serial NOT NULL PRIMARY KEY, "user_id" integer NOT NULL, "provider" varchar(32) NOT NULL, "uid" varchar(255) NOT NULL, "extra_data" text NOT NULL);
The error was: relation "social_auth_usersocialauth" already exists
Error in migration: social_auth:0001_initial
Traceback (most recent call last):
File "/Users/jacob/.virtualenvs/sentry_venv/bin/sentry", line 9, in <module>