This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT start_time, time_zone, start_time + (time_zone * INTERVAL '1 second') AS start_time_local FROM events LIMIT 1; | |
start_time | time_zone | start_time_local | |
-----------------------+-----------+----------------------- | |
2012-10-25 11:53:37.5 | -14400 | 2012-10-25 07:53:37.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- In first version WHERE is outside JOIN: | |
SELECT * FROM t1 | |
INNER JOIN t2 ON t1.t2_id = t2.id | |
WHERE t2.some_boolean; | |
-- In second version condition is lifted into JOIN condition | |
SELECT * FROM t1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT AVG(CAST(end_time AS time)) AS avg_end_time FROM "places" INNER JOIN "events" ON "events"."place_id" = "places"."id" AND events.category_id = 8 WHERE "places"."geocode_id" = 6096070 AND "places"."category_id" = 2 AND (place_events_count > 2) AND ((EXTRACT(EPOCH FROM end_time) - EXTRACT(EPOCH FROM start_time)) BETWEEN (4*3600) AND (12*3600) AND EXTRACT(HOUR FROM end_time) BETWEEN 11 AND 19) AND EXTRACT(DOW FROM end_time) IN (6,0); | |
avg_end_time | |
----------------- | |
15:55:32.654876 | |
(1 row) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
redis 127.0.0.1:6379> LPUSH test, "hello" | |
(integer) 2 | |
redis 127.0.0.1:6379> LLEN test | |
(integer) 0 | |
redis 127.0.0.1:6379> RPOP test | |
(nil) | |
redis 127.0.0.1:6379> LPOP test | |
(nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb(main):050:0> user = User.find 1 | |
[snip] | |
irb(main):051:0> events = FactoryGirl.create_list :place_event, 3, user: user | |
[snip] | |
irb(main):052:0> new_place = FactoryGirl.create :place, user: user | |
[snip] | |
irb(main):067:0> PlaceEvent.where("id IN (#{ events.collect(&:id).join(',') })").move_to new_place | |
[snip] | |
SQL (1.1ms) UPDATE "places" SET "place_events_count" = COALESCE("place_events_count", 0) + 1 WHERE "places"."id" = 1799211 | |
SQL (1.0ms) UPDATE "places" SET "place_events_count" = COALESCE("place_events_count", 0) - 1 WHERE "places"."id" = 1799208 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Works, but a bit awkward: | |
def self.group_by_name(r) | |
r.group_by &:name | |
end | |
Model.group_by_name(models.where(..)) | |
# Would be nicer to have |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mon Jun 10 19:17:51 MST 2013: performing suspend | |
Tue Jun 11 07:52:44 MST 2013: Awake. | |
Tue Jun 11 07:52:44 MST 2013: Running hooks for resume | |
Running hook /etc/pm/sleep.d/novatel_3g_suspend resume suspend: | |
/etc/pm/sleep.d/novatel_3g_suspend resume suspend: success. | |
Running hook /usr/lib/pm-utils/sleep.d/99video resume suspend: | |
/usr/lib/pm-utils/sleep.d/99video resume suspend: success. | |
Running hook /etc/pm/sleep.d/99bcmbluetooth resume suspend: |
We can't make this file beautiful and searchable because it's too large.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.0986533107808496 | |
1.583960737452346 | |
0.13734048649924682 | |
3.5384582189028078 | |
0.8109541275321867 | |
1.4710983394905912 | |
1.2568627243577724 | |
0.6561450580865987 | |
1.2664615130882972 | |
1.10855911768647 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
original_bobs = User.where first_name: 'Bob' | |
# Assume this deletes a Bob: | |
User.destroy 123 | |
# Now I'd like to see user 123 in this list: | |
puts original_bobs | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timer, | |
work = function () { | |
asyncWork(function(err) { | |
timer = setTimeout(work, 10000); | |
} | |
}, | |
exports.start = function () { | |
work(); |