Skip to content

Instantly share code, notes, and snippets.

View workmaster2n's full-sized avatar

Tyler DeWitt workmaster2n

  • Peritus Resource Group
  • Tulsa, OK
View GitHub Profile
@workmaster2n
workmaster2n / explain
Created October 1, 2012 17:45
optimize query
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: players
type: index
possible_keys: PRIMARY
key: index_players_on_LastName
key_len: 768
ref: NULL
rows: 10
desc "all in one"
task :all_in_one => :environment do
#q here is a message q. Assume it receives messages at the rate of 10/second
q.subscribe(:block => true) do |delivery_info, properties, body|
#process the message (body)
puts "I got a message: #{body}"
#I'd like every 10 seconds to output Total Messages Received: 13021
end
@workmaster2n
workmaster2n / fail.console
Created January 15, 2014 19:41
Cacheing has_many through:
p = Person.create
p.items << Item.create
Rails.cache.write(Time.now, p)
=> false
p.reload
Rails.cache.write(Time.now, p)
=> <truthy>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using QTrack.QT500.Demo.Core;
using QTrack.RemoteEvents;
@workmaster2n
workmaster2n / non_root.log
Last active December 30, 2015 10:09
rvm issue
[2013-12-05 13:28:28] requirements_osx_brew_libs_install
requirements_osx_brew_libs_install ()
{
brew unlink "$@" || true;
brew install "$@" || {
typeset ret=$?;
rvm_warn "There were package installation errors, make sure to read the log.
Try \`brew tap --repair\` and make sure \`brew doctor\` looks reasonable.
@workmaster2n
workmaster2n / query.sql
Created November 14, 2013 00:18
count distinct date
SELECT DISTINCT ON (date_trunc('day', recorded_at)) COUNT(*)
FROM tracked_points WHERE worker_id = 1 AND recorded_at > '2013-11-14'
"HashAggregate (cost=142395.01..142395.21 rows=20 width=4) (actual time=1693.497..1693.500 rows=21 loops=1)"
" -> Seq Scan on tracked_points (cost=0.00..121326.67 rows=4213667 width=4) (actual time=0.006..665.009 rows=4206624 loops=1)"
"Total runtime: 1693.546 ms"
SELECT tracked_point_zones.worker_id, tracked_point_zones.zone_id, COUNT(*) FROM tracked_point_zones
LEFT JOIN zones ON zones.id = tracked_point_zones.zone_id AND tracked_point_zones.recorded_at > '2013-11-01' AND tracked_point_zones.worker_id = 5
GROUP BY tracked_point_zones.worker_id, tracked_point_zones.zone_id
ORDER BY COUNT(*) DESC
@workmaster2n
workmaster2n / script.bash
Created November 5, 2013 21:49
postgres/postgis
To install PostGIS/Postgres:
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install postgresql-9.1-postgis
@workmaster2n
workmaster2n / doesnt_work.sql
Last active December 27, 2015 10:39
different updates
UPDATE tracked_points SET worker_id = worker_tags.worker_id
FROM tags LEFT JOIN worker_tags ON tags.id = worker_tags.tag_id
WHERE (tags.frequency = tracked_points.frequency OR worker_tags.id IS NULL)
AND tracked_points.worker_id_checked_at IS NULL