Skip to content

Instantly share code, notes, and snippets.

View marcusshepp's full-sized avatar
🎯
Focusing

Marcus Shepherd marcusshepp

🎯
Focusing
View GitHub Profile
@marcusshepp
marcusshepp / django_migration_function.py
Created March 11, 2016 23:47
How to create a function inside a Django migration file
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-03-11 23:37
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
def foo(apps, schema_editor):
@marcusshepp
marcusshepp / csrf.js
Last active March 11, 2016 23:49
Access CSRF token in external javascript file, using jquery.cookie.js
// base.html
<script type="text/javascript">
$(document).ready(function(){
var csrf = "{% csrf_token %}";
$.cookie("csrfmiddlewaretoken", csrf);
});
</script>
// script.js
var csrf_func = function(){
@marcusshepp
marcusshepp / ssh_config
Created March 14, 2016 18:59
couldn't connect to aws ec2 instance
# added this to
# ~/.ssh/config
Host ec2-52-38-4-225.us-west-2.compute.amazonaws.com
User ubuntu
IdentityFile ~/foobar.pem
IdentitiesOnly yes
@marcusshepp
marcusshepp / js_char_keycodes.js
Created April 8, 2016 15:41
javascript keycodes for chars and both delete btns
var keycode = event.which;
var valid_key = (keycode > 47 && keycode < 58) ||
(keycode > 64 && keycode < 91) ||
keycode == 8 || keycode == 48 ||
keycode == 190;
@marcusshepp
marcusshepp / ajax_request.js
Created April 10, 2016 15:33
Vanilla Javascript AJAX Function
var http_request = new XMLHttpRequest();
http_request.open("GET", "{% url 'api_categories' %}");
http_request.send(null);
http_request.onreadystatechange = function(){
var DONE = 4;
var OK = 200;
if (http_request.readyState === DONE){
if (http_request.status === OK){
console.log(http_request.responseText);
} else {
@marcusshepp
marcusshepp / document_dot_ready.js
Created April 10, 2016 16:28
Vanilla Javascript's equivalent to jQuery's $(document).ready(function(){});
document.addEventListener("DOMContentLoaded", function(){});
@marcusshepp
marcusshepp / changing_angular_template_tags.js
Created April 26, 2016 14:07
Angular: using different template tags
var app = angular.module("myfirstapp", []);
app.config(["$interpolateProvider", function($interpolateProvider){
$interpolateProvider.startSymbol("{[");
$interpolateProvider.endSymbol("]}");
}]);
@marcusshepp
marcusshepp / angular_get_request.js
Created April 26, 2016 15:33
Angular: Making a GET request
var foo_app = angular.module("foo_app", []);
foo_app.controller("bar_controller", ["$scope", "$http",
function ($scope, $http){
$http({
method: "GET",
url: "api/foo/bar/",
}).then(
function successCallback(response){
console.log(response);
<!doctype html>
<html ng-app>
<head>
<title>My Angular App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
</head>
<body>
</body>
</html>
@marcusshepp
marcusshepp / pip_install_solution.py
Created May 2, 2016 13:37
when pip installing a requirements file fails on something stupid
# collects and installs each requirement fully one at a time.
# rather than collecting all packages then installing.
import pip
from subprocess import call
with open("requirements.txt", "r") as req:
for package in req:
call("pip install " + package, shell=True)