Skip to content

Instantly share code, notes, and snippets.

View JanDintel's full-sized avatar

JanDintel

View GitHub Profile
@JanDintel
JanDintel / db_cleaner.rb
Last active December 27, 2015 08:59
RSpec, SpecHelper and DatabaseCleaner (with Capybara and Postgres)
# spec/support/db_cleaner.rb
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
@JanDintel
JanDintel / .zshrc
Created November 5, 2013 12:06
Configure oh-my-zsh ENV file with Rails aliasses
# ~/.zshrc
alias migratetestdb='rake db:migrate RAILS_ENV=test'
alias droptestdb='rake db:drop RAILS_ENV=test; rake db:create RAILS_ENV=test; rake db:migrate RAILS_ENV=test'
alias resettestdb='rake db:reset RAILS_ENV=test'
@JanDintel
JanDintel / factory.rb
Created November 5, 2013 12:10
Factories with `#initialize_with`
# spec/factories/factory.rb
factory :factory_name, class: Klass do
skip_create
ignore do
variable "Hello"
end
initialize_with do
@JanDintel
JanDintel / Preferences.sublime-settings
Last active December 28, 2015 18:49
Sublime 3 User settings
{
"auto_complete_commit_on_tab": false,
"theme": "itg.flat.dark.sublime-theme",
"color_scheme": "Packages/Theme - itg.flat/itg.dark.tmTheme",
"itg_small_tabs": true,
"ensure_newline_at_eof_on_save": true,
"font_size": 12,
"ignored_packages":
[
"Vintage"
@JanDintel
JanDintel / 1_before_example.rb
Last active August 29, 2015 14:06
Virtus: Allow a default value when the attribute is assigned as nil, with the :allow_nil option
require 'virtus'
class Page
include Virtus.model
attribute :title, String
attribute :font, String, :default => 'Helvetica'
attribute :header, String, :default => 'Welcome'
attribute :author, String, :default => 'Mies', :allow_nil => false
end
{"swagger":"2.0","info":{"version":"v0","title":"Test application","description":"Documents the V0 API of the Test application.","contact":{"name":"Jan"},"license":{"name":"MIT"}},"host":"localhost:3000","basePath":"/api/v0","consumes":["application/json"],"produces":["application/json"],"paths":{"/profiles":{"get":{"description":"Finds all Profiles","operationId":"findPets","responses":{"200":{"description":"Profiles response","schema":{"type":"array","items":{"$ref":"#/definitions/Profile"}}}}}},"/profiles/{id}":{"get":{"description":"Finds a Profile","operationId":"findPetById","parameters":[{"name":"id","in":"path","description":"Pseudonym of the Profile","required":true,"type":"string"}],"responses":{"200":{"description":"Profile response","schema":{"$ref":"#/definitions/Profile"}}}}}},"definitions":{"Profile":{"required":["id","type"],"properties":{"id":{"type":"string"},"type":{"type":"string"}}}}}
@JanDintel
JanDintel / cron_ping.rb
Last active July 16, 2020 15:18
Perform a HTTP GET request safely in Ruby, to answer https://twitter.com/mattiasgeniar/status/1283725453065367555
require 'net/http'
def ping(endpoint)
uri = URI.parse(endpoint)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end