Skip to content

Instantly share code, notes, and snippets.

View pirj's full-sized avatar
🚜
Relentless

Phil Pirozhkov pirj

🚜
Relentless
View GitHub Profile
@pirj
pirj / Equation Greatest Common Divisior for a list of integers
Created May 3, 2009 19:00
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
struct list_item {
list_item *next; // указатель на следующий элемент списка
list_item *rand; // указатель на произвольный элемент списка
};
list_item *first; // указатель на первый элемент списка
list_item copy(){
int length = 0;
require 'kit/base'
# require 'kit/travian'
class Dozorni
extend Bot::Base
# extend Bot::Travian
def self.bot name, &b
::AllBots.bots[name] = b
end
commit 6b9484bd51ce108dcab1158062a0183348aa16d4
Author: Phil Pirj <[email protected]>
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
@pirj
pirj / agent.lua
Created February 23, 2010 15:04
Agent
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)
@pirj
pirj / простой
Created April 19, 2010 18:25
http proxy
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
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
def class_for_name name
namespaces = name.split '::'
base = Kernel
namespaces.each do |namespace| base = base.const_get(namespace) end
base
end
user app;
worker_processes 2;
error_log /home/app/logs/nginx.error.log info;
events {
worker_connections 1024;
}
@pirj
pirj / ability.rb
Created July 17, 2011 20:23
Padrino and CanCan
# 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