This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def to_u_phone | |
if self.match(/[,;]/) | |
return self.split(/\s*[,;]\s*/).map(&:to_u_phone).sort.join(", ") | |
end | |
number = self.gsub(/\D/, '').gsub(/^(8?0|380)/, '').strip | |
return '' if number.blank? | |
number = "2" + number if 6 == number.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CDEPEND=" | |
#... | |
nginx_modules_http_passenger? ( | |
>=dev-ruby/rubygems-1.3.7 # версия свежее, чем действительно необходимо, такова воля левой пятки | |
>=dev-ruby/rake-0.8.7 | |
)" | |
pkg_setup() { | |
#... | |
if use nginx_modules_http_passenger; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@entries = e | |
@tags = {:incomings => Hash.new(0), :expenses => Hash.new(0)} | |
@dailies = {:incomings => Hash.new(0), :expenses => Hash.new(0), :tags => Hash.new { |h, k| h[k] = Set.new} } | |
@entries.each do |i| | |
if i.amount < 0 | |
@dailies[:expenses][i.created_at] += i.amount.to_f | |
else | |
@dailies[:incomings][i.created_at] += i.amount.to_f | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import os | |
import random | |
import sys | |
import time | |
from collections import defaultdict | |
random.seed(os.urandom(16)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Category < ActiveRecord::Base | |
has_many :items | |
has_many :tags, through: :items | |
end | |
class Item < ActiveRecord::Base | |
belongs_to :category | |
has_many :taggings, dependent: :destroy | |
has_many :tags, through: :taggings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Element.prototype.is_visible = (scrollTop, height) -> | |
_top = $(this).offset().top | |
_height = $(this).height() | |
scrollTop <= _top <= scrollTop + height or | |
scrollTop <= _top + _height <= scrollTop + height or | |
(scrollTop > _top and _top + _height > scrollTop + height) | |
jQuery -> | |
if $("#items").length | |
window.ItemsPager = new ItemsPager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):055:0> o = Order.last | |
Order Load (0.4ms) SELECT "orders".* FROM "orders" ORDER BY "orders"."id" DESC LIMIT 1 | |
=> #<Order id: 143, customer_id: 13, session_id: "5c7f3b0268022483ed1c87ff9fb5304a", state: nil, discount: #<BigDecimal:7fe419d863f0,'0.0',9(18)>, balance: #<BigDecimal:7fe419d86328,'0.0',9(18)>, notes: nil, shipping_method: nil, shipping_details: nil, created_at: "2012-09-16 17:27:39", updated_at: "2012-09-16 21:09:56"> | |
irb(main):056:0> oi = o.order_items.includes(item: :photos) | |
OrderItem Load (0.4ms) SELECT "order_items".* FROM "order_items" WHERE "order_items"."order_id" = 143 | |
Item Load (0.2ms) SELECT "items".* FROM "items" WHERE "items"."id" IN (227) | |
Photo Load (0.1ms) SELECT "photos".* FROM "photos" WHERE "photos"."item_id" IN (227) | |
=> [#<OrderItem id: 302, order_id: 143, item_id: 227, item_price: #<BigDecimal:7fe4198f21b8,'0.5E2',9(18)>, quantity: 1, size: 95, type: "rent", starts_on: "2012-09-17", ends_on: "2012-09-18", created_at: "2012-09-16 20:03:33", updated_at: "2012-0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
main() { | |
root=$1 | |
for i in $(find $root -type d -iname '.Training.Spam'); do | |
process_maildir $(dirname $i) | |
done | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
src = [["Ukraine", ["Kyiv", "Kharkov"]], ["France", ["Paris", "Marseilles"]], ["Poland", ["Warsaw", "Krakow"]]] | |
dst = src.flat_map { |(country, cities)| cities.map { |city| "#{country}/#{city}" }} | |
puts dst.map { |i| [i, dst - [i]]}.inspect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
letters = ARGV[0].split('') | |
words = open("/usr/share/dict/words").read.split(/\n/).reduce([]) do |words, word| | |
signature = word.chomp.downcase.split('') | |
words << word if signature == signature & letters | |
words | |
end |
OlderNewer