This file contains hidden or 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
| // скрипт учитывает повторные голосования пользователей и максимум 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) { |
This file contains hidden or 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
| # 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" |
This file contains hidden or 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
| require 'ripper' | |
| require 'pp' | |
| sexp = Ripper.sexp '"Hello #{ friend } vs Hello #{friend}"' | |
| pp sexp | |
| # [:program, | |
| # [[:string_literal, | |
| # [:string_content, |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| require 'parser' | |
| require 'parser/current' | |
| module OneLetterVariableDetector | |
| class NodeAnalyzer < Struct.new(:node, :path) | |
| def analyze | |
| return unless node && node.respond_to?(:type) | |
| if node.type == :lvasgn || node.type == :lvar | |
| if lvar_name.size == 1 |
This file contains hidden or 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
| train_path.each do |obj| | |
| result << obj.obj_id | |
| end if train_path.any? | |
| # | |
| # 1. Если ты вызываешь метод .each, то как минимум переменная | |
| # должна иметь множественное число, это ведь коллекция (массив), | |
| # т.е. это train_paths | |
| # | |
| # 2. Если массив пуст, то метод .each сразу вернет пустой массив |
This file contains hidden or 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
| require 'active_record' | |
| require 'csv' | |
| ActiveRecord::Base.establish_connection( | |
| adapter: "mysql2", | |
| host: "localhost", | |
| database: "36on_development", | |
| user: "username", | |
| password: "password", | |
| pool: 5, |
This file contains hidden or 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
| require 'benchmark' | |
| require 'benchmark/ips' | |
| Benchmark.ips do |r| | |
| r.report("group_by") do | |
| (0..1000).group_by { |w| w % 2 == 0 }.values | |
| end | |
| EVEN = 0 | |
| ODD = 1 |
This file contains hidden or 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
| at_exit do | |
| deploy.unlock | |
| end | |
| set :deploy_lock_file, "#{shared_path}/tmp/deploing_lock_file" | |
| namespace :deploy do | |
| desc "Check if somebody already is deploing" | |
| task :check_lock do |