Skip to content

Instantly share code, notes, and snippets.

View teropa's full-sized avatar

Tero Parviainen teropa

View GitHub Profile
@teropa
teropa / q_now.js
Created May 20, 2014 14:01
$q.now() - an immediately resolved promise oneliner for Angular.js
module.config(['$provide', function($provide) {
// Add a method to $q that returns a promise resolved to
// the given value. Use as: $q.now(42)
$provide.decorator('$q', ['$delegate', function($delegate) {
$delegate.now = function(value) {
var d = $delegate.defer();
d.resolve(value);
return d.promise;
};
@teropa
teropa / d-fens.js
Created May 7, 2014 09:36
Angular.js DI example
// Framework
function createInjector() {
var instanceCache = {};
var providerCache = {};
function constant(key, value) {
instanceCache[key] = value;
}
{ "names": [ "Anne", "Bette", "Cate", "Dawn",
"Elise", "Faye", "Ginger", "Harriot",
"Izzy", "Jane", "Kaye", "Liz",
"Maria", "Nell", "Olive", "Pat",
"Queenie", "Rae", "Sal", "Tam",
"Uma", "Violet", "Wilma", "Xana",
"Yvonne", "Zelda",
"Abe", "Billy", "Caleb", "Davie",
"Eb", "Frank", "Gabe", "House",
"Icarus", "Jack", "Kurt", "Larry",

On Lisp

Instead of just writing your program in Lisp, you can write your own language on Lisp, and write your program in that.

It is possible to write programs bottom-up in any language, but Lisp is the most natural vehicle for this style of programming. In Lisp, bottom-up design is not a special technique reserved for unusually large or difficult programs. Any substantial program will be written partly in this style. Lisp was meant from the start to be an extensible language. [...]

@teropa
teropa / angular_toc.md
Created November 11, 2013 18:39
A preliminary table of contents for "Build Your Own AngularJS"

0. Project Setup

Part 1: Scopes

1. Scopes and Digest

2. Scope Inheritance

3. Watching Collections

Part 2: Expressions And Filters

4. Lexing Expressions

5. Parsing Expressions

6. Expressions On The Scope

7. Creating Filters

/*
* call-seq:
* Rugged::Repository.new(name, options = {}) -> repository
*
* Open a Git repository with the given +name+ and return a +Repository+ object
* representing it.
*
*/
static VALUE rb_git_repo_new(int argc, VALUE *argv, VALUE klass)
{
@teropa
teropa / resources.md
Last active December 4, 2020 05:42
Clojure Resources

Tutorials

@teropa
teropa / spec_helper.rb
Created November 30, 2012 14:16
Combine the Rails 3.2 tagged logger with rSpec around hooks -> See which spec did each query in test.log
config.around(:each) do |example|
Rails.logger.tagged(example.metadata[:full_description]) do
example.run
end
end
@teropa
teropa / res.clj
Created May 25, 2012 12:06
Reservation puzzle, one possible solution
(def seats (-> (repeat 5000 nil) vec ref))
(def clerks (repeatedly 10 #(agent 0)))
(defn available-indexes
"Given a sequence of seats, returns a (lazy)
sequence of the indexes of the available seats.
This is purely functional and doesn't know anything
about refs or agents"
[seats]
(keep-indexed