Skip to content

Instantly share code, notes, and snippets.

@hakunin
hakunin / approach_01_random_ids.rb
Last active November 16, 2016 11:01
Prevent different records with matching IDs from falsely passing tests
# put this inside spec/support/random_ids.rb
# NOTE: this works, but will break tests whee something like Article.last is used
# a more clever approach is used in 02 below
# Some tests may pass when they should have failed
# due to Rails using sequential ids. This allows us
# to fix that by having random ids.
class ActiveRecord::Base
before_create :generate_random_id
@vitskvara
vitskvara / analyza.r
Created November 28, 2015 19:25
datafestak2015_R_workshop
library(stats)
library(forecast)
### DATALOAD ###
# nemocnice
pripady<-read.csv('fnhk_pripady.csv',header=T)
vykony<-read.csv('fnhk_vykony.csv',header=T)
zup<-read.csv('fnhk_zup.csv',header=T)
data_length<-nrow(pripady)
# PSC po okresech
@pixeltrix
pixeltrix / time_vs_datatime.md
Last active February 18, 2024 19:20
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
@leighhalliday
leighhalliday / config.ru
Created February 17, 2015 16:15
Rack Example
# Use:
# This is in file config.ru
# 1) gem install rack
# 2) rackup
# 3) visit http://localhost:9292 in browser
# 4) Timer info will be in console
# 5) when changing code, will have to restart rackup
# Include rack
require 'rack'
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@Integralist
Integralist / Ruby Lambdas.md
Last active August 8, 2023 05:10
Ruby lambdas

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
class GroupersController < ApplicationController::Base
def create
@grouper = Grouper.new(leader: current_member)
if @grouper.save
ConfirmedGrouperEmails.new(@grouper).deliver
AssignBarForGrouper.enqueue(@grouper.id)
redirect_to home_path
else
class GroupersController < ApplicationController::Base
def create
@grouper = Grouper.new(leader: current_member)
if @grouper.save
confirm_grouper_via_emails(@grouper)
enqueue_bar_assignment(@grouper)
redirect_to home_path
else
@jvns
jvns / interview-questions.md
Last active March 5, 2024 19:03
A list of questions you could ask while interviewing

A lot of these are outright stolen from Edward O'Campo-Gooding's list of questions. I really like his list.

I'm having some trouble paring this down to a manageable list of questions -- I realistically want to know all of these things before starting to work at a company, but it's a lot to ask all at once. My current game plan is to pick 6 before an interview and ask those.

I'd love comments and suggestions about any of these.

I've found questions like "do you have smart people? Can I learn a lot at your company?" to be basically totally useless -- everybody will say "yeah, definitely!" and it's hard to learn anything from them. So I'm trying to make all of these questions pretty concrete -- if a team doesn't have an issue tracker, they don't have an issue tracker.

I'm also mostly not asking about principles, but the way things are -- not "do you think code review is important?", but "Does all code get reviewed?".

@pcreux
pcreux / Gemfile
Last active December 11, 2023 20:24
Fast Rails + Heroku Configuration
group :production do
gem 'unicorn'
# Enable gzip compression on heroku, but don't compress images.
gem 'heroku-deflater'
# Heroku injects it if it's not in there already
gem 'rails_12factor'
end