Skip to content

Instantly share code, notes, and snippets.

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

Alexandr Kovtunov AKovtunov

🏠
Working from home
View GitHub Profile
# Ruby 3.1+
users = [
{ name: "Yukihiro Matsumoto", age: 57 },
{ name: "Kabosu the Shiba Inu", age: 16 },
{ name: "Thiago Massa", age: 33 }
]
def fetch_age_from_person(person, hash)
hash => [*, {name: ^person, age: age}, *]
k = [1]
h = {}
h[k] = 1
k << 2
h[k] = 2
p h # {[1, 2]=>1, [1, 2]=>2}
k = [1]
h = {k => 1, (k << 2) => 2}
@komasaru
komasaru / twitter_access_token.rb
Created March 10, 2014 08:05
Ruby script to get twitter access token from consumer key.
# ***************************************
# Oauth - Access Token, Secret 取得処理
# ***************************************
require 'oauth'
class TwitterAccessToken
SITE_URL = "https://twitter.com"
def get_token
# Consumer 情報入力
@bjensen
bjensen / bootstrap_breadcrumbs_builder.rb
Created April 16, 2012 17:51
How to make breadcrumbs_on_rails render a Bootstrap compatible breadcrumb navigation
# The BootstrapBreadcrumbsBuilder is a Bootstrap compatible breadcrumb builder.
# It provides basic functionalities to render a breadcrumb navigation according to Bootstrap's conventions.
#
# BootstrapBreadcrumbsBuilder accepts a limited set of options:
# * separator: what should be displayed as a separator between elements
#
# You can use it with the :builder option on render_breadcrumbs:
# <%= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder, :separator => "&raquo;" %>
#
# Note: You may need to adjust the autoload_paths in your config/application.rb file for rails to load this class:
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@otaviomedeiros
otaviomedeiros / alias_matcher.rb
Created March 1, 2012 16:18
RSpec matcher for alias_method
# RSpec matcher for alias_method.
# https://gist.github.com/1950961
# Usage:
#
# describe User do
# it { should alias_from(:username).to(:email) }
# end
RSpec::Matchers.define :alias_from do |alias_method|
@BDQ
BDQ / Import
Created December 3, 2008 21:37
namespace :spree do
desc "Export Products to CSV File"
task :export_products => :environment do
require 'fastercsv'
products = Product.find(:all)
puts "Exporting to #{RAILS_ROOT}/products.csv"
FasterCSV.open("#{RAILS_ROOT}/products.csv", "w") do |csv|
csv << ["id", "name", "description","sku", "master_price" ]