Skip to content

Instantly share code, notes, and snippets.

View AndrewJHart's full-sized avatar
:atom:
Building react apps & micro-services

Andrew Hart AndrewJHart

:atom:
Building react apps & micro-services
View GitHub Profile
@AndrewJHart
AndrewJHart / webpack.config.js
Created May 8, 2017 16:51 — forked from JaySpears/webpack.config.js
Webpack 2.0 Configuration with React Example
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3000/',
'webpack/hot/only-dev-server',
path.resolve(__dirname, 'app/index')
],
@AndrewJHart
AndrewJHart / emitter.service.ts
Created February 11, 2017 09:56 — forked from sasxa/emitter.service.ts
Angular2 Communicating between sibling components
import {Injectable, EventEmitter} from 'angular2/core';
@Injectable()
export class EmitterService {
private static _emitters: { [ID: string]: EventEmitter<any> } = {};
static get(ID: string): EventEmitter<any> {
if (!this._emitters[ID])
this._emitters[ID] = new EventEmitter();
return this._emitters[ID];
@AndrewJHart
AndrewJHart / .env
Created March 18, 2016 20:06 — forked from allanlei/.env
Sample local Heroku/Django development environment using foreman
DATABASE_URL=postgres://USERNAME:PASSWORD@127.0.0.1/DATABASE
MEMCACHE_SERVERS=127.0.0.1:11211
DJANGO_SETTINGS_MODULE=settings.development.local
class DynamicFieldsMixin(object):
"""
A serializer mixin that takes an additional `fields` argument that controls
which fields should be displayed.
Usage::
class MySerializer(serializers.HyperlinkedModelSerializer, DynamicFieldsMixin):
class Meta:
model = MyModel
@AndrewJHart
AndrewJHart / validate_uuid4.py
Created February 26, 2016 15:19 — forked from ShawnMilo/validate_uuid4.py
Validating a uuid4 with Python.
from uuid import UUID
def validate_uuid4(uuid_string):
"""
Validate that a UUID string is in
fact a valid uuid4.
Happily, the uuid module does the actual
checking for us.
@AndrewJHart
AndrewJHart / README.md
Created February 26, 2016 00:22 — forked from rduplain/README.md
Connect to MSSQL using FreeTDS / ODBC in Python.

Goal: Connect to MSSQL using FreeTDS / ODBC in Python.

Host: Ubuntu 11.10 x86_64

Install:

sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc
pip install pyodbc sqlalchemy

In /etc/odbcinst.ini:

@AndrewJHart
AndrewJHart / logging_settings.py
Last active January 4, 2016 15:29 — forked from palewire/settings.py
Semi-advanced and useful logging config for django. Makes for good base to replace default Django config; great for app layout skeleton
# replaces default django logging config
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
},
'null': {
@AndrewJHart
AndrewJHart / Backbone.sync_csrftoken.js
Created November 14, 2013 15:47 — forked from gcollazo/Backbone.sync_csrftoken.js
Set backbone to automatically set the CSRF header token for django for all ajax requests
var oldSync = Backbone.sync;
Backbone.sync = function(method, model, options){
options.beforeSend = function(xhr){
xhr.setRequestHeader('X-CSRFToken', CSRF_TOKEN);
};
return oldSync(method, model, options);
};
def save_m2m(self, bundle):
"""
Handles the saving of related M2M data.
Due to the way Django works, the M2M data must be handled after the
main instance, which is why this isn't a part of the main ``save`` bits.
Currently slightly inefficient in that it will clear out the whole
relation and recreate the related data as needed.
"""
from django.db import models
import uuid
class UUIDField(models.CharField):
"""
A field which stores a UUID value in hex format. This may also have
the Boolean attribute 'auto' which will set the value on initial save to a
new UUID value (calculated using the UUID1 method). Note that while all
UUIDs are expected to be unique we enforce this with a DB constraint.