Skip to content

Instantly share code, notes, and snippets.

View rdavila's full-sized avatar

Rubén Dávila Santos rdavila

View GitHub Profile
https://drive.google.com/file/d/1PUrtICphMlDtr9kCIBodir8cN44jODeY/view?usp=drivesdk
https://drive.google.com/file/d/1PUrtICphMlDtr9kCIBodir8cN44jODeY/uc?usp=drivesdk
result = Hash.new(0)
result[:foo] += 1
p result # I get { :foo => 1 } good.
result = Hash.new([])
result[:foo] << 1
p result # I get {} instead of { :foo => [1] }
@rdavila
rdavila / eval_file.vim
Last active October 5, 2015 02:27
Vimscript function to eval the contents of the current file or only the selected lines based on file extension
function! GetSelectedLines(type, ...) range
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
if a:type == 'n'
silent exe a:firstline . "," . a:lastline . "y"
elseif a:type == 'c'
silent exe a:1 . "," . a:2 . "y"
else
silent exe "normal! `<" . a:type . "`>y"
class A
attr_accessor :foo
def ==(other)
other.is_a?(B) && self.foo == other.foo
end
end
class B
attr_accessor :foo
def console_prices=(values)
values.each do |console_id, price|
self.classifications.build(console_id: console_id, price: price) if price.present?
end
end
= form_for :game do |f|
%p
= f.label :name
= f.text_field :name
%p
- @consoles.each do |console|
= console.name
= text_field_tag "game[console_prices][#{console.id}]"
@rdavila
rdavila / Fancy File Inputs.js
Created October 14, 2012 02:28 — forked from davist11/Fancy File Inputs.js
Fancy File Inputs
var SITE = SITE || {};
SITE.fileInputs = function() {
var $this = $(this),
$val = $this.val(),
valArray = $val.split('\\'),
newVal = valArray[valArray.length-1],
$button = $this.siblings('.button'),
$fakeFile = $this.siblings('.file-holder');
if(newVal !== '') {
class Admin.Routers.Menus extends Backbone.Router
routes:
'': 'fetchData'
fetchData: ->
Admin.Collections.MenuCategories.fetch
success: (col, resp) ->
names = col.pluck('name')
$("#menu_menu_category_id").autocomplete(data: names)
Menus.prototype.fetchData = function() {
var names;
Admin.Collections.MenuCategories.fetch();
names = Admin.Collections.MenuCategories.pluck('name');
$("#menu_menu_category_id").autocomplete({
data: names
});
return names;
};
class Admin.Routers.Menus extends Backbone.Router
routes:
'': 'fetchData'
fetchData: ->
Admin.Collections.MenuCategories.fetch()
$("#menu_menu_category_id").autocomplete
data: Admin.Collections.MenuCategories.pluck('name')