Skip to content

Instantly share code, notes, and snippets.

View mariovisic's full-sized avatar

Mario Visic mariovisic

View GitHub Profile
@mariovisic
mariovisic / frogger.rb
Created September 28, 2022 21:55
Frogger game in Ruby 2D
require 'ruby2d'
GRID_SIZE = 40
# Set the window size
set width: GRID_SIZE * 12
set height: GRID_SIZE * 9
# Create a new shape
frogger = Square.new(
@mariovisic
mariovisic / frogger.rb
Created September 26, 2022 10:31
Simple Frogger game in Ruby 2d
require 'ruby2d'
GRID_SIZE = 80
set width: GRID_SIZE * 12
set height: GRID_SIZE * 9
frogger = Square.new(size: GRID_SIZE, color: 'olive', y: Window.height - GRID_SIZE, x: GRID_SIZE * 4)
trucks = []; boats = []; motorbikes = []; bicycles = []
game_state = :in_progress
@mariovisic
mariovisic / battleship.rb
Last active April 18, 2018 03:24
Battleship game from the study group
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
@mariovisic
mariovisic / ruby_2_3_open_struct.rb
Last active December 31, 2015 05:21
Ruby 2.3 Open Struct
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 01:22
Simple ruby web app benchmarking tool
#!/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 December 23, 2015 19:19
Postgres rails bug testing
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 July 22, 2013 02:10
Rails + PostgreSQL: Converting created at date's in the database to Melbourne time.
-- 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 07:53
wbench test for microlancer.com after async loading web fonts.
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:
t = Thread.new do
pid = fork { raise 'nope' }
Process.waitpid(pid)
end
t.join
@mariovisic
mariovisic / example.bash
Last active December 15, 2015 17:39
Heroku toolbelt in a project with the heroku CLI gem
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.