Skip to content

Instantly share code, notes, and snippets.


Filippos Vasilakis vasilakisfil

View GitHub Profile
jingoro / gist:3015664
Created Jun 29, 2012
Mongoid Callback Sequence
View gist:3015664
require 'rubygems'
require 'bundler/setup'
require 'mongoid'
Mongoid.configure do |config|
config.master ='localhost', 27017, :logger => nil).db('mongoid-test')
class A
include Mongoid::Document
d-mart / domain_validator.rb
Created Oct 4, 2012 — forked from rietta/domain_validator.rb
Rails 3 Bare Domain Validator
View domain_validator.rb
# Domain Validator by Frank Rietta
# (C) 2012 Rietta Inc. All Rights Reserved.
# Licensed under terms of the BSD License.
# To use in a validation, add something like this to your model:
# validates :name, :domain => true
class DomainValidator < ActiveModel::EachValidator
henrik /
Last active May 23, 2022
Sandi Metz' four rules from Ruby Rogues episode 87. Listen or read the transcript:
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done. And your view can only know about one instance variable.

You can break these rules if you can talk your pair into agreeing with you.

alex-zige / gist:5795358
Last active Feb 27, 2021
Rails Rspec API Testing Notes
View gist:5795358

Rails Rspec APIs Testing Notes

Folders Structure

  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
mpeteuil / rubocop_pre_commit_hook
Created Aug 3, 2013
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
View rubocop_pre_commit_hook
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
havenwood / arity_range.rb
Last active Aug 29, 2015
Ask a method, lambda or proc for the range of arguments it can be called with from minimum to maximum.
View arity_range.rb
module ArityRange
def arity_range
args = &:first
req = args.count :req
opt = args.include?(:rest) ? Float::INFINITY : args.count(:opt)
keyreq = args.count :keyreq
keyopt = args.include?(:keyrest) ? Float::INFINITY : args.count(:key)
tadast /
Last active Jun 21, 2022 — forked from trcarden/gist:3295935
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
vasilakisfil /
Last active Jun 11, 2020
New linux machine setup
#install essential stuff
sudo apt-get install build-essential autoconf locate
sudo apt-get install git guake zsh curl vim vim-gtk3 postgresql-client \
postgresql postgresql-contrib redis golang direnv tmux bat ripgrep fzf
curl -L | sh
chsh -s /bin/zsh
#edit pg_hba.conf
jvenezia /
Last active Nov 10, 2021
Rails mailer structure

Rails mailer structure

Your application is growing, and you are starting to have a complex mailing system: notification emails, retention emails, misc user emails, admin emails, etc...

It's time to clean up your mailers !

Existing mailer

You may already have a single mailer, responsible of every emails, like this one:

View radio-button-component.js
// {{ radio-button name='dish' value='spam' groupValue=selectedDish selectedAction='testAction' }} Spam
// {{ radio-button name='dish' value='eggs' groupValue=selectedDish }} Eggs
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: [ 'checked', 'name', 'type', 'value' ],