Skip to content

Instantly share code, notes, and snippets.

🌺

Phil Pirozhkov pirj

🌺
Block or report user

Report or block pirj

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pirj
pirj / Equation Greatest Common Divisior for a list of integers
Created May 3, 2009
Equation Greatest Common Divisior for a list of integers
View Equation Greatest Common Divisior for a list of integers
#!/usr/bin/env ruby
module Algo
# Gets the Greatest Common Divisior of integers a and b
def self.gcd(a, b)
if b == 0
a.abs
else
gcd(b, a % b)
end
View gist:289694
require 'kit/base'
# require 'kit/travian'
class Dozorni
extend Bot::Base
# extend Bot::Travian
def self.bot name, &b
::AllBots.bots[name] = b
end
View gist:302554
commit 6b9484bd51ce108dcab1158062a0183348aa16d4
Author: Phil Pirj <pirj@mail.ru>
Date: Wed Feb 10 23:17:46 2010 +0300
adding /logs
diff --git a/container.rb b/container.rb
index 6bec45a..5d80b29 100644
--- a/container.rb
+++ b/container.rb
View agent.lua
require 'util'
require 'luarocks.require' -- http://www.luarocks.org/
local http = require 'socket.http' -- http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/
local bot_container = 'http://dozorni.heroku.com/whatnow'
local body, status = http.request(bot_container, '')
local json = require('json') -- http://luaforge.net/projects/luajson/
local dec = json.decode(body)
View простой
local function handler(sock_in)
local line = sock_in:receive('*l')
-- where to?
local url = string.match(line, 'http://([%a%d\.-]+):*%d*/')
local port = string.match(line, 'http://[%a%d\.-]+:(%d+)/')
local sock_out = socket.connect(url, port or 80)
repeat
if line then sock_out:send(line..'\r\n') end
View data
6
whale: big black water animal
penguin: black white ice beak
piano: keyboard black white wire
jackboot: leather heel black
train: rail wheel black
rose: red green thorn
4
whale penguin piano jackboot train
penguin piano
View class for complex names, e.g. Errno::ENOENT
def class_for_name name
namespaces = name.split '::'
base = Kernel
namespaces.each do |namespace| base = base.const_get(namespace) end
base
end
View nginx.conf
user app;
worker_processes 2;
error_log /home/app/logs/nginx.error.log info;
events {
worker_connections 1024;
}
@pirj
pirj / ability.rb
Created Jul 17, 2011
Padrino and CanCan
View ability.rb
# include this in app file
# this is for Role Based Access Controle, can be much shorter
class Ability
include CanCan::Ability
def initialize account
@abilities ||= {}
allow [:any, :manager, :manufacturer, :admin] do
You can’t perform that action at this time.