Thursday, April 17, 2014
Block Procs Lambdas map&:(to_s) &:
How &: works? if it is a method, and where is it defined?
> It is rails addition to ruby obviously.
http://caboo.se/doc/classes/Symbol.html#M003931
Symbol#to_proc
This is tricky thing to document. It exploits a ruby syntax quirk where
prepending a & to a method argument calls "to_proc" on that object in an
attempt to make it eligible to be a block.
v.map(&:to_s)
Is the same as:
v.map { |i| i.to_s }
https://www.ruby-forum.com/topic/154453
http://www.reactive.io/tips/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
Wednesday, April 16, 2014
algorithms
Algorithm - a small procedure that solves a recurrent problem.
What is a computer algorithm?
To make a computer do anything, you have to write a computer program. To write a computer program, you have to tell the computer, step by step, exactly what you want it to do. The computer then "executes" the program, following each step mechanically, to accomplish the end goal.
When you are telling the computer what to do, you also get to choose how it's going to do it. That's where computer algorithms come in. The algorithm is the basic technique used to get the job done. Let's follow an example to help get an understanding of the algorithm concept.
Let's say that you have a friend arriving at the airport, and your friend needs to get from the airport to your house. Here are four different algorithms that you might give your friend for getting to your home:
The taxi algorithm:
- Go to the taxi stand.
- Get in a taxi.
- Give the driver my address.
http://algorithms.openmymind.net/
Top 10 Algorithms for Coding Interview
Videos
http://www.computerscienceforeveryone.com/Course_1/Unit_13/Lesson_1/
http://www.scifac.ru.ac.za/javabook/ch02.htm
SORTING ALGORITHMS IN RUBY, PART 1
Algorithm LargestNumber
Input: A non-empty list of numbers L.
Output: The largest number in the list L.
largest ← L0
for each item in the list (Length(L)≥1), do
if the item > largest, then
largest ← the item
return largest
Ruby Projects
https://www.learnstreet.com/lessons/study/ruby#get-hint
Pinterest, FB
The issue I have is to make sure the FB link posts a photo of the product and the url to it.
References:
https://developers.facebook.com/docs/reference/fql
https://developers.pinterest.com/pin_it/
Sharing with FaceBook
https://developers.facebook.com/docs/web/share
Publishing rich and structured Custom Stories, for example a story about cooking a meal, running a race, or reading a book:
FB has a few ways that you can provide these:
Social Plugins such as the Like and Share Buttons let people quickly recommend pieces of content to various audiences on Facebook. Social Plugins simply require copy and pasting a couple of bits of HTML, and are the easiest way for developers to get sharing into their apps, with no Facebook Login required.
The Feed Dialog, which can be invoked via the JavaScript SDK or through URL redirection, allows people to share content using a consistent UI that matches that of Facebook. You also don't need to implement Facebook Login to use the Feed Dialog, which makes it simpler for developers.
The Graph API can be used for any of these types of sharing, and is the only way to use Custom Stories on the web. This can offer more control of the sharing experience by letting you build your own UI, but requires that Facebook Login is also implemented.
Can I use the Share Dialog without using the Share Button?
Yes, although we recommend using the Share button to offer the simplest and most consistent experience for people using your site, you can invoke the Share Dialog using a link:
<a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fparse.com" target="_blank">
Share on Facebook
</a>
**********************************
Add a _metadatafile to designs inventories and downloads directories
**********************************
_metadata.html.erb
app/helpers/application_helper.rb
FACEBOOK_SHARE_URL = "https://www.facebook.com/sharer/sharer.php"
TWITTER_SHARE_URL = "https://twitter.com/share"
PINTEREST_SHARE_URL = "http://pinterest.com/pin/create/button"
----------------------------------------------------------------
----------------------------------------------------------------
Converts an array into a string suitable for use as a URL query string, using the given key as the param name.
Side Note:
Chrome Developers Tools Tutorials
References:
https://developers.facebook.com/docs/reference/fql
https://developers.pinterest.com/pin_it/
Sharing with FaceBook
https://developers.facebook.com/docs/web/share
Publishing rich and structured Custom Stories, for example a story about cooking a meal, running a race, or reading a book:
FB has a few ways that you can provide these:
Social Plugins such as the Like and Share Buttons let people quickly recommend pieces of content to various audiences on Facebook. Social Plugins simply require copy and pasting a couple of bits of HTML, and are the easiest way for developers to get sharing into their apps, with no Facebook Login required.
The Feed Dialog, which can be invoked via the JavaScript SDK or through URL redirection, allows people to share content using a consistent UI that matches that of Facebook. You also don't need to implement Facebook Login to use the Feed Dialog, which makes it simpler for developers.
The Graph API can be used for any of these types of sharing, and is the only way to use Custom Stories on the web. This can offer more control of the sharing experience by letting you build your own UI, but requires that Facebook Login is also implemented.
Can I use the Share Dialog without using the Share Button?
Yes, although we recommend using the Share button to offer the simplest and most consistent experience for people using your site, you can invoke the Share Dialog using a link:
<a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fparse.com" target="_blank">
Share on Facebook
</a>
**********************************
Add a _metadatafile to designs inventories and downloads directories
**********************************
_metadata.html.erb
<meta charset="utf-8">
<!-- <meta http-equiv="X-UA-Compatible" content="IE=7" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
WeBRAND | A WeBRAND shop
</title>
<meta name="description" content="blah blah.">
<meta name="keywords" content="">
<meta property="og:title" content="Blah" />
<meta property="og:url" content="<%= root_url %>"/>
<meta property="og:image" content="<%= image_path("logo_color_small.png") %>"/>
<meta property="og:description" content= "Blah."/>
<%= tag :meta, name: "crowdshop[slug]", content: crowdslug if @_crowdshop %>
<%= csrf_meta_tags %>
<!-- <meta http-equiv="X-UA-Compatible" content="IE=7" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
WeBRAND | A WeBRAND shop
</title>
<meta name="description" content="blah blah.">
<meta name="keywords" content="">
<meta property="og:title" content="Blah" />
<meta property="og:url" content="<%= root_url %>"/>
<meta property="og:image" content="<%= image_path("logo_color_small.png") %>"/>
<meta property="og:description" content= "Blah."/>
<%= tag :meta, name: "crowdshop[slug]", content: crowdslug if @_crowdshop %>
<%= csrf_meta_tags %>
app/helpers/application_helper.rb
def facebook_link_to(url)
open_to facebook_icon, "#{FACEBOOK_SHARE_URL}?#{{ u: url }.to_query}", class: "btn btn-info"
end
def twitter_link_to(text, url, via, related)
open_to twitter_icon, "#{TWITTER_SHARE_URL}?#{{ text: text, url: url, via: via, related: related }.to_query}", class: "btn btn-primary"
end
def pinterest_link_to(description, url, media = nil)
open_to pinterest_icon, "#{PINTEREST_SHARE_URL}?#{{ description: description, url: url, image: image, media: media }.to_query}", class: "btn btn-danger"
end
open_to facebook_icon, "#{FACEBOOK_SHARE_URL}?#{{ u: url }.to_query}", class: "btn btn-info"
end
def twitter_link_to(text, url, via, related)
open_to twitter_icon, "#{TWITTER_SHARE_URL}?#{{ text: text, url: url, via: via, related: related }.to_query}", class: "btn btn-primary"
end
def pinterest_link_to(description, url, media = nil)
open_to pinterest_icon, "#{PINTEREST_SHARE_URL}?#{{ description: description, url: url, image: image, media: media }.to_query}", class: "btn btn-danger"
end
FACEBOOK_SHARE_URL = "https://www.facebook.com/sharer/sharer.php"
TWITTER_SHARE_URL = "https://twitter.com/share"
PINTEREST_SHARE_URL = "http://pinterest.com/pin/create/button"
----------------------------------------------------------------
to_query(key)
public----------------------------------------------------------------
Converts an array into a string suitable for use as a URL query string, using the given key as the param name.
['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
Facebook Debugger
Enter a URL to see some helpful feedback about your page markup. Enter an access token to see its expiry and user.SOLUTION:
Add the metadata into the download and the design directories.Side Note:
Chrome Developers Tools Tutorials
Tuesday, April 15, 2014
ssh
I have been trying to push changes to rubilicious for a while unsuccessfully. I kept getting the error: fatal: Authentication failed
VonC on StackOverflow had my answer which was to switch to an ssh url:
git remote set-url origin git@github.com:rubilicious/rubilicious.github.io.git
VonC on StackOverflow had my answer which was to switch to an ssh url:
git remote set-url origin git@github.com:rubilicious/rubilicious.github.io.git
Friday, April 11, 2014
Heartbleed Bug Fixes
The Heartbleed Bug is a serious vulnerability in the popular OpenSSL cryptographic software library. This weakness allows stealing the information protected, under normal conditions, by the SSL/TLS encryption used to secure the Internet. SSL/TLS provides communication security and privacy over the Internet for applications such as web, email, instant messaging (IM) and some virtual private networks (VPNs).
The Heartbleed bug allows anyone on the Internet to read the memory of the systems protected by the vulnerable versions of the OpenSSL software. This compromises the secret keys used to identify the service providers and to encrypt the traffic, the names and passwords of the users and the actual content. This allows attackers to eavesdrop on communications, steal data directly from the services and users and to impersonate services and users.
Things I had to do to fix it:
0. Update my Open SSL (which I did yesterday)1. $ rvm implode Ignore this message:
Failed to completely remove /home/jen/.rvm -- You will have to do so manually.2. remove ssh secrets
Note you may need to manually remove /etc/rvmrc and ~/.rvmrc if they exist still.
Please check all .bashrc .bash_profile .profile and .zshrc for RVM source lines and delete or comment out if this was a Per-User installation.
Also make sure to remove `rvm` group if this was a system installation.
Finally it might help to relogin / restart if you want to have fresh environment (like for installing RVM again).
remove all authorizations from github security
$ rm ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
3. Remove all ssh keys from Github and
any other permissions in Security and Applications section
4. regenerate ssh keys
$ ssh-keygen -t rsa -C <"myname@email.com">
Generating public/private rsa key pair.Enter file in which to save the key (/home/jen/.ssh/id_rsa): (hit Enter/Return for default)5. get rid of ruby on computer
Enter passphrase (empty for no passphrase): (hit Enter/Return for default or add pswd)
Enter same passphrase again: (hit Enter/Return for default or add pswd again)
Your identification has been saved in /home/jen/.ssh/id_rsa.Your public key has been saved in /home/jen/.ssh/id_rsa.pub.The key fingerprint is: blah blah blah
6. get a password manager for ubuntu
KeePassX saves many different information e.g. user names, passwords, urls, attachments and comments in one single database. For a better management user-defined titles and icons can be specified for each single entry. Furthermore the entries are sorted in groups, which are customizable as well. The integrated search function allows to search in a single group or the complete database.
KeePassX offers a little utility for secure password generation. The password generator is very customizable, fast and easy to use. Especially someone who generates passwords frequently will appreciate this feature.
Task for today:
K is pushing a branch I need to download it and test itThursday, April 10, 2014
Notes - Rails Tutorial Chapter 2 & Ubuntu Updates
Did an upgrade of all my Ubuntu packages including Open SSL
OpenSSL could be made to expose sensitive information over the network, possibly including private keys.
Neel Mehta discovered that OpenSSL incorrectly handled memory in the TLS
heartbeat extension. An attacker could use this issue to obtain up to 64k
of memory contents from the client or server, possibly leading to the
disclosure of private keys and other sensitive information.

Setters and getters are like attr accessor and attr reader.
OpenSSL could be made to expose sensitive information over the network, possibly including private keys.
Neel Mehta discovered that OpenSSL incorrectly handled memory in the TLS
heartbeat extension. An attacker could use this issue to obtain up to 64k
of memory contents from the client or server, possibly leading to the
disclosure of private keys and other sensitive information.
rails console vs irb
The exact prompt you'll see in irb can vary and I see the same one you do in Rails 3. It's nothing to worry about. In fact, I see the simple prompt in plain irb, and the full prompt in rails console :-)
They are both irb, it's just that rails console is set up such that the rails environment is all set and ready to work with, while regular irb has almost nothing loaded by default.
Controller
A controller is a Ruby class which inherits from ApplicationController and has methods just like any other class. When your application receives a request, the routing will determine which controller and action to run, then Rails creates an instance of that controller and runs the method with the same name as the action.Request methods
An HTTP 1.1 request made using telnet. The request, response headersand response body are highlighted.
HTTP defines methods (sometimes referred to as verbs) to indicate the desired action to be performed on the identified resource. What this resource represents, whether pre-existing data or data that is generated dynamically, depends on the implementation of the server. Often, the resource corresponds to a file or the output of an executable residing on the server. The HTTP/1.0 specification[10]:section 8defined the GET, POST and HEAD methods and the HTTP/1.1 specification[1]:section 9 added 5 new methods: OPTIONS, PUT, DELETE, TRACE and CONNECT. By being specified in these documents their semantics are well known and can be depended upon. Any client can use any method and the server can be configured to support any combination of methods. If a method is unknown to an intermediate it will be treated as an unsafe and non-idempotent method. There is no limit to the number of methods that can be defined and this allows for future methods to be specified without breaking existing infrastructure. For example, WebDAV defined 7 new methods and RFC5789 specified the PATCH method.
- GET
- Requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect. (This is also true of some other HTTP methods.)[1] The W3C has published guidance principles on this distinction, saying, "Web application design should be informed by the above principles, but also by the relevant limitations."[11] See safe methods below.
- HEAD
- Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.
- POST
- Requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI. The data POSTed might be, as examples, an annotation for existing resources; a message for a bulletin board, newsgroup, mailing list, or comment thread; a block of data that is the result of submitting a web form to a data-handling process; or an item to add to a database.[12]
- PUT
- Requests that the enclosed entity be stored under the supplied URI. If the URI refers to an already existing resource, it is modified; if the URI does not point to an existing resource, then the server can create the resource with that URI.[13]
- DELETE
- Deletes the specified resource.
- TRACE
- Echoes back the received request so that a client can see what (if any) changes or additions have been made by intermediate servers.
- OPTIONS
- Returns the HTTP methods that the server supports for the specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource.
- CONNECT
- Converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.[14][15] See HTTP CONNECT Tunneling.
- PATCH
- Is used to apply partial modifications to a resource.[16]
HTTP servers are required to implement at least the GET and HEAD methods[17] and, whenever possible, also the OPTIONS method.[citation needed]
Resources
A resource is simply the object the user of the application will interact with.
Rails Tutorial Chapter 8.20
current_user=
First, you're reading the method names wrong (which is not surprising given how cryptic ruby method naming can be). def current_user=(user) is actually read as defining the method current_user= that takes an argument user, whereas def current_user defines a method current_user that takes no arguments. These are referred to respectively as setters and getters.Setters and getters are like attr accessor and attr reader.
Tuesday, April 8, 2014
Ruby Gems
Ruby-toolbox
Rubygems.org
squeel
Github: https://github.com/activerecord-hackery/squeelDocumentation: http://rubydoc.info/gems/squeel/1.1.1/frames
Railscast: http://railscasts.com/episodes/354-squeel?view=asciicast
Squeel lets you write your Active Record queries with fewer strings, and more Ruby, by making the Arel awesomeness that lies beneath Active Record more accessible.
acts-as-taggable-on
Github: https://github.com/mbleigh/acts-as-taggable-onDocumentation: http://rubydoc.info/gems/acts-as-taggable-on/3.1.1/frames
Railscast: http://railscasts.com/episodes/382-tagging
In a social network, a user might have tags that are called skills, interests, sports, and more. There is no real way to differentiate between tags and so an implementation of this type is not possible with acts as taggable on steroids.
Enter Acts as Taggable On. Rather than tying functionality to a specific keyword (namely
tags
), acts as taggable on allows you to specify an arbitrary number of tag "contexts" that can be used locally or in combination in the same way steroids was used.apartment
Github: https://github.com/influitive/apartmentDocumentation: http://rubydoc.info/gems/apartment/0.24.3/frames
Railscast: http://railscasts.com/episodes/389-multitenancy-with-postgresql?view=comments
Apartment provides tools to help you deal with multiple tenants in your Rails application. If you need to have certain data sequestered based on account or company, but still allow some data to exist in a common tenant, Apartment can help.
paper_trail
Github: https://github.com/airblade/paper_trailDocumentation: http://rubydoc.info/gems/papertrail/0.9.9/frames
Railscast: http://railscasts.com/episodes/415-upgrading-to-rails-4?view=asciicast
Command-line client for Papertrail hosted log management service. Tails and searches app server logs and system syslog. Supports Boolean search and works with grep and pipe output (Unix).
carrierwave
Github: https://github.com/carrierwaveuploader/carrierwaveDocumentation: http://carrierwave.rubyforge.org/rdoc/
Railscast: http://railscasts.com/episodes/253-carrierwave-file-uploads
CarrierWave makes it easy and clean to add file uploads to your application. It supports a variety of ORMs, frameworks and image processors.
carrierwave-serializable
Github: https://github.com/timsly/carrierwave-serializableDocumentation:
Railscast:
activerecord-tableless
Github:Documentation:
Railscast:
mini-magick
Github:Documentation:
Railscast:
devise
Github:Documentation:
Railscast:
draper\grape-active_model_serializers
GithubDocumentation:
Railscast:
oj
Github:Documentation:
Railscast:
cache_digests
Github:Documentation:
Railscast:
naught
Github:Documentation:
Railscast:
countries
Github:Documentation:
Railscast:
country_select
Github:Documentation:
Railscast:
oink
Github:Documentation:
Railscast:
bugsnag
Github:Documentation:
Railscast:
puma
Github:Documentation:
Railscast:
letter_opener
Github:Documentation:
Railscast:
quiet_assets
Github:Documentation:
Railscast:
spring
Github:Documentation:
Railscast:
spring-commands-rspec
Github:Documentation:
Railscast:
flamegraph
Github:Documentation:
Railscast:
poltergeist
Github:Documentation:
Railscast:
webmock
Github:Documentation:
Railscast:
fabrication
Github:Documentation:
Railscast:
timecop
Github:Documentation:
Railscast:
Subscribe to:
Posts (Atom)