Skip to content

Instantly share code, notes, and snippets.

View dekart's full-sized avatar

Aleksey Dmitriev dekart

View GitHub Profile
@dekart
dekart / README
Last active August 29, 2015 14:01
Iptables setup for port forwarding on local dev machine.
Should be added to /etc/network/if-pre-up.d/iptable_rules
Don't forget to run
chmod +x /etc/network/if-pre-up.d/iptable_rules
@dekart
dekart / Nginx rc.d file
Created March 11, 2009 10:18
Nginx rc.d file
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
#!/usr/bin/env ruby
Dir["*"].each do |f|
if File.directory?(f) and File.directory?(File.join(f, ".git"))
command = "cd #{f}; git #{ARGV.collect{|a| a.include?(" ") ? "\"#{a}\"" : a }.join(" ")}"
puts "Command: #{command}"
result = `#{command}`
named_scope :victims_for, Proc.new{|attacker|
{
:conditions => [
%{
(level BETWEEN :low_level AND :high_level) AND
characters.id NOT IN (
SELECT fights.victim_id FROM fights WHERE attacker_id = :attacker_id AND winner_id = :attacker_id AND fights.created_at > :time_limit
) AND
characters.id != :attacker_id
},
VTM = {
:dice => 10,
:critical_failure => 1,
:critical_success => 10,
:success => 5
}
def calculate_dices(attacker, victim)
attack_points = attacker.attack_points
defence_points = victim.defence_points
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
require 'optparse'
require 'ostruct'
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
class Character < ActiveRecord::Base
extend SerializeWithPreload
LEVELS = [0]
200.times do |i|
LEVELS[i + 1] = LEVELS[i].to_i + (i + 1) * 10
end
UPGRADES = {
config.action_controller.asset_host = Proc.new do |source, request|
if source =~ %r{^/(pictures|brands|users)}i
"http://img.24video-test.net"
else
""
end
end
require "yaml"
require "benchmark"
class SomeClass
def initialize(value)
@value = value
end
end
hash = {
ruby serialize_bench.rb
user system total real
Marshal dump 0.350000 0.010000 0.360000 ( 0.355897)
Marshal load 0.310000 0.000000 0.310000 ( 0.312442)
YAML dump 15.900000 0.030000 15.930000 ( 16.127431)
YAML load 3.810000 0.010000 3.820000 ( 3.878175)