Tuesday, 18 November 2014

rescue

(@lang = Language.find(@user_cookie[:language_id])) rescue @lang, value = find_default_lang_id
view raw gistfile1.rb hosted with ❤ by GitHub

Monday, 17 November 2014

the tbs google param

http://stenevang.wordpress.com/2013/02/22/google-search-url-request-parameters/
// http://jwebnet.net/advancedgooglesearch.html#advDatePeriod
// http://stackoverflow.com/questions/9452169/google-custom-search-refinement-for-newest-results
// &tbs=rltm:1 [real time results]
// &tbs=qdr:s [past second]
// &tbs=qdr:n [past minute]
// &tbs=qdr:h [past hour]
// &tbs=qdr:d [past 24 hours (day)]
// &tbs=qdr:w [past week]
// &tbs=qdr:m [past month]
// &tbs=qdr:y [past year]
// Any time: tbs=qdr:a
// Last second: tbs=qdr:s (Read more about this “real time search” on Lifehacker)
// Last minute: tbs=qdr:n
// Last 10 minutes: tbs=qdr:n10 (and so on for any number of minutes)
// Last hour: tbs=qdr:h
// Last 12 hours: tbs=qdr:h10 (and so on for any number of hours)
// Last day: tbs=qdr:d
// Last week: tbs=qdr:w
// Last month: tbs=qdr:m
// Last year: tbs=qdr:y
// A specific time range, for example from March 2 1984 to June 5 1987: tbs=cdr:1,cd_min:3/2/1984,cd_max:6/5/1987
// Sort by date: tbs=sbd:1
// Sort by relevance: tbs=sbd:0
view raw gistfile1.txt hosted with ❤ by GitHub

Saturday, 15 November 2014

rails 4 none filter

def filter(filter_name)
case filter_name
when :all
scoped
when :published
where(:published => true)
when :unpublished
where(:published => false)
else
none
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Thursday, 13 November 2014

unicode cldr REGIONS AND LANGUAGES

