Skip to content

Instantly share code, notes, and snippets.

View svenyurgensson's full-sized avatar

Yury Batenko svenyurgensson

View GitHub Profile
require "rubygems"
require "bson"
require "mongoid"
require 'ap'
Mongoid.configure do |config|
name = "test"
host = "localhost"
config.allow_dynamic_fields = false
<!DOCTYPE html>
<html>
<head>
<%= yield :meta %>
</head>
<body>
<%- content_for :meta do %>
<%= render text: "Trying to return something" %>
@svenyurgensson
svenyurgensson / Gemfile
Created April 19, 2012 12:04 — forked from fxposter/Gemfile
Test environment for rails apps
group :development, :test do
gem 'rspec-rails', '~> 2.9' # rails generate rspec:install
gem 'factory_girl_rails'
end
group :test do
gem 'spork-rails' # spork rspec --bootstrap
gem 'capybara'
gem 'launchy'
gem 'timecop'
@svenyurgensson
svenyurgensson / solver.rb
Created April 22, 2012 15:00
Partition problem solve
# -*- encoding : utf-8 -*-
# http://en.wikipedia.org/wiki/Partition_problem
# http://www.americanscientist.org/issues/id.3278,y.2002,no.3,content.true,page.1,css.print/issue.aspx
# http://www8.cs.umu.se/kurser/TDBAfl/VT06/algorithms/BOOK/BOOK2/NODE45.HTM
# http://ru.wikipedia.org/wiki/%D0%9B%D0%B8%D0%BD%D0%B5%D0%B9%D0%BD%D0%BE%D0%B5_%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5
# http://www.rubyquiz.com/quiz65.html
require 'pp'
require './source_array'
@svenyurgensson
svenyurgensson / geoip_service.rb
Created September 5, 2012 05:12 — forked from mislav/geoip_service.rb
Simple GeoIP service class using freegeoip.net and Faraday
require 'faraday_middleware'
require 'hashie/mash'
# Public: GeoIP service using freegeoip.net
#
# See https://github.com/fiorix/freegeoip#readme
#
# Examples
#
# res = GeoipService.new.call '173.194.64.19'
@svenyurgensson
svenyurgensson / easy_way.rb
Created September 5, 2012 05:12 — forked from mislav/easy_way.rb
RESOLVE SHORT URLS before storing. Short URLs are for microblogging; you should never actually keep them around.
require 'net/http'
# WARNING do not use this; it works but is very limited
def resolve url
res = Net::HTTP.get_response URI(url)
if res.code == '301' then res['location']
else url.to_s
end
end
@svenyurgensson
svenyurgensson / config.ru
Created September 5, 2012 05:16 — forked from mislav/config.ru
Shortest simplest sweetest web "hello {NAME}" in Ruby
run ->(e){ p=Hash[*e['QUERY_STRING'].split(/[&=]/)]; [200, {'Content-type'=>'text/html'}, ["Hello #{p['name']}!"]] }
@svenyurgensson
svenyurgensson / cmd.rb
Created September 5, 2012 05:17 — forked from mislav/cmd.rb
Execute a command, return its output, error stream and exit status
# returns [output string, err string, exit code]
def cmd(args, input = nil)
parent_read, child_write = IO.pipe
err_read, err_write = IO.pipe
child_read, parent_write = IO.pipe if input
pid = fork do
if input
parent_write.close
$stdin.reopen(child_read)
def index
@find_text = params[:text]
@find_type = params[:type]
page = params[:page] || 1
from = @find_from = (params[:from].blank?) ? (Time.now - 6.days).strftime("%d.%m.%Y") : params[:from]
till = @find_till = (params[:till].blank?) ? (Time.now + 1.day).strftime("%d.%m.%Y"): params[:till]
text = params[:text]
type = params[:type] || 1
type = type.to_i
(1.9.3@tops) master *% ~/projects/www/benj/tops $
>rails_best_practices .
Source Codes: 100% |oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo| Time: 0:00:03
./db/schema.rb:16 - always add db index (attachments => [attachmentable_id, attachmentable_type])
./db/schema.rb:107 - always add db index (products => [manufacturer_id])
./app/models/attachment_related/content_image.rb:31 - change Hash Syntax to 1.9
./app/controllers/admin/images_controller.rb:39 - change Hash Syntax to 1.9
./app/controllers/frontend_controller.rb:21 - change Hash Syntax to 1.9
./app/decorators/product_decorator.rb:26 - change Hash Syntax to 1.9
./config/application.rb:12 - change Hash Syntax to 1.9