Skip to content

Instantly share code, notes, and snippets.

View gurdasnijor's full-sized avatar
🤠

Gurdas Nijor gurdasnijor

🤠
View GitHub Profile
@sanxiyn
sanxiyn / lisp.c
Created August 14, 2010 04:16
Lisp
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
enum type {
NIL,
@zerowidth
zerowidth / paginated_collection.js
Created November 18, 2010 22:04
first whack at pagination with backbone.js
// includes bindings for fetching/fetched
PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage');
this.page = 1;
},
fetch: function(options) {
options || (options = {});
this.trigger("fetching");
@tbranyen
tbranyen / app.js
Created September 22, 2011 16:51
backbone.js sub routing
/* Pretend app setup stuff is here */
/* Kick off app */
jQuery(function($) {
var Gallery = app.module("gallery");
app.Router = Backbone.Router.extend({
initialize: function() {
this.gallery = new Gallery.Router("gallery/");
@dandean
dandean / backbone.model.es5properties.js
Created October 17, 2011 06:30
Monkey patch `Backbone.Model.extend()` with ES5 getters/setters for each attribute defined in the defaults.
/**
* Monkey patch `Backbone.Model.extend()` with ES5 getters/setters for each
* attribute defined in the defaults. Gives you the added bonus of being
* to pass your backbone models directly to your Mustache.js views.
*
* Example:
*
* var User = Backbone.Model.extend({
* defaults: {
* username: undefined,
@geddski
geddski / nesting.js
Created January 14, 2012 05:08
helper function for nesting backbone collections.
function nestCollection(model, attributeName, nestedCollection) {
//setup nested references
for (var i = 0; i < nestedCollection.length; i++) {
model.attributes[attributeName][i] = nestedCollection.at(i).attributes;
}
//create empty arrays if none
nestedCollection.bind('add', function (initiative) {
if (!model.get(attributeName)) {
model.attributes[attributeName] = [];
@jlongster
jlongster / gist:1840230
Created February 16, 2012 00:03
tracing Outlet code
(trace-source (let ((i (+ 4 5)))
(+ i (* 2 (/ 3 4)))))
;; Output
(let ((i (+ 4 5)))
(+ i (* 2 (/ 3 4))))
-- (+ 4 5)
>> RESULT: 9
@stuarthalloway
stuarthalloway / gist:2321773
Created April 6, 2012 18:15
Datomic schema query, constrained by attribute namespace
;; Datomic sample code
;; schema query for attribute types in specified namespaces
(q '[:find ?attr
:in $ [?include-ns ...] ;; bind ?include-ns once for each item in collection
:where
[?e :db/valueType] ;; all schema types (must have a valueType)
[?e :db/ident ?attr] ;; schema type name
[(datomic.Util/namespace ?attr) ?ns] ;; namespace of name
[(= ?ns ?include-ns)]] ;; must match one of the ?include-ns
@pelle
pelle / accounts.clj
Created May 8, 2012 14:37
Using database functions in Datomic transactions and annotating transaction history
(use '[datomic.api :only [q db] :as d])
(def uri "datomic:mem://accounts")
;; create database
(d/create-database uri)
;; connect to database
(def conn (d/connect uri))
@stuarthalloway
stuarthalloway / gist:2645453
Created May 9, 2012 15:22
Datomic queries against Clojure collections
;; Datomic example code
(use '[datomic.api :only (db q) :as d])
;; ?answer binds a scalar
(q '[:find ?answer :in ?answer]
42)
;; of course you can bind more than one of anything
(q '[:find ?last ?first :in ?last ?first]
"Doe" "John")
@drinchev
drinchev / require.js
Created May 9, 2012 17:34
implementation of require
(function() {
var modules = {}, cache = {};
if (this.require && this.require.modules) {
modules = this.require.modules;
}
var require = function(name, root) {
var path = expand(root, name), indexPath = expand(path, './index'), module, fn;
module = cache[path] || cache[indexPath];