http://unicode.org/repos/cldr/trunk/common/main/
aa
aa_DJ
aa_ER
aa_ET
af
af_NA
af_ZA
agq
agq_CM
ak
ak_GH
am
am_ET
ar
ar_001
ar_AE
ar_BH
ar_DJ
ar_DZ
ar_EG
ar_EH
ar_ER
ar_IL
ar_IQ
ar_JO
ar_KM
ar_KW
ar_LB
ar_LY
ar_MA
ar_MR
ar_OM
ar_PS
ar_QA
ar_SA
ar_SD
ar_SO
ar_SS
ar_SY
ar_TD
ar_TN
ar_YE
as
as_IN
asa
asa_TZ
ast
ast_ES
az
az_Cyrl
az_Cyrl_AZ
az_Latn
az_Latn_AZ
bas
bas_CM
be
be_BY
bem
bem_ZM
bez
bez_TZ
bg
bg_BG
bm
bm_Latn
bm_Latn_ML
bn
bn_BD
bn_IN
bo
bo_CN
bo_IN
br
br_FR
brx
brx_IN
bs
bs_Cyrl
bs_Cyrl_BA
bs_Latn
bs_Latn_BA
ca
ca_AD
ca_ES
ca_ES_VALENCIA
ca_FR
ca_IT
cgg
cgg_UG
chr
chr_US
cs
cs_CZ
cy
cy_GB
da
da_DK
da_GL
dav
dav_KE
de
de_AT
de_BE
de_CH
de_DE
de_LI
de_LU
dje
dje_NE
dsb
dsb_DE
dua
dua_CM
dyo
dyo_SN
dz
dz_BT
ebu
ebu_KE
ee
ee_GH
ee_TG
el
el_CY
el_GR
en
en_001
en_150
en_AG
en_AI
en_AS
en_AU
en_BB
en_BE
en_BM
en_BS
en_BW
en_BZ
en_CA
en_CC
en_CK
en_CM
en_CX
en_DG
en_DM
en_ER
en_FJ
en_FK
en_FM
en_GB
en_GD
en_GG
en_GH
en_GI
en_GM
en_GU
en_GY
en_HK
en_IE
en_IM
en_IN
en_IO
en_JE
en_JM
en_KE
en_KI
en_KN
en_KY
en_LC
en_LR
en_LS
en_MG
en_MH
en_MO
en_MP
en_MS
en_MT
en_MU
en_MW
en_MY
en_NA
en_NF
en_NG
en_NR
en_NU
en_NZ
en_PG
en_PH
en_PK
en_PN
en_PR
en_PW
en_RW
en_SB
en_SC
en_SD
en_SG
en_SH
en_SL
en_SS
en_SX
en_SZ
en_TC
en_TK
en_TO
en_TT
en_TV
en_TZ
en_UG
en_UM
en_US
en_US_POSIX
en_VC
en_VG
en_VI
en_VU
en_WS
en_ZA
en_ZM
en_ZW
eo
eo_001
es
es_419
es_AR
es_BO
es_CL
es_CO
es_CR
es_CU
es_DO
es_EA
es_EC
es_ES
es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ss_SZ
ss_ZA
ssy
ssy_ER
sv
sv_AX
sv_FI
sv_SE
sw
sw_KE
sw_TZ
sw_UG
swc
swc_CD
ta
ta_IN
ta_LK
ta_MY
ta_SG
te
te_IN
teo
teo_KE
teo_UG
th
th_TH
ti
ti_ER
ti_ET
tn
tn_BW
tn_ZA
to
to_TO
tr
tr_CY
tr_TR
ts
ts_ZA
twq
twq_NE
tzm
tzm_Latn
tzm_Latn_MA
ug
ug_Arab
ug_Arab_CN
uk
uk_UA
ur
ur_IN
ur_PK
uz
uz_Arab
uz_Arab_AF
uz_Cyrl
uz_Cyrl_UZ
uz_Latn
uz_Latn_UZ
vai
vai_Latn
vai_Latn_LR
vai_Vaii
vai_Vaii_LR
ve
ve_ZA
vi
vi_VN
vo
vo_001
vun
vun_TZ
wae
wae_CH
xog
xog_UG
yav
yav_CM
yi
yi_001
yo
yo_BJ
yo_NG
zgh
zgh_MA
zh
zh_Hans
zh_Hans_CN
zh_Hans_HK
zh_Hans_MO
zh_Hans_SG
zh_Hant
zh_Hant_HK
zh_Hant_MO
zh_Hant_TW
zu
zu_ZA
view raw gistfile1.txt hosted with ❤ by GitHub

Wednesday, 12 November 2014

start end pagination

_start = @current_page >= 5 ? @current_page -5 : 1
_end = @current_page + 5
@pagination = Array(_start.._end)
view raw gistfile1.rb hosted with ❤ by GitHub

Tuesday, 11 November 2014

remove empty 00 from time

# video_time_to_human("00:05:20")
# => "05:20"
# video_time_to_human("10:05:20")
# => "10:05:20"
def video_time_to_human(time)
time = time.split(":")
time.delete_at(0) if time.first == "00"
time.join(":")
end
view raw gistfile1.rb hosted with ❤ by GitHub

rails enable i18n fallbacks

#in application.rb
#enable fallbacks
config.i18n.fallbacks =[:en]
view raw gistfile1.rb hosted with ❤ by GitHub

Friday, 7 November 2014

IBeacon

https://github.com/AltBeacon/android-beacon-library

http://www.easibeacon.com/doc/
https://github.com/msroot/motion-beacon-example
http://blog.willrax.com/ibeacons-and-rubymotion/
http://buyibeacons.com/

http://estimote.com/
https://github.com/chrishale/proximity-motion
https://teamstrobe.com/2014/02/07/ibeacons-with-rubymotion.html
http://blog.willrax.com/ibeacons-and-rubymotion/
http://en.wikipedia.org/wiki/IBeacon

Monday, 3 November 2014

access helpers from controllers

def update_stats
render json: {
new_users: view_context.number_helper(User.created_today.count),
new_searches: view_context.number_helper(Query.searches_today)
}
end
view raw gistfile1.rb hosted with ❤ by GitHub

rails number_helper

module ApplicationHelper
# make number 123123123 1K
def number_helper(number)
number_to_human(number, :format => '%n%u', :units => { :thousand => 'K' })
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Sunday, 2 November 2014

