Skip to content

Instantly share code, notes, and snippets.

View anaumov's full-sized avatar
🚀
Looking for an interesting project related to real life.

Alexey Naumov anaumov

🚀
Looking for an interesting project related to real life.
View GitHub Profile
@anaumov
anaumov / gist:73d615dc43d7b3eef298df8355552134
Created August 26, 2020 10:00
Rebase all commits in branch to separate branch after merge to master
git rebase --onto live $(git merge-base --fork-point master) $(git branch --show-current)
{
"checks": [
{
"fd": "81109",
"state": "approved",
"number": "81109",
"date": "2020-08-09",
"actual_draw_date": "2020-08-12",
"prise": "Сертификат на 2000р.",
"prise_slug": "sertificate_2000",
@anaumov
anaumov / us_cities.json
Last active May 19, 2020 14:28
20 biggest US cities with coordinates
[
{
city: "New York",
state: "NY",
latitude: 40.7127837,
longitude: -74.0059413
},
{
city: "Los Angeles",
state: "CA",
@anaumov
anaumov / highlight.sh
Created April 22, 2019 12:14
Highlight JS code for keynote
highlight -O rtf vanilla.js --line-numbers --font-size 24 --font Inconsolata --style solarized-dark -W -J 50 -j 3 --src-lang js | pbcopy
@anaumov
anaumov / traslit.rb
Created March 6, 2019 07:51
Translit с русского на латиницу
class Translit
RU_TO_EN = {
'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e',
'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k',
'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r',
'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'ts',
'ч' => 'ch','ш' => 'sh','щ' => 'sch','ъ' => '','ы' => 'y', 'ь' => '',
'э' => 'je', 'ю' => 'yu', 'я' => 'ya'
}
let!(:user) { create :user }
before do
allow(User).to receive(:find).with(user.id).and_return(user)
end
it 'updates the user' do
expect(user).to receive(:update!).with(name: 'Alex')
post "/users/#{user.id}", params: { name: 'Alex' }
end
let!(:user) { create :user }
it 'updates the user' do
expect_any_instance_of(User).to receive(:update!).with(name: 'Alex')
post "/users/#{user.id}", params: { name: 'Alex' }
end
# http://localhost:3000/users/:id/update
def update
user = User.find(params[:id])
user.update!(name: params[:name])
end
let!(:user) { create :user }
it 'updates the user' do
expect(user).to receive(:update!).with(name: 'Alex')
post "/users/#{user.id}", params: { name: 'Alex' }
end
@anaumov
anaumov / dig.rb
Created October 8, 2018 07:40
Ruby dig example
hash = { user: { name: 'Peter' } }
hash[:user][:name] # => "Peter"
hash = {}
hash[:user][:name] # => NoMethodError: undefined method `[]' for nil:NilClass
hash[:user] && hash[:user][:name] # => "Peter"
{ user: { name: 'Peter' } }.dig(:user, :name) # => "Peter"