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 / 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 / kill_port.sh
Created February 26, 2016 16:23
how to kill a port on mac os x terminal
lsof -i tcp:8000 # or what ever port # you need to search for
kill -9 <PID> # replace <PID> with the process PID you want to kill
@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 / 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 / gunicorn.sh
Last active November 1, 2023 07:53
Django Gunicorn Daemon Script
# django gunicorn script
# Generates a Daemon process with Gunicorn.
# see processes with ps -aux
# tested on: Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-74-generic x86_64), aws ec2
# Runs on apps built with Django==1.9
# Marcus Shepherd <marcusshepdotcom@gmail.com>
# 3-12-16
NAME=project # REPLACE WITH BASE DIR NAME
@marcusshepp
marcusshepp / _etc_nginx_sites-enabled_default
Last active July 29, 2016 19:58
Basic Nginx Script Listen's for a Gunicorn Generated Sock File
upstream app_server {
server unix:/opt/proc/mysite-gunicorn.sock fail_timeout=0;
}
server {
listen 80;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
@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("]}");
}]);