Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

- roles = []
- roles << {"Can manage users" => {:scope =>["reza", "waitline"]}}
- roles << {"Can change settings" => {:scope =>["pssurvey"]}}
- roles << {"Can use" => {:scope =>["account"]}}
.container
.row
.span12
= ko_context system: {users: {"Arek" => roles, "田中" => roles }}, settings: [1,2,3] do
/ko foreach: window.s = new System(context.model.system).users
class ApplicationController < ActionController::Base
# Creates an accessor which is exposed to the view
def self.view_accessor(*names)
attr_accessor *names
helper_method *names
end
end
# Usage: redis-cli publish message.achannel hello
require 'sinatra'
require 'redis'
conns = Hash.new {|h, k| h[k] = [] }
Thread.abort_on_exception = true
get '/' do
@arekt
arekt / gist:5275479
Created March 30, 2013 05:16
Example how to use content_for
+ def ble # concatenates everything and you can render whole part in partial by calling yield :ble, or content_for :ble
+ content_for :ble, content_tag(:p, "Here form starts:")
+ content_for :ble, content_tag(:p, "Here form starts:")
+ content_for :ble, content_tag(:p, "Here form starts:")
+ content_for :ble, content_tag(:p, "Here form starts:")
+ render "shared/bootstrap/ble"
+ end
+
+ def ble2 # you can render everything on the end of helper as well
+ content_for :ble, content_tag(:p, "Here form starts: asdfasdf")
@arekt
arekt / index.html.haml
Created February 25, 2013 01:16
Example from Codeschool knockout, with small changes rewritten in coffee and haml.
.container
%h1 Todo List
%ul.todos(data-bind="foreach: todos")
%li(data-bind="attr: {class: className}")
%input(type="checkbox" data-bind="checked: completed")
%span(data-bind="text: title")
%a(data-bind="visible: allowClear, click: clearList") Clear List
%input(type="text" placeholder="New Todo Title" data-bind="value: todoToAdd, event: {change: addTodo}")
class AppSettings::Base
@show_info = true
class << self
attr_accessor :cells
attr_accessor :show_info
end
def self.setup(&block)
yield(self)
end
@arekt
arekt / to_proc.rb
Created September 6, 2012 14:28
to_proc
class Filter
def initialize()
@constraints = []
end
def constraint(&block)
@constraints << block
end
def to_proc
@arekt
arekt / AbstractModel.rb
Created July 28, 2012 21:13
Delegating methods to some class
class AbstractModel
def self.set_target(model_name)
@@model_name = model_name
AbstractModel.class.delegate :find, :to => :"#{@@model_name}"
AbstractModel.class.delegate :all, :to => :"#{@@model_name}"
end
end
#AbstractModel.set_target("Product")
#AbstractModel.find(1)
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
require 'sinatra/base'
require 'curl'
class FbConnect < Sinatra::Base
get '/info' do
"Redirect URL: #{ENV['REDIRECT_URL']} session_data:#{session.inspect}"
end
require 'rubygems'
require 'mongo_mapper'
MongoMapper.connection = Mongo::Connection.new('localhost',27017)
MongoMapper.database = "test"
class User
include MongoMapper::Document
key :name, String
many :ideas do