Skip to content

Instantly share code, notes, and snippets.

Avatar

Filippos Vasilakis vasilakisfil

View GitHub Profile
@vasilakisfil
vasilakisfil / .eslintrc
Created Apr 27, 2017
eslint defaults..
View .eslintrc
{
"extends": "airbnb",
"env": {
"browser": true
},
"rules": {
"no-underscore-dangle": 0,
"class-methods-use-this": 0,
"arrow-body-style": 0,
"no-console": 0,
@vasilakisfil
vasilakisfil / test.rb
Created Sep 3, 2016
Ruby calling method performance
View test.rb
require 'benchmark/ips'
class Foo
def bar; end
end
foo = Foo.new
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
@vasilakisfil
vasilakisfil / user_serializer.rb
Last active Sep 2, 2016
How to include only links of relationships in JSONAPI (ActiveModelSerializers gem)
View user_serializer.rb
class Api::V1::UserSerializer < Api::V1::BaseSerializer
type :users
attributes :id, :name
has_many :microposts, serializers: Api::V1::MicropostSerializer do
link :self, '/api/v1/microposts'
end
end
@vasilakisfil
vasilakisfil / service.js
Created Aug 17, 2016
which one should we use ?
View service.js
import Ember from 'ember';
export default Ember.Service.extend({
_observer1: Ember.observer('foobar', function() {
//something here
}).on('init'),
_observer2: Ember.on('init', Ember.observer('foobar', function() {
//something here
}))
});
@vasilakisfil
vasilakisfil / run.rb
Created May 22, 2016
Hack github's contribution history
View run.rb
require 'git'
require 'fileutils'
require 'date'
begin
FileUtils.rm_rf('.git/')
File.delete('myfile.out')
rescue Errno::ENOENT
end
@vasilakisfil
vasilakisfil / reshape_hash.rb
Last active Apr 13, 2016
Having fun with instance_exec in Ruby
View reshape_hash.rb
class Hash
def reshape(binding)
new_hash = self.clone
new_hash.each{|k, v| new_hash[k] = (binding.instance_exec(&(v))) if v.is_a? Proc}
return new_hash
end
end
def foo_method
@vasilakisfil
vasilakisfil / benchmark.rb
Created Mar 30, 2016
Have fun with benchmarking in Ruby
View benchmark.rb
require 'benchmark'
@i=0
def undefined_check
return @undefined_check += 2 if defined?(@undefined_check)
return @i += 1
end
@nil = nil
View rails_mailer_structure.md

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 gist:90197775b06c5909ff65

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
View rspec_api_helper.rb
#rspec/support/rspec_api_helper.rb
module RspecApiHelper
module ExampleMethods
def objectize_resources(json, root: root)
array = []
array_hash = HashWithIndifferentAccess.new(MultiJson.load(json))
if root
array_hash = array_hash[root]
end