Skip to content

Instantly share code, notes, and snippets.

View rsadwick's full-sized avatar
🌪️
spin 2 win

Ryan Sadwick rsadwick

🌪️
spin 2 win
View GitHub Profile
@grappler
grappler / Gruntfile.js
Last active October 5, 2020 03:47
https://webtranslateit.com/en/docs/web_translate_it_client/ / http://docs.transifex.com/developer/client/ Run this command in the folder to install all of the files needed. `npm install --save-dev`
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
makepot: {
target: {
@jerivas
jerivas / active_user_middleware.py
Last active August 29, 2015 13:56
[Django] Active User Middleware. Let's you blacklist URLs requiring user auth without decorating every view. Whitelist approach here: https://djangosnippets.org/snippets/2845/
from re import compile
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.views import redirect_to_login
if hasattr(settings, "LOGIN_REQUIRED_URLS"):
URLS = [compile(expr) for expr in settings.LOGIN_REQUIRED_URLS]
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<!-- The required Stripe lib -->
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<!-- jQuery is used only for this example; it isn't required to use Stripe -->
@cyface
cyface / child_create.html
Created July 21, 2012 22:29
Django Many-To-Many Create With Intermediary (Through) Table
{% extends "base.html" %}
{% block content %}
<section title="Child Create" data-role="content">
<h2>Child Create</h2>
<form action="{% url child_create slug=form.family_slug.value %}" method="POST">
{{ form.errors }}
{% csrf_token %}
<ul>
@mdellavo
mdellavo / jquery.format.js
Created May 24, 2012 13:16
Format phone number/credit card/ssn/etc inputs by regular expression
(function() {
var formatters = {
'phone' : [/^\(?\s?(\d{3})\s?\)?\s?\-?\s?(\d{3})\s?\-?\s?(\d{4})$/, '($1) $2-$3' ],
'ssn' : [/^(\d{3})\s?\-?\s?(\d{2})\s?\-?\s?(\d{3})$/, '$1-$2-$3' ],
'creditcard' : [/^(\d{4})\s?\-?\s?(\d{4})\s?\-?\s?(\d{4})\s?\-?\s?(\d{4})$/, '$1-$2-$3-$4']
};
jQuery.fn.formatWith = function(regex, replacement) {
$(this).change(function() {
this.value = this.value.replace(regex, replacement);
@remy
remy / audiosprite.js
Created December 23, 2010 13:54
An example of how an audio sprite can be used (includes fixes for iOS)
function Track(src, spriteLength, audioLead) {
var track = this,
audio = document.createElement('audio');
audio.src = src;
audio.autobuffer = true;
audio.load();
audio.muted = true; // makes no difference on iOS :(
/* This is the magic. Since we can't preload, and loading requires a user's
input. So we bind a touch event to the body, and fingers crossed, the
@ryanflorence
ryanflorence / static_server.js
Last active February 27, 2025 06:28
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);