Skip to content

Instantly share code, notes, and snippets.

@lightstrike
lightstrike / preview.js
Last active August 31, 2018 00:42
Example WordPress GatsbyJS Preview Page
import React, { Component } from "react";
import PropTypes from "prop-types";
import Helmet from "react-helmet";
class PreviewPage extends Component {
constructor() {
super();
this.state = {
post: {
title: {
@lightstrike
lightstrike / readable.py
Last active July 2, 2024 17:14
Readable.io API Python Wrapper
import hashlib
import time
import requests
class ReadableAPIClient:
"""
API Client for Readable.io, written for Python 3
See API documentation: https://readable.io/api/docs/
@lightstrike
lightstrike / admin.py
Created February 9, 2017 19:27
Custom User Admin
from django import forms
from django.contrib import admin
from django.utils.translation import ugettext as _
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from .models import User
class UserCreationForm(forms.ModelForm):
@lightstrike
lightstrike / models.py
Created February 7, 2017 14:43
Abstract Base Django Model w/ DB Indexing
from django.db import models
from django.utils.translation import ugettext_lazy as _
from model_utils.fields import AutoCreatedField, AutoLastModifiedField
class IndexedTimeStampedModel(models.Model):
created = AutoCreatedField(_('created'), db_index=True)
modified = AutoLastModifiedField(_('modified'), db_index=True)
class Meta:
@lightstrike
lightstrike / ny.geojson
Created September 25, 2016 18:25
NY Neighborhoods from Zillow
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lightstrike
lightstrike / set_leanplum_user_attributes.py
Created September 10, 2016 01:04
Setting User Attributes in Leanplum using Web API
import csv
from sys import argv
import requests
def transform_user_file(filename: str) -> []:
user_file = open(filename, 'r')
user_data = csv.reader(user_file)
# skip first row
@lightstrike
lightstrike / admin.py
Created June 8, 2016 23:20
Student Record Brainstorming
class StudenAdmin(admin.ModelAdmin):
inlines = (StudentRecordInline,)
@lightstrike
lightstrike / admin.py
Last active December 21, 2022 03:11
Before Import Customization for Django-Import-Export
class OrganizationImportExportResource(ModelResource):
types = widgets.ManyToManyWidget(model=graph_models.OrganizationType,
field='name')
class Meta:
model = Organization
fields = [
'name',
]
import_id_fields = ['name']
@lightstrike
lightstrike / .vimrc
Created February 18, 2016 00:40
Vimrc Config
" Initialize pathogen for flake8
execute pathogen#infect()
syntax on
filetype plugin indent on
" remove trailing spaces in Python & Markdown
autocmd BufWritePre *.py :%s/\s\+$//e
autocmd BufWritePre *.md :%s/\s\+$//e
" call flake8 at every save
@lightstrike
lightstrike / add_to_settings.py
Created January 19, 2016 17:39
Setting up model mommy generators for custom fields
from model_mommy import generators
MOMMY_CUSTOM_FIELDS_GEN = {
'easy_thumbnails.fields.ThumbnailerImageField': generators.gen_image_field,
'model_utils.fields.AutoCreatedField': generators.gen_datetime,
'model_utils.fields.AutoLastModifiedField': generators.gen_datetime,
'django_extensions.db.fields.AutoSlugField': generators.gen_slug,
}