Skip to content

Instantly share code, notes, and snippets.

View sebastianvirlan's full-sized avatar
🎯
Focusing

Sebastian Vîrlan sebastianvirlan

🎯
Focusing
  • Moteefe
  • Manchester
View GitHub Profile
@sebastianvirlan
sebastianvirlan / 0_reuse_code.js
Created February 29, 2016 09:30
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sebastianvirlan
sebastianvirlan / select_options.rb
Last active April 27, 2018 13:57
Generate Options straight from the Model for using them with html select options.
module SelectOptions
extend ActiveSupport::Concern
FIRST_OPTION = %w[All default].freeze
class_methods do
def enum_select_options(enum_name)
define_singleton_method "#{enum_name}_select_options" do |method_params = { header: true }|
map = send(enum_name.to_s.pluralize).map { |k, _| [k.humanize, k]}
@sebastianvirlan
sebastianvirlan / application_helper.rb
Last active April 30, 2018 14:40
Ruby on Rails - Get rid of conditionals on your view
# Imagining a case where you are using loads of conditionals to show different parts of UI.
# There are 2 solutions of what can I see at the moment, either you are creating a different
# view either you fill your view with conditionals.
# index.html.erb - This would be the example where you fill your view with loads of conditionals
<div>
<% if can? :delete, :users %>
<button id="delete_selected">Delete selected</button>
<% end %>
@sebastianvirlan
sebastianvirlan / array.js
Last active December 26, 2018 16:09
Ruby Array Methods in Javascript
/*** Custom RArray class ***/
class RArray extends Array {
// Returns an array containing the items for which the given closure is not true.
reject (callback) {
return this.filter((val) => {
return !callback(val);
});
}