Skip to content

Instantly share code, notes, and snippets.

View vasilakisfil's full-sized avatar

Filippos Vasilakis vasilakisfil

View GitHub Profile
@vasilakisfil
vasilakisfil / service.js
Created August 17, 2016 15:31
which one should we use ?
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 / user_serializer.rb
Last active September 2, 2016 21:38
How to include only links of relationships in JSONAPI (ActiveModelSerializers gem)
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 / example-ApplicationRoute.js
Last active September 22, 2016 20:18
How to show API errors in Ember
import Ember from 'ember';
import Notify from 'ember-notify';
export default Ember.Route.extend(ApplicationRouteMixin, {
actions: {
error: function (errorObject) {
if (errorObject) {
if (errorObject.status === 401) {
return this.transitionTo('login');
@vasilakisfil
vasilakisfil / .eslintrc
Created April 27, 2017 14:07
eslint defaults..
{
"extends": "airbnb",
"env": {
"browser": true
},
"rules": {
"no-underscore-dangle": 0,
"class-methods-use-this": 0,
"arrow-body-style": 0,
"no-console": 0,
pi@raspberrypi:~ $ crystal
/opt/crystal/embedded/bin/crystal: /lib/arm-linux-gnueabihf/libtinfo.so.5: no version information available (required by /opt/crystal/embedded/bin/crystal)
/opt/crystal/embedded/bin/crystal: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /opt/crystal/embedded/bin/crystal)
@vasilakisfil
vasilakisfil / flash_hash.rb
Created June 1, 2017 11:41
Rails flash improvements
module ActionDispatch
class Flash
class FlashHash
# Returns a hash that includes everything but the given keys.
# hash = { a: true, b: false, c: nil}
# hash.except(:c) # => { a: true, b: false}
# hash # => { a: true, b: false, c: nil}
#
# This is useful for limiting a set of parameters to everything but a few known toggles:
# @person.update(params[:person].except(:admin))
@vasilakisfil
vasilakisfil / file.rb
Created October 4, 2017 12:47
Weird Ruby behavior on private method
class Foobar
def run!
self.foobar = 'test' #doesn't fail?
hey = self.foobar #bang! fails
end
private
attr_accessor :foobar
end
Foobar.new.run!
@vasilakisfil
vasilakisfil / nested_controllers.rb
Created October 24, 2017 16:18
A module for creating UI controllers in Rails
module NestedControllers
CALLBACKS_OPTS = [:filter, :if, :unless, :kind].freeze
#adds the relative paths to controller so you can do `render 'subcontroller/something'`
#instead of `render 'parent_controller/subcontroller/something'`
#(solves 2)
def self.extended(base)
base.prepend_view_path("app/views/#{base.controller_path}/")
end
@vasilakisfil
vasilakisfil / decorators.rb
Last active December 21, 2017 21:04
Decorator strategies battletested. Original script: https://gist.github.com/rbishop/7555357
#ENV: Ruby 2.4.1, a i7-6700HQ CPU, 16GB RAM
require 'benchmark'
require 'delegate'
require 'forwardable'
class Person
def initialize(name)
@name = name
end
// {{ 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' ],