Skip to content

Instantly share code, notes, and snippets.

View techniq's full-sized avatar

Sean Lynch techniq

View GitHub Profile
@techniq
techniq / README.md
Last active December 11, 2015 17:08
Path fixer for Google App Engine to load libraries from packages directory.

path_fixer.py should be placed at the root of your project, and imported at the top of any of your entry point scripts (main.py, manage.py, test.py, etc)

All your libraries should be copied from site-packages (ex. /Library/Python/2.7/site-packages or your virtualenv) and into a packages directory at the root of your project.

myapp
|-- packages
   |-- library1.py
   |-- library2.py
 |-- library3
@techniq
techniq / console_logging.py
Created February 1, 2013 15:47
Echo logging to console
import logging
root = logging.getLogger()
root.addHandler(logging.StreamHandler())
root.setLevel(logging.DEBUG)
@techniq
techniq / audit_mixin.py
Created March 16, 2013 01:05
Useful SQLAlchemy Mixins
from datetime import datetime
from sqlalchemy import Column, Integer, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr
from flask_security import current_user
class AuditMixin(object):
created_at = Column(DateTime, default=datetime.now)
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
@techniq
techniq / view.py
Created March 16, 2013 01:06
SQLAlchemy View support
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.expression import Executable, ClauseElement
from sqlalchemy.schema import DDLElement, DropTable
from sqlalchemy.sql import table
from sqlalchemy.orm import Query
from . import db
class CreateView(DDLElement):
@techniq
techniq / anonymous_object_options.cs
Created March 20, 2013 18:48
Example using an anonymous object to pass in key/value options
public string Foo(object overrides = null)
{
if (overrides != null)
{
foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(overrides))
{
var name = property.Name;
var value = property.GetValue(overrides);
...
}
@techniq
techniq / smtp_debug.sh
Created May 6, 2013 14:01
Create an SMTP server which prints mail to stdout
python -m smtpd -n -c DebuggingServer localhost:1025
@techniq
techniq / bootstrap-validation.js
Created June 11, 2013 14:46
jQuery Validation with Twitter Bootstrap
$("#someForm").validate({
errorClass:'error',
validClass:'success',
errorElement:'div',
highlight: function (element, errorClass, validClass) {
$(element).parents("div[class='control-group']")
.addClass(errorClass)
.removeClass(validClass);
},
unhighlight: function (element, errorClass, validClass) {
@techniq
techniq / remoting.ps1
Last active June 28, 2016 23:37
PowerShell remoting
Enable-PSRemoting
$creds = Get-Credential
Enter-PSSession -ComputerName [NAME] -Credentials $creds
Invoke-Command -ComputerName [NAME] -Credentials $creds { get-UICulture }
http://www.thecodeking.co.uk/2011/02/winrm-with-mixed-domain-environments.html
http://technet.microsoft.com/en-us/library/hh849707.aspx
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
SetupIoc();
}
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
[XmlRoot("dictionary")]
public class XmlSerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IXmlSerializable
{
public XmlSchema GetSchema()