unicorn on heroku

In  config/unicorn.rb


 
config/unicorn.rb
# With a typical Rails memory footprint, you can expect to run 2-4 Unicorn worker processes.
# https://devcenter.heroku.com/articles/rails-unicorn
# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 1)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
view raw gistfile1.rb hosted with ❤ by GitHub
Procfile

 
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
view raw gistfile1.txt hosted with ❤ by GitHub
Gemfile






 
source 'https://rubygems.org'
ruby '2.1.3'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
gem 'unicorn'
group :production do
gem "rails_12factor"
end
gem "pg"
group :development, :test do
# gem "sqlite3", :require => "sqlite3"
gem "better_errors"
gem "binding_of_caller"
end
gem "faker"
gem "devise"
gem 'simple_form'
gem 'annotate'
gem 'bootstrap-generators', '~> 3.0.2'
gem 'high_voltage'
gem 'will_paginate', '~> 3.0'
gem 'will_paginate-bootstrap'
gem 'groupdate'
gem 'chartkick'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
# gem 'jquery-rails'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
# gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
# gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
# gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
# gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
# gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
view raw gistfile1.txt hosted with ❤ by GitHub
or start on localhost bundle exec unicorn -p 3000

Thursday, 30 October 2014

cloudfront as cdn

http://thediscoblog.com/blog/2013/05/01/the-rails-cloudfront-and-heroku-performance-hat-trick/



https://leanpub.com/cloudfront_rails/read

http://brandonhilkert.com/blog/setting-up-a-cloudfront-cdn-for-rails/

rake cloudinary:sync_static

http://cloudinary.com/blog/how_to_deliver_your_static_images_through_a_cdn_in_ruby_on_rails


TODO:::

If you heard of Cloudinary before, you probably already know how useful Cloudinary is with managing all your dynamically uploaded images, transforming these to their required dimensions and delivering them through a fast CDN.
 
But what about all the static images you have in your web application? background images, buttons, icons - they too should be delivered through a CDN, offloading their delivery from your servers and improving your website's performance.
 
You can always do it yourself - setup your cloud environment, upload all these static images to your cloud storage, access them through a CDN and make sure to update these images when they change. 
 
Or - you can let Cloudinary do it. Automatically.
 
In this post we wanted to introduce a new Cloudinary feature. This feature simplifies and streamlines the process of uploading your static images to the cloud and delivering them through a CDN.
 
If you haven't done so already - upgrade to our latest Ruby GEM and you will enjoy this new feature with zero code change.
 
How is this done? First, upload all your Ruby-on-Rails applications' static images to Cloudinary, using a single Rake command:
rake cloudinary:sync_static
 
images/logo.png - logo-5740ed843b23d0b86e48081f43a45b9c - Uploading
images/icon_rails.png - icon_rails-74dca949999d8f5960aedfed429711ab - Uploading
images/spinner.gif - spinner-3a0ae382485ddcfc5b57e638baa6005f - Uploading
images/background.png - background-339f8567f25075150cca85d711e94b0c - Uploading
 
Completed syncing static resources to Cloudinary
4 Uploaded
This Rake task finds all the images in all common public folders and in Rails Asset Pipeline’s image asset folders. Afterwards, it uploads all new and modified images to Cloudinary. Uploaded images and their versions are maintained using a local .cloudinary.static file. Make sure you commit this file to your source control.
 
Now that you’ve uploaded all your static images to Cloudinary, all you’ve left to do in order to deliver these through a CDN is to edit your cloudinary.yml file and set the following configuration parameters to ‘true’: 
enhance_image_tag: true
static_image_support: true
That's it. No other code changes required. From now on, every image_tag call in your views would automatically check if the image was uploaded to the cloud (using .cloudinary.static) and if so, would generate a remote Cloudinary CDN URL.
 
For example:
<%= image_tag(“logo.png”, :width => 100, :height => 100) %>
May generate the following HTML code:
<img src="http://res.cloudinary.com/demo/image/static/
      logo-5740ed843b23d0b86e48081f43a45b9c" width="100" height="100"/>
Keep in mind that you can activate CDN static image support in your production environment while keeping to local files in your development environment.
 
