Skip to content

Instantly share code, notes, and snippets.

View rubypirate's full-sized avatar
🏠
Working from home

Jamal rubypirate

🏠
Working from home
View GitHub Profile
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
def make_front
object = params[:model].constantize.find(params[:id])
if current_user.admin?
if object.front_page == true || object.front_page == false
front_page = (object.front_page? ? false : true)
object.update_attribute('front_page', front_page)
render :partial => "make_front", :locals => { :object => object, :message => nil }
else
render :partial => "make_front", :locals => { :message => 'can not be set to front-page' }
end
@rubypirate
rubypirate / gist:669883
Created November 9, 2010 21:48
jn helper
def share
link_to_function "Details" do |page|
return %(
<script type="text/javascript">
RPXNOW.loadAndRun(['Social'], function () {
var activity = new RPXNOW.Social.Activity(
"Share your comment",
"commented on 'Like My New Perfume?' on cuteoverload.com",
"http://cuteoverload.com/2009/10/26/like-my-new-perfume/");
RPXNOW.Social.publishActivity(activity);
@rubypirate
rubypirate / gist:669922
Created November 9, 2010 22:11
jn helper
in the view
=====================
<%= link_to_remote 'click', :update => "share",
:url => { :controller=>'blogs', :action=>'share' },
:complete => visual_effect(:highlight, 'share')
%>
The kingdom of <prince surname here>
announces the royal wedding of
the Princess Cinderella
daughter of King <bride's father's first name> and Queen <bride's mother's first name>
to the Prince Charming
of the kingdom of <groom's surname>
son of King <groom's father's first name> and Queen <groom's mother's first name>
at the Royal Palace
King Road
Chelsea
def up package
aws_connect
@href = package.items.where(:kind=>'video').first.urls.first.href
url = "#{@href}?token=#{@token}"
AWS::S3::S3Object.store('new_file_name.mp4', open(url), 'jamal_bucket', access: :public_read)
end
Question.find_by_sql("SELECT t1.* FROM questions t1 LEFT JOIN questions_options t2 ON t1.id = t2.question_id WHERE t2.question_id IS NULL AND t2.user_id != 1")
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
root@alquds:/home/en# RAILS_ENV=production rails s
=> Booting WEBrick
=> Rails 3.2.12 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/local/lib/ruby/1.9.1/psych.rb:203:in `parse': (<unknown>): mapping values are not allowed in this context at line 18 column 7 (Psych::SyntaxError)
from /usr/local/lib/ruby/1.9.1/psych.rb:203:in `parse_stream'
from /usr/local/lib/ruby/1.9.1/psych.rb:151:in `parse'
from /usr/local/lib/ruby/1.9.1/psych.rb:127:in `load'
# this code helps you generate random numbers for euro millions lottery
# how to run, ruby euro_millions.rb
@numbers = []
@stars_numbers = []
cards_num = 100
cards_num.times.each_with_index do |i|
rnum = rand(1..50)
stars_number = rand(1..11)
if @stars_numbers.count < 2