unix timestamp => TS = Time.now.to_i
get hash => HASH = Digest::SHA1.hexdigest(sharedsecret+TS)
Api Key => AKEY
AKEY and sharedsecret will be mailed to you once you apply for API
http://www.slideshare.net/developers/documentation
for ex:
http://www.slideshare.net/api/1/get_slideshow?api_key=AKEY&ts=TS&hash=HASH&username=UN&password=PWD&slideshow_id=Sid
Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts
Wednesday, December 12, 2007
Tuesday, March 27, 2007
Loops @ Ruby
n.times {|i| puts i}
n.times {|i| puts i}
or
n.times do |i|
puts i
end
a=["hello","to","you"]
a.each {|i| puts i}
(1..10)each{|i| puts i}
or
for i in (1..10)
puts i
end
Well, the method Integer#times iterate self times (n in this) and for each iteration calls the block, gives it the current value।
something do |line|
#process something and line here
end
something' is a method and this method call the block with
some value.
For example if you want to read a file, you write
IO.foreach('file') do |line|
# do something with line
end
the method IO::foreach open the file given in argument, read each line and
call the block, given it the current line. At the end, IO::foreach close
the file
n.times {|i| puts i}
or
n.times do |i|
puts i
end
a=["hello","to","you"]
a.each {|i| puts i}
(1..10)each{|i| puts i}
or
for i in (1..10)
puts i
end
Friday, February 23, 2007
Metaprogramming @ Ruby
Metaprogramming is the writing of programs that write or manipulate other programs (or themselves) as their data or that do part of the work that is otherwise done at run time during compile time. In many cases, this allows programmers to get more done in the same amount of time as they would take to write all the code manually.
The language in which the metaprogram is written is called the metalanguage. The language of the programs that are manipulated is called the object-language. The capacity of a programming language to be its own meta-language is called reflexivity.
Not all metaprogramming involves generative programming. If programs are modifiable at runtime (as in Lisp, Python, Smalltalk, Ruby, PHP, Perl, Tcl and other languages), then techniques can be used to accomplish metaprogramming without actually generating source code.
The language in which the metaprogram is written is called the metalanguage. The language of the programs that are manipulated is called the object-language. The capacity of a programming language to be its own meta-language is called reflexivity.
Not all metaprogramming involves generative programming. If programs are modifiable at runtime (as in Lisp, Python, Smalltalk, Ruby, PHP, Perl, Tcl and other languages), then techniques can be used to accomplish metaprogramming without actually generating source code.
Thursday, February 22, 2007
still more rails
URL routing
An incoming URL always maps to some action within a controller. A controller is simply a Ruby class, and each action implemented by the controller is a public method within the controller class. The default mapping from URL to action method is (in "Rails-speak"):
/:controller/:action/:id
If the default URL routing does not meet your needs, you can easily specify your own routing rules, even using regular expressions
Rails routing rules are Ruby code. Here is an example:
map.connect 'date/:year/:month/:day',
:controller => 'blog',
:action => 'by_date',
:month => nil,
:day => nil,
:requirements => {:year => /\d{4}/,
:day => /\d{1,2}/,
:month => /\d{1,2}/}With this routing rule, the following URLs are valid:
http://myblog.com/date/2005
http://myblog.com/date/2005/08
http://myblog.com/date/2005/08/01
This rule decomposes a URL containing a date that, perhaps, a blog might use to display the postings for a particular date. A URL that matches this form will map to the BlogController class and the by_date method. The parameter hash will contain values for a four-digit year (/\d{4}/ is a Ruby regular expression), a two-digit month, and a two-digit day. Further, the month and day are optional; if no values are present, the parameter hash will contain the default value of nil.
Filters allow you to run preprocessing code before Rails executes an action and post-processing code after it completes an action. They are useful for such things as caching or authentication before calling the action, and compression or localization of the response after calling an action. The before_filter processing can either allow the action to be called normally by returning true, or abort the action by returning false (or by performing a render or redirect operation).
http://www.onlamp.com/pub/a/onlamp/2005/10/13/what_is_rails.html?page=5
An incoming URL always maps to some action within a controller. A controller is simply a Ruby class, and each action implemented by the controller is a public method within the controller class. The default mapping from URL to action method is (in "Rails-speak"):
/:controller/:action/:id
If the default URL routing does not meet your needs, you can easily specify your own routing rules, even using regular expressions
Rails routing rules are Ruby code. Here is an example:
map.connect 'date/:year/:month/:day',
:controller => 'blog',
:action => 'by_date',
:month => nil,
:day => nil,
:requirements => {:year => /\d{4}/,
:day => /\d{1,2}/,
:month => /\d{1,2}/}With this routing rule, the following URLs are valid:
http://myblog.com/date/2005
http://myblog.com/date/2005/08
http://myblog.com/date/2005/08/01
This rule decomposes a URL containing a date that, perhaps, a blog might use to display the postings for a particular date. A URL that matches this form will map to the BlogController class and the by_date method. The parameter hash will contain values for a four-digit year (/\d{4}/ is a Ruby regular expression), a two-digit month, and a two-digit day. Further, the month and day are optional; if no values are present, the parameter hash will contain the default value of nil.
Filters allow you to run preprocessing code before Rails executes an action and post-processing code after it completes an action. They are useful for such things as caching or authentication before calling the action, and compression or localization of the response after calling an action. The before_filter processing can either allow the action to be called normally by returning true, or abort the action by returning false (or by performing a render or redirect operation).
http://www.onlamp.com/pub/a/onlamp/2005/10/13/what_is_rails.html?page=5
Labels:
"url routing",
before_filter,
controller,
filters,
rails,
ruby
Subscribe to:
Posts (Atom)