When you add new static images or change existing ones, all you need to do is re-run ‘rake cloudinary:sync_static’.
rake cloudinary:sync_static
 
images/logo.png - logo-5740ed843b23d0b86e48081f43a45b9c - Not changed
images/icon_rails.png - icon-74dca949999d8f5960aedfed429711ab - Not changed
images/spinner.gif - spinner-3a0ae382485ddcfc5b57e638baa6005f - Not changed
images/background.png - background-339f8567f25075150cca85d711e94b0c - Not changed
images/new_icon.gif - new_icon-50f7c240f43256e3f2bfaa3519dab1e8 - Uploading
 
Completed syncing static resources to Cloudinary
4 Not changed, 1 Uploaded
If your website has many static images, you can optimize your site’s load time further by using multiple CDN subdomains. See this blog post for more details on how to activate this feature.
 

CSS & Sass

The method described above is a powerful way for uploading all static images embedded in your Rails view to the cloud and delivering them through a CDN with no change to your code.
But what about images defined in your CSS or Sass files?
 
If you use the new Asset Pipeline (Rails 3.1+), this would work out-of-the-box. All image-pathand image-url in your Sass files would automatically change to remote Cloudinary CDN URLs. For example:
Sass:
.logo
    background-image: image-url("logo.png")
Generated CSS:
.logo { background-image: url(http://res.cloudinary.com/demo/image/static/logo-5740ed843b23d0b86e48081f43a45b9c) }
So if you already use Asset Pipeline and Sass files, your images will automatically be delivered through a CDN.
 

Transforming static images

One of Cloudinary's major strengths is in its powerful image transformations. In most cases, you'll want your static images displayed as-is. But occasionally, applying transformations on your static images can be very useful. For example, displaying a set of icons in multiple dimensions. Another example is when you want to support Responsive Layout and Images. In this case, adjusting the size of all static images according to your visitors' device resolution might greatly improve your visitors' experience (e.g., resize all images to 50% their original size). 
 
With Cloudinary you can apply many transformations on your static images, with ease.
 
In the following example, we take a 100x100 static logo.png image and resize it on-the-fly to a 50x50 image with rounded corners of 10 pixels radius. The following image_tag:
<%= image_tag("icon_rails.png", :width => 50, :height => 50,
              :crop => :scale, :radius => 10) %>
 
Will generate the following URL:
<img width="50" height="50"
  src="http://res.cloudinary.com/cloudinary/image/asset/
  c_scale,h_50,r_10,w_50/icon_rails-74dca949999d8f5960aedfed429711ab.png"/>
Changing the look & feel and dimensions of images in your site based on the user’s device can be done using CSS instead of changing your code. This can be be made even simpler if you are using Sass in your Rails project. Simply use the 'cloudinary-url' template method. It will convert image references to remote Cloudinary CDN URLs and can also receive all supported transformation parameters.
 
For example, the following Sass line would generate the same 50x50 scaled logo with rounded corners, via Sass:
background-image: cloudinary-url("rails.png", $width: 50, $height: 50,
                                 $crop: "scale", $radius: 10);
To summarize - if you are using Cloudinary for managing and transforming your uploaded images, you should definitely follow the simple instructions above to immediately experience the performance boost gained by delivering all your static assets through Cloudinary. Don’t have a Cloudinary account yet? Click here to setup a free account in seconds.

Tuesday, 28 October 2014

rescue InvalidTextRepresentation ActiveRecord::StatementInvalid

def partner_exist(id)
begin
Partner.find(id)
rescue PG::InvalidTextRepresentation
rescue ActiveRecord::StatementInvalid
false
end
end
view raw gistfile1.rb hosted with ❤ by GitHub

Rails 4 uuid

http://blog.crowdint.com/2013/10/09/using-postgres-uuids-as-primary-keys-on-rails.html


Rails 4 out-of-the-box is that you don't need to include the ActiveUUID::UUID module in the models and when you create the migration, instead of using id: false you would use id: :uuid:
    class CreateStories < ActiveRecord::Migration
      def change
        create_table :stories, id: :uuid do |t|
          # To handle the relationship with the authors table
          t.uuid :author_id

          t.timestamps
        end
      end
    end
Use  postgresapp  http://postgresapp.com/


and enable extension

Select db and

CREATE EXTENSION "uuid-ossp";

In migration use

    create_table :partners, id: :uuid do |t|
      #  To handle the relationship with the authors table
      #t.uuid :author_id
    end

Monday, 20 October 2014

Να μάθεις να φεύγεις

Από την ασφάλεια τρύπιων αγκαλιών
Από χειραψίες που σε στοιχειώνουν

Από την ανάμνηση μιας κάλπικης ευτυχίας
Να φεύγεις  - αθόρυβα, σιωπηλά, χωρίς κραυγές, μακρόσυρτους αποχαιρετισμούς

Να μην παίρνεις τίποτα μαζί, ούτε ενθύμια, ούτε ζακέτες για το δρόμο
Να τρέχεις μακρυά από δήθεν καταφύγια κι ας έχει έξω και χαλάζι

Να μάθεις να κοιτάς βαθιά στα μάτια όταν λες αντίο κι όχι κάτω ή το άπειρο
Να εννοείς τις λέξεις σου, μην τις εξευτελίζεις, σε παρακαλώ

Να μάθεις να κοιτάς την κλεψύδρα, να βλέπεις πως ο χρόνος σου τελείωσε

Όχι αγκαλιές, γράμματα, αφιερώσεις, κάποτε θα ξανασυναντηθούμε αγάπη μου
(Όλα τα βράδια και τα τραγούδια δεν θα είναι ποτέ δικά σας - αποδέξου το)

Να σταματήσεις να αγαπάς τον Μέλλοντα, όταν αυτό που έχεις είναι μόνο ο Ενεστώτας
Να φεύγεις από εκεί που δεν ξέρεις γιατί βρίσκεσαι - από 'κει που δεν ξέρουν γιατί σε κρατάνε

Να αποχωρίζεσαι τραγούδια που αγάπησες, μέρη που περπάτησες
Δεν έχεις τόση περιορισμένη φαντασία όσο νομίζεις

Μπορείς να φτιάξεις ιστορίες ολοκαίνουριες, με ουρανό κι αλάτι
Να θυμίζουν λίγο φθινόπωρο, πολύ καλοκαίρι κι εκείνη την απέραντη Άνοιξη

Να φεύγεις από εκεί που δε σου δίνουν αυτά που χρειάζεσαι
Από το δυσανάλογο, το μέτριο και το λίγο

Να απαιτείς αυτό που δίνεις να το παίρνεις πίσω - δεν τους το χρωτάς
Να μάθεις να σέβεσαι την αγάπη σου, το χρόνο σου και την καρδιά σου

Μην πιστεύεις αυτά που λένε - η αγάπη δεν είναι ανεξάντλητη, τελειώνει
Η καρδιά χαλάει, θα τη χτυπάς μια μέρα και δεν θα δουλεύει

Να μην συγχωρείς όσους δεν σου έπλυναν τα πόδια σου με δάκρυα μετανοίας
Να καταλάβεις πως οι δεύτερες ευκαιρίες είναι για τους δειλούς, οι τρίτες για τους γελοίους

Μην τρέμεις την αντιστοιχία λέξεων-εννοιών, να ονομάζεις σχέση την σχέση την κοροϊδία κοροϊδία
Να μαλώνεις τον εαυτό σου καμιά φορά που κάθεται και κλαψουρίζει σαν μωρό
κι εσύ κάθεσαι και του δίνεις γλυφιτζούρι μη και σου στεναχωρηθεί το βυζανιάρικο

Να μάθεις να ψάχνεις για αγάπες που θυμίζουν Καζαμπλάνκα, όχι συμβάσεις ορισμένου χρόνου
Και. Να μάθεις να φεύγεις. Από εκεί που ποτέ πραγματικά δεν υπήρξες

Να φεύγεις κι ας μοιάζει να σου ξεριζώνουν το παιδί από τη μήτρα
Να φεύγεις από όσα νόμισες γι' αληθινά, μήπως φτάσεις κάποτε σ' αυτά

Saturday, 18 October 2014

Τι θα έκανες αν ξυπνούσες ένα πρωί και ήσουνα 30 χρόνια νεότερος

45 παράξενες αλήθειες της ζωής

1. Η ζωή δεν είναι δίκαιη, αλλά ακόμα κι έτσι είναι ωραία.

2. Όταν αμφιβάλλεις για κάτι, απλά κάνε το επόμενο μικρότερο βήμα.

3. Η ζωή είναι πολύ μικρή για να χάνεις χρόνο μισώντας τον οποιονδήποτε.

4. Αν αρρωστήσεις, δε θα σε κοιτάξει η δουλειά σου. Θα σε κοιτάξουν οι φίλοι και η οικογένειά σου. Μη χάνεσαι.

5. Πλήρωνε τις πιστωτικές σου κάθε μήνα.

6. Δε χρειάζεται να κερδίζεις σε κάθε διαφωνία. Συμφώνησε με το να διαφωνείς.

7. Κλάψε παρέα με κάποιον. Είναι πιο εύκολο να συνέλθεις απ' το να κλαις μόνος.

8. Δεν πειράζει να θυμώνεις.

9. Βάζε στην άκρη για τη σύνταξή σου από τον πρώτο σου μισθό.

10. Απέναντι στη σοκολάτα κάθε αντίσταση είναι μάταιη.

11. Συμφιλιώσου με το παρελθόν σου για να μην καταστρέφεις το παρόν σου.

12. Δεν πειράζει αν σε δουν τα παιδιά σου να κλαις. Άφησέ τα να το κάνουν.

13. Μην συγκρίνεις τη ζωή σου με των άλλων. Δεν έχεις ιδέα τι νόημα μπορεί να έχει το δικό τους το ταξίδι.

14. Αν μια σχέση πρέπει να κρατιέται μυστική, τότε δεν πρέπει να την κρατάς εσύ.

15. Τα πάντα μπορεί να αλλάξουν μ' ένα ανοιγοκλείσιμο των ματιών. Αλλά μην ανησυχείς. Ο Θεός δεν τρεμοπαίζει τα βλέφαρά του.

16. Πάρε μια βαθιά ανάσα. Ηρεμεί το μυαλό.

17. Ξεφορτώσου ό,τι δεν είναι χρήσιμο, όμορφο ή γεμάτο χαρά.

18. Ό,τι δε σε σκοτώνει πράγματι σε κάνει δυνατότερο.

19. Ποτέ δεν είναι αργά για να έχεις μια ευτυχισμένη παιδική ηλικία. Αλλά τη δεύτερη φορά εξαρτάται από σένα.

20. Όταν είναι να κυνηγήσεις αυτά που αγαπάς στη ζωή, μη δεχτείς ποτέ το όχι.

21. Άναψε τα κεριά, στρώσε τα καλά σεντόνια, φόρεσε τα ακριβά εσώρουχα. Μην τα φυλάς για ειδικές περιπτώσεις. Κάθε μέρα είναι ειδική περίπτωση.

22. Προετοιμάσου για όλα. Και μετά ακολούθησε το ρεύμα.

23. Γίνε εκκεντρικός τώρα. Μην περιμένεις να πάρεις σύνταξη για να φορέσεις μωβ χρώμα!

24. To πιο σημαντικό σεξουαλικό όργανο είναι το μυαλό.

25. Σε κάθε αποκαλούμενη «καταστροφή» σκέψου: «Σε 5 χρόνια, αυτό θα έχει καμία σημασία;».

26. Πάντα να επιλέγεις τη ζωή.

27. Συγχώρησε σε όλους τα πάντα.

28. Το τι πιστεύουν οι άλλοι για σένα, δεν είναι δική σου δουλειά.

29. Ο χρόνος θεραπεύει σχεδόν τα πάντα. Δώσε χρόνο στο χρόνο.

30. Όσο καλή ή κακή κι αν είναι μια κατάσταση, θα αλλάξει.

31. Μην παίρνεις τον εαυτό σου τόσο στα σοβαρά. Κανείς άλλος δεν το κάνει.

32. Πίστευε στα θαύματα.

33. Ο Θεός σ' αγαπάει επειδή είσαι αυτός που είσαι, όχι για κάτι που έκανες ή δεν έκανες.

34. Μην παρακολουθείς τη ζωή. Βγες μπροστά και εκμεταλλεύσου την πλήρως τώρα.

35. Το να γερνάς είναι καλύτερο από την εναλλακτική λύση: να πεθαίνεις νέος.

36. Τα παιδιά σου θα ζήσουν μόνο μία παιδική ζωή.

37. Το μόνο που έχει σημασία τελικά είναι ό,τι αγάπησες.

38. Βγες έξω κάθε μέρα. Τα θαύματα παραμονεύουν παντού.

39. Αν όλοι ρίχναμε τα προβλήματά μας σε ένα σωρό δίπλα - δίπλα, θα αρπάζαμε τα δικά μας πίσω.

40. Η ζήλια είναι χάσιμο χρόνου. Έχεις ήδη όλα όσα χρειάζεσαι.

41. Τα καλύτερα έπονται.

42. Ό,τι διάθεση και να έχεις, σήκω, ντύσου και πήγαινε εκεί που έχεις να πας.

43. Να ενδίδεις.

44. Η ζωή δεν είναι τυλιγμένη με κορδέλα, δεν παύει όμως να είναι δώρο.

45. Κανείς δεν είναι υπεύθυνος για την ευτυχία σου παρά μόνο εσύ.

lifo.gr/lifoland/you-send-it/54275

Wednesday, 20 August 2014

παωτοοο

# χρόνος που λεπτό δε χάνει
# πέρασε με σενα Johnny k sunny
# το ονομα σου αυτό το καλλιτεχνικό
# μα εγω όλο σου λέω παωτοοο
# κ εμένα λες μαρδέλλη
# η κοτόπουλο, η μωρελι
# το σουβλάκι σου αρέσει
# μα στα χέρια σου αν πέσει
# συνταγη σαν της μαμάς
# θα τη φτιάξεις μονομιάς
# οτι φτιάξεις θα το φάω
# και οταν μονη περπατάω
# και τα παπουτσια μου χαλάω
# καποιο αστειο που χεις πει
# στο μυαλό μου θα μου ρθει
# κ οταν το δικό σου τρέχει με χιλιόμετρα πολλά
# κάποια ιδέα θα κατεβαζεις κ θα κλαις από χαρα
# θα γελάω κ θα σαι πάντα το καλο μου το σουβλάκι
# ειναι που έσβησα κεράκι
# απο τουρτα σαν μουστάκι
view raw gistfile1.rb hosted with ❤ by GitHub

Wednesday, 13 August 2014

extract_options

def options(*args)
args.extract_options!
end
options(1, 2) # => {}
options(1, 2, :a => :b) # => {:a=>:b}
# Use args with the splat operation to allow
# an unlimited number of parameters
def my_method(*args)
options = args.extract_options!
puts "Arguments: #{args.inspect}"
puts "Options: #{options.inspect}"
end
my_method(1, 2)
# Arguments: [1, 2]
# Options: {}
my_method(1, 2, :a => :b)
# Arguments: [1, 2]
# Options: {:a=>:b}
#http://simonecarletti.com/blog/2009/09/inside-ruby-on-rails-extract_options-from-arrays/
view raw gistfile1.rb hosted with ❤ by GitHub

Monday, 11 August 2014

Collection Proxy

require "delegate"
class CollectionProxy
def products
@products ||= HasManyAssociation.new([])
@products.associated_class ||= Product
@products
end
end
class Product
def initialize(attributes)
@attributes = attributes
end
attr_reader :attributes
def name
attributes[:name]
end
end
# -----------------------------------------------------------
# With DelegateClass
# -----------------------------------------------------------
class HasManyAssociation < DelegateClass(Array)
attr_accessor :associated_class
def initialize(array)
super(array)
end
def create(params)
self << associated_class.new(params)
end
end
proxy = CollectionProxy.new
products = proxy.products
products.create(:name => 'products one')
products.create(:name => 'products two')
p products[0].name
p products[1].name
p products.map { |q| q.name }
# -----------------------------------------------------------
# with method_missing
# -----------------------------------------------------------
class HasManyAssociation < BasicObject
attr_accessor :associated_class
def initialize(array)
@array = array
end
def create(params)
self << associated_class.new(params)
end
def method_missing(*a, &b)
@array.send(*a, &b)
end
end
proxy = CollectionProxy.new
products = proxy.products
products.create(:name => 'products one')
products.create(:name => 'products two')
p products.map { |q| q.name }
view raw gistfile1.rb hosted with ❤ by GitHub

Proxy

http://blog.rubybestpractices.com/posts/gregory/060-issue-26-structural-design-patterns.html




Proxy

Proxy is any object that acts as a drop-in replacement object that does a bit of work and then delegates to some other underlying object. This is another pattern that’s easy to recognize for Rails developers, because it is used extensively in ActiveRecord associations support. The following example shows a typical interaction between a base model and one of its associations.
  1. quiz = Quiz.first  
  2. quiz.questions.class #=> Array  
  3.   
  4. quiz.questions.count #=> 10  
  5.   
  6. quiz.questions.create(:question_text => "Who is the creator of Ruby?",  
  7.                       :answer        => "Matz")  
  8.   
  9. quiz.questions.count #=> 11  
  10.   
  11. quiz.questions[-1].answer #=> "Matz"   
While the questions association claims to be an array, it also provides some of the common helpers found in ActiveRecord::Base. If we stick to the core idea and ignore some of the Rails specific details, creating such an association proxy is fairly easy to do using Ruby’s delegate standard library. The code below more or less does the trick.
  1. require "delegate"  
  2.   
  3. class Quiz  
  4.   def questions  
  5.     @questions                  ||= HasManyAssociation.new([])  
  6.     @questions.associated_class ||= Question  
  7.   
  8.     @questions  
  9.   end  
  10. end  
  11.   
  12. class Question  
  13.   def initialize(params)  
  14.     @params = params  
  15.   end  
  16.   
  17.   attr_reader :params  
  18.   
  19.   def answer  
  20.     params[:answer]  
  21.   end  
  22. end  
  23.   
  24. class HasManyAssociation < DelegateClass(Array)  
  25.   attr_accessor :associated_class  
  26.   
  27.   def initialize(array)  
  28.     super(array)  
  29.   end  
  30.   
  31.   def create(params)  
  32.     self << associated_class.new(params)  
  33.   end  
  34. end  
  35.   
  36. quiz = Quiz.new  
  37.   
  38. # grab the proxy object  
  39. questions = quiz.questions  
  40.   
  41.   
  42. # use custom create() method on proxy object  
  43.   
  44. questions.create(:question_text => "Who is the creator of Ruby?",  
  45.                  :answer        => "Matz")  
  46. questions.create(:question_text => "Who is the creator of Perl?",  
  47.                  :answer        => "Larry Wall")  
  48.   
  49.   
  50. # use array like behavior on proxy object  
  51.   
  52. p questions[0].answer #=> "Matz"  
  53. p questions[1].answer #=> "Larry Wall"  
  54. p questions.map { |q| q.answer }.join(", "#=> "Matz, Larry Wall"  
Interestingly enough, while Ruby provides a standard library for building Proxy objects, most people tend to implement them in a different way, through the use of an explicitmethod_missing() hook on a blank slate object such as Ruby 1.9’s BasicObject. For example, we could have written our HasManyAssociation code in the manner shown below and things would still work as expected.
  1. class HasManyAssociation < BasicObject  
  2.   attr_accessor :associated_class  
  3.   
  4.   def initialize(array)  
  5.     @array = array  
  6.   end  
  7.   
  8.   def create(params)  
  9.     self << associated_class.new(params)  
  10.   end  
  11.   
  12.   def method_missing(*a, &b)  
  13.     @array.send(*a, &b)  
  14.   end  
  15. end  
Without looking at the source, I’m almost sure that Rails does something similar to this, because doing some_association.class returns Array rather than the name of the proxy object. This is the only noticeable difference on the surface between this approach and the DelegateClass approach.
Personally, I’ve written proxies in both ways, and I tend to prefer the DelegateClass()approach slightly, simply because it’s more explicit and doesn’t require me to explicitly define amethod_missing() hook. But on the other hand, we can see that rolling your own proxy implementation is trivial in Ruby, and some may prefer the self contained nature of doing the delegation work yourself. It’d be interesting to hear what readers have to say on this topic, so please feel free to post to the mailing list if you prefer one approach over the other.