Tuesday, 31 July 2012
Saturday, 28 July 2012
what?
%w{rubygems pp wirble what_methods}.each do |lib|
begin
require lib
rescue LoadError => err
$stderr.puts "Couldn't load #{lib}: #{err}"
end
end
%w{init colorize}.each { |str| Wirble.send(str) }
if I have an object, what method can I call on it to get that result?
1.9.3-p194 :009 > "hello".what? "HELLO"
"hello".upcase == "HELLO"
"hello".swapcase == "HELLO"
"hello".upcase! == "HELLO"
"hello".swapcase! == "HELLO"
Thursday, 19 July 2012
Struct && delegate
Sunday, 15 July 2012
Saturday, 14 July 2012
location aware realtime visitor tracker with pusher and php
http://www.webresourcesdepot.com/location-aware-realtime-visitor-tracker-using-pusher-tutorial/
underscore
Underscore provides 60-odd functions that support both the usual functional suspects:map, select, invoke — as well as more specialized helpers: function binding, javascript templating, deep equality testing, and so on. It delegates to built-in functions, if present, so modern browsers will use the native implementations offorEach, map, reduce, filter, every, some and indexOf.
http://documentcloud.github.com/underscore/
http://documentcloud.github.com/underscore/
nowjs
Server push
You can call easily client functions from the server and server functions from the client. That means you can push to the client simply by calling a client-side Javascript function on the server. Communication is achieved using Socket.io
Use me for push notifications: http://nowjs.com/
Moment.js
---------------------------------
<!-- <html>
<head>
<title>in a Moment.js</title>
</head>
<body>
<h1>Moment.js here now: <span id="then" data-date="Sat Jul 14 2012 07:43:14 GMT-0400 (EDT)"></span></h1>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://raw.github.com/timrwood/moment/1.6.2/moment.js"></script>
<script>
$(document).ready(function(){
var then = $('#then'),
date = moment(new Date(then.attr('data-date'))),
update = function(){
then.html(date.fromNow());
};
update();
setInterval(update, 6000);
});
</script>
</body>
</html>
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Formatting dates using the Moment.js date library</title>
</head>
<body>
<p><time data-momentjs>2012-07-12</time></p>
<p><time data-momentjs>1976-09-09</time></p>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/timrwood/moment/1.1.1/moment.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$("time[data-momentjs]").each(function (idx, item) {
var $item = $(item),
mdate = moment($item.text(), "YYYY-MM-DD");
$item.attr("title", mdate.format("ddd, MMM Do, YYYY")).text(mdate.fromNow());
});
});
</script>
</body>
</html>
------------------------------
Moment.js here now:
Friday, 13 July 2012
Tuesday, 10 July 2012
ror db Snapshot by 37signals
Snapshot
The snapshot plugin adds two new rake tasks that make it easy for you to take a snapshot of your existing (development) database, and restore it again.
Why would you want this?
Imagine you are developing an app. You've spent a few hours filling your development DB with data so that you can design a particular UI scenario. Now, though, you need to design another scenario, which requires a different dataset, and you are loathe to lose the data you so laboriously entered.
The snapshot plugin saves the day:
$ rake db:snapshot
This creates a db/snapshot file (which records all the data in your DB), and a db/snapshot.schema file (which records the state of the schema when the snapshot was taken). At any time, then, you can restore that snapshot:
$ rake db:snapshot:restore
This will erase the existing DB, restore the db/snapshot.schema schema, and then load the data. If there are any pending migrations, it will then run those, and then regenerate the snapshot so that it stays at the latest schema.
You can pass a different snapshot file to use as a parameter, to either task:
$ rake db:snapshot[scenarios/real-estate]
...
$ rake db:snapshot:restore[scenarios/telemarketer]
Limitations
The current version will probably fail when there are foreign key constraints, since the order the tables and rows are restored is not guaranteed to be in any particular order.
Also, even moderately large data sets (e.g. multiple thousands of rows) may result in poor performance during snapshot and restore, since the data is all loaded into memory.
https://github.com/37signals/snapshot
DJ demons
On production, you would want the worker to be running all the time. Also, it will be nice to have the ability to stop the worker just before the deployment and start it again once the deployment finishes. It sounds complicated, but its pretty easy to set up.
First, install the daemons gem:
# Add in environment.rb
config.gem 'daemons'
$ rake gems:install
Then, copy this script in your rails project in file script/delayed_job and give it execute permission. This creates a worker daemon, which when started keeps running as a background process.
Alternately, instead of daemons gem, you can use daemon-spawn gem.
Install the gem on the host where you want the delayed_job daemon to run:
$ sudo gem sources -a http://gems.github.com
$ sudo gem install alexvollmer-daemon-spawn
And then copy this script instead in script/delayed_job. Rest all of the following steps are identical, whichever gem and script/delayed_job you choose.
# start the worker daemon
$ ruby script/delayed_job start
# stop it
$ ruby script/delayed_job stop
http://8raystech.com/2009/2/28/background-job-processing-in-rails-with-delayed_job
Sunday, 8 July 2012
Subscribe to:
Posts (Atom)