Skip to content

Instantly share code, notes, and snippets.

View thelinuxlich's full-sized avatar
🐉
Here be dragons

Alisson Cavalcante Agiani thelinuxlich

🐉
Here be dragons
View GitHub Profile
@VM =
estados: KO []
cidades: KO []
funcionario: new Funcionario() # KO model
VM.funcionario.estado = KO("SP").intercept (value) ->
if typeof value is "object"
@(value.value)
VM.carregaCidades(value.callback)
else if typeof value is "string"
/** Dependent observable with callback on write */
Function.prototype.intercept = function(callback) {
var underlyingObservable = this;
return ko.dependentObservable({
read: underlyingObservable,
write: function(value) { callback.call(underlyingObservable,
value) }
});
};
@thelinuxlich
thelinuxlich / config.ru
Created March 5, 2012 17:38
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
@thelinuxlich
thelinuxlich / gist:3218947
Created July 31, 2012 17:58
Knockout subscribeChanged
ko.subscribable.fn.subscribeChanged = function(callback) {
if (!this.previousValueSubscription) {
this.previousValueSubscription = this.subscribe(function(_previousValue) {
this.previousValue = _previousValue;
}, this, 'beforeChange');
}
return this.subscribe(function(latestValue) {
callback(latestValue, this.previousValue);
}, this);
};
@thelinuxlich
thelinuxlich / gist:3440606
Created August 23, 2012 19:26 — forked from caseman/gist:3428752
Ctor: Lightweight Javascript Constructors with Inheritance

Ctor: Lightweight Javascript Constructors with Inheritance

Author: Casey Duncan @iamnotcasey

This Javascript constructor with inheritance pattern is designed as a lightweight alternative to other methods I've seen while still providing a nice abstraction as a 13 line function that can be easily inlined into your code.

"Mudar status do item quando requisitado": function(){
this.xhr.respondWith([200, { "Content-Type": "application/json" },
'{"id": 1}']);
VM.itemNovo("Lavar a louça");
VM.adicionarItem();
this.xhr.respond();
VM.mudarStatusItem(VM.todoItens()[0]);
this.xhr.respond();
expect(VM.todoItens()[0].status()).toBe(true);
VM.mudarStatusItem(VM.todoItens()[0]);

Sass/Less Comparison

In this document I am using Sass's SCSS syntax. You can choose to use the indented syntax in sass, if you prefer it, it has no functional differences from the SCSS syntax.

For Less, I'm using the JavaScript version because this is what they suggest on the website. The ruby version may be different.

Variables

@thelinuxlich
thelinuxlich / Guardfile
Created August 31, 2012 17:42
Using Guard to automate laravel artisan test task
guard 'sass', :input=> 'public/sass', :output => 'public/css', :style => :compressed
guard 'coffeescript', :input => 'public/coffee', :output => 'public/js',:bare => true
module ::Guard
class ArtisanTest < Guard
def run_on_change(paths)
::Guard::UI.info("Running tests...")
::Guard::Notifier.notify("Running tests...",:title => "Laravel",:image => :pending)
output = `php artisan test`
if output =~ /FAILURE/
::Guard::Notifier.notify("Some tests failed!",:title => "Laravel",:image => :failed)
@thelinuxlich
thelinuxlich / gist:3777363
Created September 24, 2012 18:07 — forked from brunoandradd/gist:3777274
Config nginx com php/ruby
worker_processes 3;
events {
worker_connections 1024;
}
http {
passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7;
passenger_ruby /usr/local/bin/ruby;
@thelinuxlich
thelinuxlich / script.js
Created October 10, 2012 20:58
script.js
$(function() {
$.stayInWebApp();
function reorient(e) {
var landscape = (window.orientation % 180 == 90);
$("body > div").css("-webkit-transform", !landscape ? "rotate(90deg)" : "")
.css("-webkit-transform-origin", "512px 512px");
}
window.onorientationchange = reorient;
window.setTimeout(reorient, 0);
function reorient2(e) {