Skip to content

Instantly share code, notes, and snippets.

View makaroni4's full-sized avatar

Anatoli Makarevich makaroni4

View GitHub Profile
require "socket"
socket = TCPSocket.open("www.theonion.com", "80")
TCPSocket.open("www.theonion.com", 80) do |socket|
socket.puts "GET / HTTP/1.0\n\n"
puts socket.read
end
@makaroni4
makaroni4 / Question_4.rb
Created March 24, 2014 13:31
Ruby Quiz questions
# Reddit thread: http://www.reddit.com/r/ruby/comments/217yvm/trivia_ruby_quiz/
# Quiz page: http://makaroni4.com/ruby/quiz/2014/03/24/ruby-quiz/
# Explanation link: http://www.medihack.org/2011/03/15/intend-to-extend/
# Code example:
module Human
def eat
puts "Yam"
end
@makaroni4
makaroni4 / check_sexp.rb
Last active August 29, 2015 14:01
String interpolation in Ruby
require 'ripper'
require 'pp'
sexp = Ripper.sexp '"Hello #{ friend } vs Hello #{friend}"'
pp sexp
# [:program,
# [[:string_literal,
# [:string_content,
# Adapted slightly from Sam Dutton
# Set name of hidden property and visibility change event
# since some browsers only offer vendor-prefixed support
hidden = undefined
state = undefined
visibilityChange = undefined
if typeof document.hidden isnt "undefined"
hidden = "hidden"
visibilityChange = "visibilitychange"
state = "visibilityState"
// скрипт учитывает повторные голосования пользователей и максимум 3 картинки от одного пользователя
var numbers = {};
var voted_users = {};
$(".comment").each(function(i, comment) {
var user_id = $(comment).find("a[role='comment-user']").attr("href");
console.log(user_id)
if(voted_users[user_id] == undefined) {
require 'benchmark/ips'
require 'benchmark'
Benchmark.ips do |r|
r.report("one") do
'string' + 'string'
end
r.report("two") do
"string" + "string"
require 'benchmark/ips'
Benchmark.ips do |r|
r.report("mass") do
a, b, c, d = 1, 2, 3, 4
end
r.report("step by step") do
a = 1
b = 2
def smart_subtract(arr_1, arr_2, action)
hash_1 = Hash[arr_1]
hash_2 = Hash[arr_2]
result = []
hash_1.each do |key, value|
if hash_2[key]
result << [key, value.send(action, hash_2[key])]
else
result << [key, value]
@makaroni4
makaroni4 / mimimetrics.rb
Created August 10, 2014 09:10
Реализация отправки Operation данных в Mimimetrics API на Ruby
require 'net/http'
require 'uri'
require 'json'
def send_operation()
data = {
operation: {
operation_id: "24215140440800001402186",
amount: 571.13,
direction: "in",
@makaroni4
makaroni4 / mimimetrics_cpas.rb
Created August 10, 2014 09:14
Пример запроса к API Mimimetrics для отправки данных о CPA
require 'net/http'
require 'uri'
require 'json'
def send_operation()
data = {
cpa: {
amount: "24215140440800001402186",
datetime: "2007-09-01T21:30:04.000+04:00",
}