Skip to content

Instantly share code, notes, and snippets.

View RKushnir's full-sized avatar

Roman RKushnir

View GitHub Profile
@RKushnir
RKushnir / check_availability.js
Created March 14, 2014 10:35
Show Intertop.ua product availability on click
$('.item_img').click(function(e) {
e.preventDefault();
var product_id = $(this).attr('href').match(/\/(\d+)\.html/)[1]
$.post('/shop/item/shops', {
region_id: '***region***',
size: '***size***',
product_id: product_id,
}, function(data) {
console.log(product_id, data.length > 0);
});
@RKushnir
RKushnir / action_controller_master.rb
Last active December 28, 2015 00:29
Url generation issue
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
GEMFILE
system 'bundle'
end
require 'bundler'
@RKushnir
RKushnir / action_controller_master.rb
Last active December 28, 2015 00:28
ActionController master bug report template issue
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
GEMFILE
system 'bundle'
end
require 'bundler'
(ns listener
(:require [clojure.java.io :as io])
(:import [java.net ServerSocket Socket])
(:import [java.io InputStreamReader BufferedReader]))
(def settings {:client-port 5000})
(defn get-reader [socket]
(BufferedReader. (InputStreamReader. (.getInputStream socket))))
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p385.tar.gz
tar -xvzf ruby-1.9.3-p385.tar.gz
cd ruby-1.9.3-p385/
CFLAGS="-march=native -O2" ./configure --prefix=/usr/local
make
make install
@RKushnir
RKushnir / circle.rb
Created February 12, 2012 15:53
Circle drawing algorithm
class Circle
def initialize(radius)
@radius = radius
end
def draw
unless @canvas
diameter = 2 * @radius
@canvas = Array.new(diameter + 1){ ' ' * (2 * (diameter + 1)) }
key_points.each do |kx, ky|
@RKushnir
RKushnir / count_ships.rb
Created January 6, 2012 19:28
Count the ships
field = [
[1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, ],
[1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, ],
[1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, ],
[0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, ],
[1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, ],
[1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, ],
]
count = 0