Skip to content

Instantly share code, notes, and snippets.

class Cache
attr_reader :limit, :store, :queue
def [](key)
heat(key) if result = store[key]
result
end
def []=(key, value)
@Ptico
Ptico / password.js
Last active December 23, 2015 04:59
var Password = {},
utils;
function getOptionNum(target, defaults, rest) {
if (typeof(defaults) == 'undefined') defaults = 0;
var val = (typeof(target) == 'undefined') ? defaults : target;
if (val > rest) val = rest;
require 'spec_helper'
describe Aequitas::Violation, '#resource' do
subject { object.resource }
let(:object) { described_class.new(rule, resource) }
let(:rule) { mock('Rule') }
let(:resource) { mock('Resource') }
it { should equal(resource) }
@Ptico
Ptico / deploy.rb
Last active December 16, 2015 00:19 — forked from Lightpower/gist:5347055
require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
# require 'mina/rvm' # for rvm support. (http://rvm.io)
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
@Ptico
Ptico / abstract.rb
Created December 11, 2012 16:40
A tribute to abstract classes
module Abstract
def abstract(meth, args=[])
define_method(meth.to_sym) do |*params|
raise NotImplementedError, "method ##{meth} should be implemented with arguments (#{ args.join(', ') })"
end
end
end
class Hello
extend Abstract
@Ptico
Ptico / widget.js
Created August 30, 2012 16:10
bee.js widget proposition
define(["bee/widget", "app/models/transport", "app/modules/cargo-log"], function(Widget, Transport, CargoLog) {
"use strict";
var Transports = new Widget({
root: "#transports-sidebar",
extends: [CargoLog],
init: function() {
this.transports = [];
@Ptico
Ptico / class-test.js
Created April 15, 2012 01:20
Just an experiment with JS object model and ES5 functions
var Hello = Class({
attrReader: "val",
initialize: function(val) {
this.val = val;
},
publicFn: function() {
console.log(this.val);
this.privateFn();
App = {};
// Another sandbox functions
/**
* Creates namespace in sandbox by string definition
* If part of namespace already defined - keep it untouchable,
* else - create empty object.
*
* App.namespace("Hello.World");
var Baby = (function() {
function Baby(name) { // Constructor
this.name = name;
}
Baby.prototype = { // Public
introduce: function() {
alert("Hello! My name is " + name);
},
play: function() {
[BUG] Segmentation fault
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
-- Control frame information -----------------------------------------------
c:0007 p:---- s:0021 b:0021 l:000020 d:000020 CFUNC :next!
c:0006 p:0049 s:0018 b:0018 l:000017 d:000017 METHOD /Users/ptico/.rvm/gems/ruby-1.9.3-p0/gems/data_objects-0.10.7/lib/data_objects/reader.rb:35
c:0005 p:---- s:0014 b:0014 l:000013 d:000013 FINISH
c:0004 p:---- s:0012 b:0012 l:000011 d:000011 CFUNC :to_a
c:0003 p:0087 s:0009 b:0008 l:001638 d:002478 EVAL do.rb:8
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH