Skip to content

Instantly share code, notes, and snippets.

brew install postgresql
sudo ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
createuser -d -P admin
@bgvo
bgvo / gist:5f49684b5f963b8ce1d6
Created September 12, 2014 07:04
index.hbs (blog theme for Ghost.io)
{{!< default}}
{{> header}}
<main class="main_pixel headline" role="main">
{{#foreach posts}}
<article class="article_pixel" role="article" itemscope itemtype="http://schema.org/Article">
@bgvo
bgvo / 0_reuse_code.js
Last active August 29, 2015 14:06
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
@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)
}
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 / 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| %>
@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 / 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 / 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: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)