Skip to content

Instantly share code, notes, and snippets.

View nikrowell's full-sized avatar
⛰️

Nik Rowell nikrowell

⛰️
View GitHub Profile
@denis
denis / jquery.plugin_name.js
Created September 24, 2008 20:21
A simple jQuery plugin skeleton
(function ($) {
$.fn.pluginName = function (settings) {
settings = $.extend({
param: 'value'
}, settings);
return this.each(
function () {
var $this = $(this);
// plugin code here
<?php /*mongodb custom php session handler
copyright 2010 ryan day
lgpl
*/
$mongo = new Mongo();
//MongoSession::setConfig('collection','session_test');
$mongo_session = new MongoSession($mongo);
@saaji
saaji / JST.js
Created December 12, 2011 19:33
Tiny JavaScript Template loader/compiler with Handlebars.
var JST = {
prefix: 'js/templates/',
extension: '.hbs',
compile_template: function(name, data) {
this[name] = Handlebars.compile(data);
},
register_partial: function(name, data) {
this[name] = Handlebars.registerHelper(name, Handlebars.compile(data));
@mxriverlynn
mxriverlynn / 1-routing-delete.js
Created August 3, 2011 21:19
don't route commands and events
SomeModel = Backbone.Model.extend({});
SomeCollection = Backbone.Collection.extend({
model: SomeModel
});
SomeView = Backbone.view.extend({
el: "#some-model",
template: "#some-template",
@namlook
namlook / myapp.py
Created May 25, 2011 12:36
flask, celery and global g
from flask import Flask
app = Flask(__name__)
from flaskext.celery import Celery
celery = Celery(app)
def process_global(glob_obj):
g.db = app.config['MONGO_DATABASE'] # get the unpickle-izable database
for k,v in glob_obj.iteritems():
@chluehr
chluehr / toAscii.php
Created January 18, 2012 12:56
PHP clean url slug generator / converter (slug)
<?php
// source: http://cubiq.org/the-perfect-php-clean-url-generator
// author: Matteo Spinelli
// MIT License / http://creativecommons.org/licenses/by-sa/3.0/ (please re-check at source)
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-') {
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
@paulirish
paulirish / gist:366184
Created April 14, 2010 18:59
html5 geolocation with fallback.
// geo-location shim
// currentely only serves lat/long
// depends on jQuery
// doublecheck the ClientLocation results because it may returning null results
;(function(geolocation){
if (geolocation) return;
@charliepark
charliepark / hatchshow.js
Created July 30, 2011 16:07
A jquery typography plugin.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(window).load(function(){
$().hatchShow();
});
jQuery.fn.hatchShow = function(){
$('.hsjs').css('display','inner-block').css('white-space','pre').each(function(){
var t = $(this);
t.wrap("<span class='hatchshow_temp' style='display:block'>");
var pw = t.parent().width();
@joelnet
joelnet / example.html
Created June 3, 2011 18:03
Unobtrusive Knockout support library for jQuery
Choose a ticket class: <select id="tickets"></select>
<p id="ticketOutput"></p>
<script id="ticketTemplate" type="text/x-jquery-tmpl">
{{if chosenTicket}}
You have chosen <b>${ chosenTicket().name }</b>
($${ chosenTicket().price })
<button data-bind="click: resetTicket">Clear</button>
{{/if}}
@developit
developit / unistore.js
Last active September 8, 2020 15:13
Update: the newer & better version of this is published: https://github.com/developit/unistore
import { h, Component } from 'preact';
/** Creates a new store, which is a tiny evented state container.
* @example
* let store = createStore();
* store.subscribe( state => console.log(state) );
* store.setState({ a: 'b' }); // logs { a: 'b' }
* store.setState({ c: 'd' }); // logs { c: 'd' }
*/