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

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