Skip to content

Instantly share code, notes, and snippets.

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

Marat Khusnetdinov khusnetdinov

🏠
Working from home
View GitHub Profile
@khusnetdinov
khusnetdinov / simple_fiber_concurrency.rb
Created August 12, 2016 19:21 — forked from aprescott/simple_fiber_concurrency.rb
Simple example of concurrency in Ruby with Fiber.
require "fiber"
f1 = Fiber.new { |f2| f2.resume Fiber.current; while true; puts "A"; f2.transfer; end }
f2 = Fiber.new { |f1| f1.transfer; while true; puts "B"; f1.transfer; end }
f1.resume f2
@khusnetdinov
khusnetdinov / SOLID.markdown
Last active June 19, 2019 05:06 — forked from emaraschio/SOLID.markdown
SOLID Principles with ruby examples

#SOLID Principles with ruby examples

##SRP - Single responsibility principle A class should have only a single responsibility.

Every class should have a single responsibility, and that responsibility should be entirely encapsulated. All its services should be narrowly aligned with that responsibility, this embrace the high cohesion.

##OCP - Open/closed principle Software entities should be open for extension, but closed for modification.

@khusnetdinov
khusnetdinov / XXXXXXXXXXXXX_add_authentication_token_to_users.rb
Created August 2, 2016 19:03 — forked from gonzalo-bulnes/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
(Update: I've packaged this gist into a gem to make its use easier, see: https://github.com/gonzalo-bulnes/simple_token_authentication.) Add token authentication to your Rails API. Follows the José Valim recomendations and is fully compatible with Devise (tokens are created the first time users sign in). See https://gist.github.com/josevalim/fb7…
# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
@khusnetdinov
khusnetdinov / capybara cheat sheet
Created July 15, 2016 19:27 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@khusnetdinov
khusnetdinov / post_xml.rb
Created February 27, 2016 06:42 — forked from mattriley/post_xml.rb
Ruby HTTP POST request containing XML content
require 'net/http'
def post_xml url_string, xml_string
uri = URI.parse url_string
request = Net::HTTP::Post.new uri.path
request.body = xml_string
request.content_type = 'text/xml'
response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }
response.body
end
@khusnetdinov
khusnetdinov / doc.md
Created January 20, 2016 21:12 — forked from oelmekki/doc.md
Rails + Browserify + React + es7

1. Gemfile

gem 'browserify-rails', '1.5.0' # until fix: https://github.com/browserify-rails/browserify-rails/issues/101
gem 'react-rails'

Browserify-rails allows to use browserify within assets pipeline. React-rails is here only to allow to use #react_component (and thus, prerendering).

Note that jquery-rails can be removed from Gemfile, the npm version of jquery and jquery-ujs will be used instead.

def index
@products = ProductsSearch.new { |instance| instance.per_page = 27 }.search do |query|
query.order()
end
end
# source 'https://www.npmjs.com/'
assets_path 'assets/javascripts'
asset 'angular', '1.4.3' # Angular
asset 'angular-ui-bootstrap', '0.13.3' # Booustrap UI
asset 'Chart.js', '1.0.2' # Chart.js
asset 'angular-chart.js', '0.7.3' # Directives
class Dashboard::StoreProductsController < ApplicationController
before_filter :require_login
before_action :set_auction_durations, only: [:index, :edit]
AUCTION_DURATIONS = [['1 day', 24], ['3 days', 72], ['7 days', 168], ['30 days', 720], ['90 days', 2160]]
def index
@products = current_user.products.includes(:order)
@scope = params.fetch(:scope, 'all')
private static Boolean checkClonedFilesChecksum(String source, String result) throws IOException, NoSuchAlgorithmException {
String sourceChecksum = getChecksum(source);
String resultChecksum = getChecksum(result);
System.out.println("Source checksum: " + sourceChecksum);
System.out.println("Result checksum: " + resultChecksum);
return sourceChecksum.equals(resultChecksum);
}
private static String getChecksum(String fileName) throws IOException, NoSuchAlgorithmException {
MessageDigest msg = MessageDigest.getInstance("SHA1");