Skip to content

Instantly share code, notes, and snippets.

@bgvo
bgvo / neo4j_on_mac.txt
Created November 29, 2021 11:44
Installing and connecting to Neo4j on Mac
### Install neo4j
brew install neo4j
### Disable auth
code /usr/local/Cellar/neo4j/4.3.7/libexec/conf/neo4j.conf
# uncomment this line:
dbms.security.auth_enabled=false
@bgvo
bgvo / enable-ssl-with-puma-rails.md
Last active August 4, 2021 06:15
Enable local SSL connections using Puma with Rails
@bgvo
bgvo / gist:8a190a5c77aad1d6a64b
Created July 8, 2015 16:14
Find (never-ending) syntax errors (Ruby).

Sometimes a linter is not enough. Trying its best, it will point out to the end of file. That's ok if the file is short enough to go through it and spot it. Hoewever, sometimes that's not the case and the error is not so obvious. It's in these cases where one has to apply other techniques.

Instead of going through all the code line by line, what about using your Text Editor Fold/Unfold? For Sublime Text you have the option of folding different lvels of code.

Consider the following code:

module A
  method one
 end
@bgvo
bgvo / gist:443a2ce15dc34b8f6f50
Created January 15, 2015 17:48
has_many association not working
class User
include Mongoid::Document
has_many :wishlists, class_name: "Item"
end
In rails s:
>> u = User.first
>> u.wishlists.push(Item.first)
@bgvo
bgvo / gist:bb9ac76968cad1c4eddd
Last active August 29, 2015 14:11
Search not working
TEST.JS
db.createCollection("test_index")
db.test_index.ensureIndex({"t.n":"text"})
var mydocs = [
{t: [{language: "english", n: "Mother 1"},{language: "spanish", n: "Madre 1"}]},
{t: [{language: "english", n: "Spreme 1"},{language: "spanish", n: "Edificio 1"}]}
]
db.test_index.insert(mydocs)
@bgvo
bgvo / gist:fdb9b6d521aea9148ddf
Created December 2, 2014 18:06
querying inside foreach
db.ratings.find().forEach(function(doc){
var item = db.items.find({_id: doc.item_id})
var ry = item.detail.ry
})
ITEM
@bgvo
bgvo / skiping
Last active August 29, 2015 14:08
Getting incrementing ranges of data (over a million of docs)
olds = Item.order_by(id: 1).skip(new_batch*10000).limit(10000).not_in(id: set)
olds.each do |doc|
...
end
@bgvo
bgvo / fields_for checkb_ox
Created October 22, 2014 12:05
For some reason it doesn't accept 5 arguments as said in http://apidock.com/rails/v4.0.2/ActionView/Helpers/FormHelper/check_box
<%= form_for @user, url: admin_user_path(@user) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<br>
<%= f.label :email %>
<%= f.text_field :email %>
<br>
<%= f.label :roles %>
<%= f.fields_for :roles do |roles_fb| %>
irb(main):028:0* User.collection
=> #<Moped::Collection:0x007fcb8dafed20 @database=#<Moped::Database:0x007fcb8dafeeb0 @session=<Moped::Session seeds=[<Moped::Node resolved_address="54.74.247.101:63879">] database=gemfeeddb>, @name="gemfeeddb">, @name="users">
irb(main):029:0> User.collection.remove
NoMethodError: undefined method `remove' for #<Moped::Collection:0x007fcb8db07678>
from (irb):29
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rails/commands/console.rb:90:in `start'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rails/commands/console.rb:9:in `start'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:69:in `console'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/borjagvo/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/railties-4.1.4/lib/rail
@bgvo
bgvo / gist:fba173bf0b1ab1f12985
Last active August 29, 2015 14:07
Abstract json rendering outside controller
render json: {
item: {
name: item.name,
kind: item.kind,
details_en: item.details_en
},
rating: item.ratings.where(user_id: @current_user.id)
}