Skip to content

Instantly share code, notes, and snippets.

View foxweb's full-sized avatar
🏠
Working from home

Aleksey Kurepin foxweb

🏠
Working from home
View GitHub Profile
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Example aliases
-='cd -'
..='cd ..'
...='cd ../..'
1='cd -'
2='cd -2'
3='cd -3'
4='cd -4'
5='cd -5'
6='cd -6'
7='cd -7'
@foxweb
foxweb / utf8.rb
Last active August 29, 2015 14:01
require 'benchmark'
n = 10000000000
Benchmark.bm do |x|
x.report { puts "hello йё".force_encoding("ISO-8859-1").encode("UTF-8") } # насильно в латиницу и обратно в UTF
x.report { puts "hello йё".encode("UTF-8").force_encoding('UTF-8') } # из UTF и в UTF
x.report { puts "hello йё".encode("UTF-8", invalid: :replace, undef: :replace, replace: "?") } # мягкое исправление ошибок кодировки
x.report { puts "hello йё" } # как есть
end
require 'mysql2'
client = Mysql2::Client.new(host: "127.0.0.1", username: "root", database: "test", encoding: "utf8")
File.open('9220.txt').each do |line|
line.chomp!
sql = "SELECT p.account, CONCAT(u.lname, ' ', u.fname, ' ', u.sname) username, u.email
FROM payments2 p JOIN users u ON userid = u.user_id
WHERE account = '#{line}'"
# create_table :domains, force: true do |t|
# t.string :slug, null: false
# t.integer :path, default: [], null: false, array: true
# t.datetime :created_at
# t.datetime :updated_at
# end
#
# add_index :domains, [:slug, :path], name: :index_domains_on_slug_and_path, unique: true, using: :btree
class Domain < ActiveRecord::Base
# Класс создатель объектов Url и связанных сущностей.
class UrlCreator
attr_reader :url
# Инициирует модель Url на основе полного URL.
#
# @param [String] full_url какой-то URL (http://www.linux.org.ru/forum/talks/8623652)
#
def initialize(full_url)
@url = URI.parse(full_url)
0.01 14.972 0.038 0.000 14.934 11461 *ActiveSupport::Callbacks::Filters::End#call
0.01 0.044 0.037 0.000 0.007 8974 Time#strftime
0.01 14.823 0.037 0.000 14.785 8974 *ActiveRecord::Timestamp#create_record
0.01 1.582 0.037 0.000 1.545 8974 ActiveSupport::TimeWithZone#respond_to_missing?
0.01 4.352 0.037 0.000 4.315 10000 ActiveRecord::ConnectionAdapters::OpenTransaction#commit
0.01 0.558 0.037 0.000 0.521 4487 Arel::Visitors::ToSql#visit_Arel_Nodes_InsertStatement
0.01 0.282 0.037 0.000 0.245 8974 TZInfo::TimeOrDateTime#+
0.01 0.500 0.036 0.000 0.464 4487 ActiveModel::Validations#valid?
0.01 0.056 0.036 0.000 0.020 26922 Time#nsec
0.01 0.183 0.036 0.000 0.148 7 <Module::Kernel>#load
hash = {
topics: "quod",
page: "omnis",
rubrics: {
russia: {
tags: [
"at",
"et"
]
},
types = %w(people companies places events type1 type2 type3 type4 type5 type6)
positions =* (1..10)
Document.all.each do |document|
puts 'Document GID: ' + document.gid.to_s
positions.each do |position|
tagging = Tagging.create do |tagging|
tagging.document_gid = document.gid
tagging.type = types.sample
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
/*******************************************************
This program will test the LCD panel and the buttons
Mark Bramwell, July 2010
********************************************************/