Skip to content

Instantly share code, notes, and snippets.

View ch1ago's full-sized avatar
🏠
Working mostly from home since 2006

Thiago Almeida ch1ago

🏠
Working mostly from home since 2006
  • Mexico City
  • 02:06 (UTC -06:00)
View GitHub Profile
@ch1ago
ch1ago / gist:2368818
Created April 12, 2012 16:24
current_user performance :)
Hey guys, since current_user is a method used in every request I decided to give it a few benchmarks
I'm gisting this so if anyone may find good literature
here was my start point question:
which is best?
(yes this approach doesn't validate an auth token)
def current_user
if session[:user_id]
class Post
def youtube_url=(value)
self.youtube=value.gsub("http://.../","")
end
def youtube_url
youtube
end
end
belongs_to :gift
belongs_to :user
<style>
body {
margin: 0px;
padding: 0px;
}
#myCanvas {
border: 1px solid red;
width: 99.9%;
height: 1000px;
@ch1ago
ch1ago / gist:1887901
Created February 22, 2012 22:23
isntalling gem pg
[user@red ~]$ gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
def link_to_profile_dropdown(user)
link_to "#", :class => "dropdown-toggle", "data-toggle" => "dropdown" do
"#{user.email} <b class='caret'></b>"
end
end
<% module_namespacing do -%>
class <%= controller_class_name %>Controller < ApplicationController
# TODO: name these comments properly with all the matching URLs to each action
# GET <%= route_url %>
def index
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
end
# GET <%= route_url %>/1
<jarr0dsz> im having a @group.participants.order(:id).offset(0).limit(1).first that returns a participant object i checked with .inspect but how do i get an attribute from that?
first_participant = @group.participants.order("id").select("name").first || :no_participant_for_this_group
if first_participant == :no_participant_for_this_group
puts first_participant.name
else
def consent
@user = current_user
if @user.update_attributes(params[:user])#this is really dangerous, I could force my email to change form the form =/
redirect_to :back, notice: "Error updating your user account"
else
flash[:notice] = 'User information updated'
@cart.consent_updated = false
end
end
if
@sentiment["mood"] == positive && @sentiment["prob"] > 0.94
@tag.score = 100
elsif
@sentiment["mood"] == positive && @sentiment["prob"] > 0.89
@tag.score = 96
elsif
@sentiment["mood"] == positive && @sentiment["prob"] > 0.84
@tag.score = 92
elsif