Skip to content

Instantly share code, notes, and snippets.

Mario Visic mariovisic

Block or report user

Report or block mariovisic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mariovisic
mariovisic / battleship.rb
Last active Apr 18, 2018
Battleship game from the study group
View battleship.rb
class Game
attr_reader :player_one, :player_two, :board_one
def initialize(name_one, name_two)
@player_one = Player.new(name_one)
@player_two = Player.new(name_two)
@board_one = Board.new
end
end
View ruby_2_3_open_struct.rb
class Ruby23OpenStructPatched
# :nodoc:
class << self
alias allocate new
end
#
# Creates a new OpenStruct object. By default, the resulting OpenStruct
# object will have no attributes.
#
@mariovisic
mariovisic / ruby_web_app_benchmark
Created May 23, 2014
Simple ruby web app benchmarking tool
View ruby_web_app_benchmark
#!/usr/bin/env sh
website="http://studio.envato.com"
while [ 1 ]
do
time=$(curl -s -I $website | Grep Runtime | awk '{ print $2}')
printf "\rApp response: %.0fms " $(echo "$time * 1000" | tr -d $'\r' | bc)
sleep 0.25
done
@mariovisic
mariovisic / postgres_rails_check.rb
Last active Dec 23, 2015
Postgres rails bug testing
View postgres_rails_check.rb
model = User # For the test we just need any active record model that has a created_at timestamp.
puts %{
==========================
Bug present?: #{model.where('created_at > ?', model.last.created_at).any?}
Ruby: #{RUBY_DESCRIPTION}
Raw SQL: #{ActiveRecord::Base.connection.execute(model.where('created_at > ?', Time.at(model.last.created_at.to_i)).to_sql).to_a.first['created_at']}
AR Timestamp: #{model.last.created_at.to_f}
Rails: #{Rails.version}
@mariovisic
mariovisic / timezone_convert.sql
Created Jul 22, 2013
Rails + PostgreSQL: Converting created at date's in the database to Melbourne time.
View timezone_convert.sql
-- Rails doesn't actually store timestamps in the database as UTC, it actually
-- stores them without any timezone information in the database (but in UTC
-- time). Which means that to convert a timestamp to another timezone we
-- first need to cast the timestamp to a timestamp that's in UTC and then
-- convert to the timezone we actually want. Melbourne in this case.
SELECT
TO_CHAR(((created_at AT TIME ZONE 'UTC') AT TIME ZONE 'Australia/Melbourne')::date, 'YYYY-MM-DD') AS "Day",
FROM jobs
GROUP BY "Day";
@mariovisic
mariovisic / microlancer_wbench.txt
Created May 20, 2013
wbench test for microlancer.com after async loading web fonts.
View microlancer_wbench.txt
Testing http://www.microlancer.com/
At Mon May 20 17:52:07 2013
10 loops
Fastest Median Slowest Std Dev
---------------------------------------------------------------------------
Server performance:
Total application time 71ms 115ms 482ms 121ms
Host latency:
View thred_hang.rb
t = Thread.new do
pid = fork { raise 'nope' }
Process.waitpid(pid)
end
t.join
@mariovisic
mariovisic / example.bash
Last active Dec 15, 2015
Heroku toolbelt in a project with the heroku CLI gem
View example.bash
mario:~/Work/microlancer (master) $ heroku --version
heroku-toolbelt/2.36.1 (x86_64-darwin12.2.0) ruby/2.0.0
mario:~/Work/microlancer (master) $ gem list | grep heroku
heroku-api (0.3.9)
# Login says it was successful but then I cannot run commands
mario:~/Work/microlancer (master) $ heroku login
Authentication successful.
@mariovisic
mariovisic / factory_girl.rb
Created Mar 22, 2013
Do not allow Factory Girl usage in unit tests.
View factory_girl.rb
# spec/support/factory_girl.rb
# This file is here to limit the use of factories to only integration tests and not unit tests.
#
# If you really want to use a factory you can add the tag :factories to a test
#
module FactoryGirlBlocker
mattr_accessor :disabled
def self.with_disabled
self.disabled = true
View session_store.rb
SSOServer::Application.config.session_store :active_record_store
ActiveRecord::SessionStore.session_class = UserSessionStore
You can’t perform that action at this time.