Skip to content

Instantly share code, notes, and snippets.

@marcofiset
marcofiset / average.clj
Last active August 29, 2015 14:26 — forked from fadelakin/average.clj
A function that calculates the average of some numbers in Clojure
(defn average
[numbers]
(if (empty? numbers)
0
(/ (reduce + numbers) (count numbers))))
@marcofiset
marcofiset / angular.js
Created November 12, 2014 22:33
Very simple and naive implementation of AngularJS, from https://www.youtube.com/watch?v=Mk2WwSxK218
function Scope() {
var self = this;
self.$$watchers = [];
self.$watch = function(watcherFn, listenerFn) {
self.$$watchers.push({
watcherFn: watcherFn,
listenerFn: listenerFn
});
@marcofiset
marcofiset / ioc.js
Last active August 29, 2015 14:08
Simple IoC container in javascript using function reference as types.
App = (function() {
var bindings = {};
return {
make: make,
bind: bind
};
function bind(type, object) {
bindings[type] = object;
@marcofiset
marcofiset / clear_tags.rb
Last active August 29, 2015 14:04 — forked from lfbittencourt/clear_tags.rb
Delete tags less than a specific version from a git repository, both locally and remotely.
# Tags with version number less than max_tag will be deleted
max_tag = ARGV[0]
if !Gem::Version.correct?(max_tag)
puts 'Incorect version number'
exit
end
tags = `git tag`.split(/\s+/).select do |t|
!Gem::Version::correct?(t) || Gem::Version.new(t) < Gem::Version.new(max_tag)
Locate the section for your github remote in the `.git/config` file. It looks like this:
```
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:joyent/node.git
```
Now add the line `fetch = +refs/pull/*/head:refs/remotes/origin/pr/*` to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:
@marcofiset
marcofiset / quicksort.js
Last active December 15, 2015 04:59
Recursive QuickSort in Javascript
Array.prototype.filter = function(callback) {
var result = [];
var length = this.length;
for (var i = 0; i < length; i++) {
if (callback(this[i])) {
result.push(this[i]);
}
}
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@marcofiset
marcofiset / heroku_mongomapper
Created July 19, 2012 00:58 — forked from kimenye/heroku_mongomapper
Sinatra + MongoMapper + MongoHQ + Heroku
require 'sinatra'
require 'uri'
require 'mongo_mapper'
mongo_url = ENV['MONGOHQ_URL'] || 'mongodb://localhost/dbname'
MongoMapper.connection = Mongo::Connection.from_uri mongo_url
MongoMapper.database = URI.parse(mongo_url).path.gsub(/^\//, '') #Extracts 'dbname' from the uri