Skip to content

Instantly share code, notes, and snippets.

import numpy as np
def vectorize(x):
# vectorize a string
if len(x) > 1:
return np.sum([vectorize(c) for c in x], axis=0)
if x == '.':
i = 27
elif x == ' ':
i = 26
@slacy
slacy / models.py
Created September 4, 2012 21:56
Django Model mixin for pushing signal handling back into instance methods.
class SignalModel(models.Model):
"""A Model mixin class that lets you put your signal handler methods back into your Model class."""
@classmethod
def _sig_pre_delete(cls, instance, *args, **kwargs):
"""dispatch the pre_delete method to a regular instance method. """
return instance.sig_pre_delete(*args, **kwargs)
@classmethod
def _sig_post_delete(cls, instance, *args, **kwargs):
@0sn
0sn / build_rt.py
Created April 15, 2013 16:59
A python script to turn rescuetime data into something that Panic's StatusBoard app understands
#/usr/local/bin/python
"""Build Rescuetime Graph Data for StatusBoard.app
This script pulls data from a rescuetime account and flattens it into a format
that is easily read by StatusBoard. Okay. Run it with cron or launchd, whatever.
*nick wolfe
http://nameremoved.com/
"""
@IBestuzhev
IBestuzhev / .pylint.py
Last active February 13, 2019 05:01
Pylint for remote projects
#!/usr/bin/env python3
import subprocess
import sys
path = sys.argv[-1]
if path.startswith('/path/to/my/local/source/folder/'):
path = path.replace('/path/to/my/local/source/folder/', '/app/folder/')
subprocess.run(['docker-compose', 'exec', '-T', 'cross', 'sh', '-c',
@embr
embr / gist:4707996
Created February 4, 2013 17:03
RescueTime Python API Example
# coding: utf-8
import pprint
import pandas as pd
from rescuetime.api.service import Service
from rescuetime.api.access import AnalyticApiKey
s = Service.Service()
k = AnalyticApiKey.AnalyticApiKey(open('rt_key').read(), s)
p = {}
@tebeka
tebeka / gist:5426211
Created April 20, 2013 14:43
Serving dynamic images with Pandas and matplotlib (using flask)
#!/usr/bin/env python2
'''Serving dynamic images with Pandas and matplotlib (using flask).'''
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from cStringIO import StringIO
@cdemers
cdemers / Installing a Go development environment on Mac OS for beginners.md
Last active June 21, 2020 20:08
How to install a functional Go development environment on MacOS with Atom and all the bells and whistles.

Warning! This doc is pretty outdated, I'm rewriting it right now and I'll update this as soon as it's done.


Installing a Go development environment on Mac OS for Beginners

Installing Go

First, install the Go compiler from Google's Go Website: https://golang.org/dl/

@tomilov
tomilov / springer-free-maths-books.sh
Created December 29, 2015 15:54 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
wget http://link.springer.com/content/pdf/10.1007/978-1-4757-1779-2.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4757-2103-4.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4684-9884-4.pdf
wget http://link.springer.com/content/pdf/10.1007/978-3-662-02945-9.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4612-9923-3.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4757-3828-5.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4684-9936-0.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4419-8566-8.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4757-4385-2.pdf
wget http://link.springer.com/content/pdf/10.1007/978-1-4419-8592-7.pdf
@veuncent
veuncent / create_wagtail_pages_through_migration
Last active August 26, 2021 07:39
Set wagtail (home)pages programmatically during Django Migrations
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from wagtail.wagtailcore.models import Page, Site
def forwards_func(apps, schema_editor):
HomePage = apps.get_model('website', 'HomePage')
@undefobj
undefobj / index.js
Last active August 17, 2022 18:28
Calling AppSync from Lambda
const https = require('https');
const AWS = require("aws-sdk");
const urlParse = require("url").URL;
const appsyncUrl = process.env.API_BACKENDGRAPHQL_GRAPHQLAPIENDPOINTOUTPUT;
const region = process.env.REGION;
const endpoint = new urlParse(appsyncUrl).hostname.toString();
const graphqlQuery = require('./query.js').mutation;
const apiKey = process.env.API_KEY;
exports.handler = async (event) => {