background preloader

Ruby(rails)

Facebook Twitter

Using Redis with Ruby on Rails. Buy The Redis Book! Written by Redis creator, Salvatore Sanfilippo, and key contributor, Pieter Noordhuis, the Redis Book will show you how to work with different data structures, how to handle memory, replication, and the cache itself, and how to implement messaging, amongst other things! Buy the book Redis is an extremely fast, atomic key-value store. It allows the storage of strings, sets, sorted sets, lists and hashes. Redis keeps all the data in RAM, much like Memcached but unlike Memcached, Redis periodically writes to disk, giving it persistence. Redis is an open source, advanced key-value store. The above quote was taken from the official Introduction to Redis page. Table of Contents Redis Data Types Below is a general overview of the data types available to you in Redis: As well as those basic types, there is also the ability to do PubSub with Redis.

Installing Redis Installation is simple: Starting Redis Server redis-server /path/to/redis.conf The default redis.conf looks like this. God. Cryptic Ruby Global Variables and Their Meanings. How many times have you looked at some ruby code and found strange variable names (eg. $0, $:, etc) and wondered what they meant? Below is a list of cryptic global variable names in ruby and their meanings. Environmental Global Variables $: (Dollar Colon) $: is basically a shorthand version of $LOAD_PATH. $: contains an array of paths that your script will search through when using require. >> $: === $LOAD_PATH=> true>> $:=> [" $0 (Dollar Zero) $0 contains the name of the ruby program being run. Example.rb Jims-MacBook-Pro:~/Desktop ruby example.rbexample.rbJims-MacBook-Pro:~/Desktop irb>> $0=> "irb" $* (Dollar Splat) $* is basically shorthand for ARGV. $* contains the command line arguments that were passed to the script. puts "$*: " << $*.inspectputs "ARGV: " << ARGV.inspect Jims-MacBook-Pro:~/Desktop ruby example.rb hello world$*: ["hello", "world"]ARGV: ["hello", "world"] $?

$? >> `pwd` # Show current directory=> "/Users/jimneath/Desktop\n">> $? $$ (Dollar Dollar) $~ (Dollar Tilde) $! $! Reia Programming Language. Headius/mirah - GitHub. Using @font-face in Padrino, Or: How to add a Mime Type - MrJaba's Adventures. Classes in Ruby : ruby. For a Good Strftime - Easy Skeezy Ruby Date/Time Formatting. OCR: Converting Images to Text with MODI. Joe Schmoe from Kokomo has a scanned image of a 300-page contract. Joe wishes he could search this file for certain rates and terms, but it's an image, not a text file. OCR might be just what the doctor ordered. Optical character recognition, usually abbreviated to OCR, is the mechanical or electronic translation of images of handwritten, typewritten or printed text (usually captured by a scanner) into machine-editable text. --Wikipedia One such OCR solution that you may already have available to you is Microsoft Office Document Imaging (MODI), part of the Microsoft Office suite.

MODI might not have been installed when you installed Microsoft Office, so your first step may be to install it from the Office install disks. Accessing the MODI API To begin with, we'll use the win32ole module to create a new instance of the MODI.Document object: require 'win32ole'doc = WIN32OLE.new('MODI.Document') Loading the Image doc.Create('C:\images\image1.tif') NOTE: MODI only works with TIFF files. Doc.OCR() Bowline. Write a Sinatra-based Twitter clone in 200 lines of Ruby code « saush. After trying out Sinatra as the interface to my search engine, I got hooked to it. I liked the no-frills approach to developing a web application. I liked it so much that I decided to write a fuller web app using Sinatra. Of course I had no idea what to write, so I decided to clone a random popular application. That was how I ended up writing a Twitter clone. It was inevitable that halfway writing the Chirp-Chirp, my Sinatra-based Twitter clone, I found out that there are already quite a few Twitter clones out there, 262 to be specific, at least as of August 2008.

The design goals for Chirp-Chirp are very simple. To begin with, let’s look at a Twitter clone. Let’s look at the various components of Chirp-Chirp: User interfaceLogin and user managementData modelingHome pageFriends and followersPublic and direct messages User interface Simply put I just copied Twitter‘s user interface and slapped on a self-drawn logo.

Data modeling I used DataMapper again for data modeling. That’s it! A Beginner's Sinatra Tutorial : TitusD. In the olden days your first program was probably in BASIC and was run from the command line, nowadays the equivalent is Web programming. Using Sinatra reminds me of my first programming experiences – you write a tiny bit of code, with no boilerplate and get to see a result. What follows owes a lot to the Sinatra README. On Linux, you’ll need Ruby and Rubygems installed (if not you should find installation instructions easily enough via a Web search). Apart from Ruby, you’ll need to use a text editor (e.g. Next install Sinatra: $ gem install sinatra Now, open a Terminal window and type: ruby minimal.rb Finally, go to this address: To stop the program, go to the Terminal window and press Ctrl+C 2.

It’s useful to structure the program as a class. Run it: ruby sinatra_base.rb 3. Create two files: $ ruby run_my_app.rb Instead of writing a script to start the app, we can use Rackup to launch the same script: Create a file ‘config.ru’: require 'my_app' run MyApp.new rackup config.ru 5.