Skip to content

Instantly share code, notes, and snippets.

View tagrudev's full-sized avatar

Todor Grudev tagrudev

View GitHub Profile
@tagrudev
tagrudev / gist:5208008
Created March 20, 2013 20:10
import csv to your posgre via rails yolo
require 'csv'
namespace :seed do
desc "seed some awesomeness"
task :awesomeness => :environment do
CSV.foreach(File.join(Rails.root, 'lib/assets/yolo.csv')) do |row|
Awesome.create(:attribute_a => row[0], :attribute_b => row[1])
end
end
end
@tagrudev
tagrudev / gist:5219811
Created March 22, 2013 08:42
get all models Rails
Module.constants.select do |constant_name|
constant = eval constant_name
if not constant.nil? and constant.is_a? Class and constant.superclass == ActiveRecord::Base
constant
end
end
<%= form_for(@project) do |f| %>
<% if f.errors.any? %>
<div id='error_explanation'>
<h2><%= pluralize(f.errors.count, 'error') %>
prohibited this foo from being saved:</h2>
<ul>
<% f.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@tagrudev
tagrudev / gist:5345691
Last active December 16, 2015 00:09
Singleton for a factory inside another's factory traits = No ideas
FactoryGirl.define do
factory :user do
first_name 'John Doe'
last_name 'Doe'
trait :yolo do
first_name 'Spinder'
last_name 'Man'
end
factory :spinder, traits: [:yolo]
end
= resource.comments.each do |comment|
%br
= comment.text
@tagrudev
tagrudev / gist:5371199
Last active December 16, 2015 03:39
Followers/Following
$(document).ready ->
$("#following_option").on "ajax:complete", (evn, data) ->
$("#following_option").html(data.responseText)
@tagrudev
tagrudev / gist:5371797
Last active December 16, 2015 03:39
Conversation Flow // Mongoid
class Conversation
include Mongoid::Document
include Mongoid::Timestamps
has_and_belongs_to_many :participants, :class_name => 'User', inverse_of: :conversations
embeds_many :messages, :class_name => 'Message'
end
private
def play_games
Game.unscoped.where(:state => "active", :start_at.lt => Time.zone.now).each do |game|
game.play
end
end
$(document).ready ->
mapOptions =
center: new google.maps.LatLng(-34.397, 150.644)
zoom: 8
mapTypeId: google.maps.MapTypeId.ROADMAP
map = new google.maps.Map $("#venues_map_canvas").get(0), mapOptions
simple_form_for(@object) do |f|
# this is an input for a name
f.input :name
# i want just an input for an autocompleter that has nothing to do with the @object
f.input