Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Marcus Shepherd marcusshepp

🎯
Focusing
View GitHub Profile
@marcusshepp
marcusshepp / csrf.js
Last active Mar 11, 2016
Access CSRF token in external javascript file, using jquery.cookie.js
View csrf.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 Feb 26, 2016
how to kill a port on mac os x terminal
View kill_port.sh
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 Mar 11, 2016
How to create a function inside a Django migration file
View django_migration_function.py
# -*- 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 Mar 14, 2016
couldn't connect to aws ec2 instance
View ssh_config
# 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 Nov 3, 2020
Django Gunicorn Daemon Script
View gunicorn.sh
# 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 Jul 29, 2016
Basic Nginx Script Listen's for a Gunicorn Generated Sock File
View _etc_nginx_sites-enabled_default
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 Apr 8, 2016
javascript keycodes for chars and both delete btns
View js_char_keycodes.js
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 Apr 10, 2016
Vanilla Javascript AJAX Function
View ajax_request.js
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 Apr 10, 2016
Vanilla Javascript's equivalent to jQuery's $(document).ready(function(){});
View document_dot_ready.js
document.addEventListener("DOMContentLoaded", function(){});
@marcusshepp
marcusshepp / changing_angular_template_tags.js
Created Apr 26, 2016
Angular: using different template tags
View changing_angular_template_tags.js
var app = angular.module("myfirstapp", []);
app.config(["$interpolateProvider", function($interpolateProvider){
$interpolateProvider.startSymbol("{[");
$interpolateProvider.endSymbol("]}");
}]);
You can’t perform that action at this time.