Skip to content

Instantly share code, notes, and snippets.

@lyndsysimon
lyndsysimon / mantras.md
Last active Aug 29, 2015
Lyndsy's Development Mantras
View mantras.md
  • There once was a developer who had a problem. They decided to solve this problem using a regex. That developer now has two problems.

  • All problems in computer science can be solved through additional layers of abstraction.

View temp.json
{
"tasks": [
{ "id": 1, "text": "my text 1" },
{ "id": 2, "text": "my text 2" },
{ "id": 3, "text": "my text 3" },
{ "id": 4, "text": "my text 4" }
]
}
@lyndsysimon
lyndsysimon / account_merge.py
Created Apr 22, 2015
OSF fixture generator
View account_merge.py
from tests import factories
from website import models
from website.util import web_url_for
from main import app
def print_merge_url(user, token, prefix):
with app.test_request_context():
print(prefix + ": " +
web_url_for(
'confirm_email_get',
View gist:5861852

Virtualenv's bin/activate is Doing It Wrong

I'm a Python programmer and frequently work with the excellent [virtualenv][] tool by Ian Bicking.

Virtualenv is a great tool on the whole but there is one glaring problem: the activate script that virtualenv provides as a convenience to enable its functionality requires you to source it with your shell to invoke it. The activate script sets some environment variables in your current environment and defines for you a deactivate shell function which will (attempt to) help you to undo those changes later.

This pattern is abhorrently wrong and un-unix-y. activate should instead do what ssh-agent does, and launch a sub-shell or sub-command with a modified environment.

Problems

@lyndsysimon
lyndsysimon / templating_language_concept
Last active Dec 20, 2015
A quick concept of a pythonic templating language based on Zen Coding, with inspiration from HAML and SASS.
View templating_language_concept
#### Template (proposed, unnamed language)
doctype(5)
html>head
style('my_stylesheet.css')
script('my_script.js')
title= {{ title }}
body>div.container
navbar(main_menu_links)
View gist:96977376ff5a743b737a3a30b607e6c8
class composable:
def __init__(self, func):
self.func = func
def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)
def __or__(self, other):
return lambda *args, **kwargs: self(other(*args, **kwargs))
View gist:516346899bb516d2aa350953e4579136
class MyAPINotAvailable < StandardError
attr_accessor :message
def initialize(message)
@message = "Failed to connect to MyAPI: #{message}"
end
end
raise MyAPINotAvailable.new "Could not update Foo"
@lyndsysimon
lyndsysimon / example.md
Created Oct 20, 2016
MySQL Column Normalization
View example.md

table source

id first_value second_value
0 0 0
1 0 1
2 1 0
3 1 1

desired output