Skip to content

Instantly share code, notes, and snippets.

View ArturT's full-sized avatar

Artur Trzop ArturT

View GitHub Profile
@ArturT
ArturT / gist:8804428
Last active August 29, 2015 13:56 — forked from jackdesert/gist:7090731
don't change non DateTime
require 'rails_admin/config/fields/base'
module RailsAdmin
module Config
module Fields
module Types
class Datetime < RailsAdmin::Config::Fields::Base
def value
value_in_default_time_zone = bindings[:object].send(name)
#!/bin/bash
i=0
files=()
# sort spec files by number of examples for better balancing
for file in $(find ./spec -name "*_spec.rb" -print0 | xargs -0 grep -e "^ *(it|specify)" -c | sort -t: -k2,2rn | awk -F":" '{ print $1 }')
do
if [ $(($i % $CIRCLE_NODE_TOTAL)) -eq $CIRCLE_NODE_INDEX ]
then
files+=" $file"
@ArturT
ArturT / gist:f650813c7035cce7dce9
Created January 14, 2015 14:37
Script to stop all docker containers
#!/bin/sh
CONTAINERS=`docker ps -q`
echo $CONTAINERS
if [ "$CONTAINERS" == "" ];
then
echo no running containers
else
echo containers exist, stopping them
@ArturT
ArturT / gist:e4a3ade36c00afa4e6ec
Created April 11, 2015 08:52
Execute rspec until fail to detect random failing spec
while rspec spec/models/user_spec.rb; do :; done
it 'increases to 50 when sell_in above 10 and quality is 49' do
item = Item.new('Backstage passes to a TAFKAL80ETC concert', sell_in=15, quality=49)
items = [item]
gilded_rose = described_class.new(items)
gilded_rose.update_quality
expect(item.quality).to eq 50
end
it 'increases to 50 instead of 51 when sell_in at least 5 and quality is 49' do
@ArturT
ArturT / square_spec.rb
Created September 29, 2015 11:43
Exercise. Create class Square to pass tests or implement tests for the class.
require 'rspec'
class Square
def initialize(x, y)
@x = x
@y = y
end
def area
@x * @y
@ArturT
ArturT / presenters.rb
Created September 30, 2015 12:27
Example of BasePresenter and BaseListPresenter
# BASE PRESENTERS
class BasePresenter
def initialize(item)
@item = item
end
def to_hash
raise NotImplementedError
end
@ArturT
ArturT / attempts.rb
Created November 30, 2015 13:52
Delayed_job: On error, the job is scheduled again in 5 seconds + N ** 4, where N is the number of attempts. https://github.com/collectiveidea/delayed_job
def time(n)
5 + n ** 4
end
total_hours = 0
25.times do |n|
seconds = time(n)
puts "---------- #{n} ---------"
puts "Seconds: #{seconds}"
@ArturT
ArturT / git_remove_tags.rb
Last active December 17, 2015 19:39
Ruby script to remove local and remote unnecessary tags.
# pull all remote tags
Kernel.system "git", "pull", "--tags"
tags = `git tag | xargs`
tags_list = tags.split(' ')
# don't remove below tags
good_tags = %w(1.0.0 1.1.0 1.1.0.1 1.1.0.2 v1.1.0.3 v1.1.0.4 v1.1.0.5 v1.1.0.6)
# those tags will be deleted
@ArturT
ArturT / spec_helper.rb
Last active December 23, 2015 00:58 — forked from terut/spec_helper.rb
Use different directory for carrierwave in test environment and clean up after all
RSpec.configure do |config|
# ...
config.after(:all) do
FileUtils.rm_rf(Dir["#{Rails.root}/tmp/test/carrierwave"])
end
end
CarrierWave.configure do |config|
config.root = "#{Rails.root}/tmp/test/carrierwave"