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 / site.conf
Created October 1, 2015 12:49 — forked from paskal/site.conf
Nginx configuration for best security and modest performance. Full info on https://terrty.net/2014/ssl-tls-in-nginx/
# read more at https://terrty.net/2014/ssl-tls-in-nginx/
# latest version on https://gist.github.com/paskal/628882bee1948ef126dd/126e4d1daeb5244aacbbd847c5247c2e293f6adf
# security test score: https://www.ssllabs.com/ssltest/analyze.html?d=terrty.net
# your nginx version might not have all directives included, test this configuration before using in production against your nginx:
# $ nginx -c /etc/nginx/nginx.conf -t
server {
# public key, contains your public key and class 1 certificate, to create:
# (example for startssl)
# $ (cat example.com.pem & wget -O - https://www.startssl.com/certs/class1/sha2/pem/sub.class1.server.sha2.ca.pem) | tee -a /etc/nginx/ssl/domain.pem > /dev/null
@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() {