Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Sebastian Vîrlan sebastianvirlan

🎯
Focusing
  • BBC
  • Manchester
View GitHub Profile
@sebastianvirlan
sebastianvirlan / array.js
Last active Dec 26, 2018
Ruby Array Methods in Javascript
View array.js
/*** 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);
});
}
@sebastianvirlan
sebastianvirlan / application_helper.rb
Last active Apr 30, 2018
Ruby on Rails - Get rid of conditionals on your view
View application_helper.rb
# 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 / select_options.rb
Last active Apr 27, 2018
Generate Options straight from the Model for using them with html select options.
View select_options.rb
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 / 0_reuse_code.js
Created Feb 29, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
You can’t perform that action at this time.