Skip to content

Instantly share code, notes, and snippets.

View ergusto's full-sized avatar
😏

Fergus Ruston ergusto

😏
View GitHub Profile
@ergusto
ergusto / Forms.py
Created July 30, 2014 12:05
Registration with CBVs
from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User
class RegistrationForm(ModelForm):
password_1 = forms.CharField(label=(u'Verify Password'), widget=forms.PasswordInput())
class Meta:
model = User
fields = ('username', 'password')
{
init: function(elevators, floors) {
var waitingFloors = [];
_.each(elevators, function(elevator) {
elevator.on("floor_button_pressed", function(floorNum) {
elevator.goToFloor(floorNum);
});
elevator.on("up_button_pressed", function(floorNum) {
elevator.goToFloor(floorNum);
});
@ergusto
ergusto / gist:5509606
Last active December 16, 2015 22:49
Simple battleship game in Python
from random import randint
board = []
for x in range(5):
board.append(["O"] * 5)
def print_board(board):
for row in board:
print " ".join(row)
@ergusto
ergusto / gist:6000407
Last active December 19, 2015 18:39
Paths for Django settings files
import django
import os
DJANGO_ROOT = os.path.dirname(os.path.realpath(django.__file__))
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
'''
Example usage:
STATIC_ROOT = os.path.join(SITE_ROOT, 'static'),
@ergusto
ergusto / markup.py
Created August 26, 2013 16:53 — forked from defrex/markup.py
import markdown as mkdn
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@register.filter()
def markdown(value):

Install Python

$ brew install readline sqlite gdbm --universal
$ brew install python --universal --framework
$ python --version
Python 2.7

Symlinks...

@ergusto
ergusto / imageSyncing.js
Created January 22, 2017 16:01 — forked from jice-lavocat/imageSyncing.js
AWS Lambda - S3 : Thumbnail creation
// dependencies
var async = require('async');
var path = require('path');
var AWS = require('aws-sdk');
var gm = require('gm').subClass({
imageMagick: true
});
var util = require('util');
// get reference to S3 client
var s3 = new AWS.S3();
@ergusto
ergusto / upload.py
Created January 22, 2017 17:49 — forked from RyanBalfanz/upload.py
[Heroku] Direct to S3 File Uploads in Python
"""
Fix for some issues with the original code from Heroku:
https://devcenter.heroku.com/articles/s3-upload-python
This example is also designed for use with Django, not Flask as in the original.
"""
import base64
import hashlib
import hmac
import functools
from channels.handler import AsgiRequest
from rest_framework.exceptions import AuthenticationFailed
from rest_framework.settings import api_settings
authenticators = [auth() for auth in api_settings.DEFAULT_AUTHENTICATION_CLASSES]
@ergusto
ergusto / reminder.sh
Last active March 1, 2019 16:52 — forked from lekro/reminder.sh
Send discord webhook using curl
#!/bin/sh
WEBHOOK_URL="put your url here"
JSON="{\"content\":null,\"embeds\": [{\"color\": \"16237652\"},{\"timestamp\": \"YYYY-MM-DDTHH:MM:SS.MSSZ\"},{\"fields\": [{\"name\": \"Grabbed Movie\",\"value\": \"$radarr_movie_title\"},{\"name\": \"Release Name\",\"value\": \"$radarr_release_title\"},{\"name\": \"Quality\",\"value\": \"$radarr_release_quality\",\"inline\": true},{\"name\": \"Source\",\"value\": \"$radarr_release_indexer\",\"inline\": true},{\"name\": \"Size\",\"value\": \"$radarr_release_size\"}]}]}\"
curl -d "$JSON" -H "Content-Type: application/json" "$WEBHOOK_URL"