Skip to content

Instantly share code, notes, and snippets.

require 'cli_spinnable'
module Cli
extend CliSpinnable
end
puts 'HAPPY RUN (should succeed):'
Cli.with_spinner do |cli|
cli.print 'Downloading something'
sleep 1
CliSpinnable.with_spinner do |cli|
cli.print('Text') #=> / Text
cli.tick #=> ✓ Text
cli.fail #=> × Text
1 / 0 #=> × Text # exceptions raised within the block also triggers printing fail mark
end
class Foo
include CliSpinnable
def call
with_spinner do |cli|
#...
end
end
end
# Step 1. Obtain token
curl -X POST \
-F "client_id=b6394b15282889398719c67983594d20" \
-F "client_secret=4aee41059af4d350a6ead3a285f0c438de146857d4134b6e63d5b1291971b12f" \
-F "grant_type=client_credentials" \
-F "scope=write_partner_users" \
'https://berlin.staging.wimdu.com/api/v3/oauth/token'
# Step 2. Create user.
# fill out <token> (obtained in Step.1)
@maicher
maicher / container.rb
Last active February 3, 2017 14:07
Container pattern
module Container
# Initialized once (kind'a singleton)
def self.a
@a ||= Object.new
end
# Initialized every time.
def self.b
Object.new
end
@maicher
maicher / print_translations.rb
Created May 12, 2017 15:37
Script for generating translation hash. For passing I18n translations to frontend.
def print_translations(hash, phrase_key, i = 0)
hash.each do |k, v|
if v.is_a?(Hash)
i.times { print ' ' }
print "#{k.to_s.camelize(:lower)}: {\n";
print_translations(v, "#{phrase_key}.#{k}", i + 1)
i.times { print ' ' }
print "},\n"
else i.times { print ' ' }
print "#{k.to_s.camelize(:lower)}: t('#{phrase_key}.#{k}'),\n"
@maicher
maicher / git
Last active June 14, 2017 13:44
Some useful git commands
# Managing own fork
### Configure upstream
git remote -v
git remote add upstream git@github.com:wimdu/wimdu.git
### Syncing to upstream
git checkout master
git fetch upstream master
git reset --hard upstream/master
@maicher
maicher / cache_proposal.md
Last active December 13, 2017 12:08
My proposal for implementing caching in OfferProvider componenet

Caching in OfferProvider

  • Why? - To improve performance (that is not call db an each provider request).
  • Where? - At the point of fething data from OfferProvider component (repositories).
  • How? - By using Rails.cache#fetch

Introduction

Why we don't like caching?

@maicher
maicher / sequence_diagrams_01.rb
Created February 1, 2018 11:22
Sequence diagrams
class A
def call
# do something
end
end
class B
def call(argument)
# do something different
end
class CreateUser
class Error < StandardError; end
# ...
end
# contoller
begin
user = CreateUser.new(params).call
p "User #{user.username} created succesfully"