Skip to content

Instantly share code, notes, and snippets.

Avatar
👻
A ghost

Nathan myobie

👻
A ghost
View GitHub Profile
View gist:15218
-- Original
SELECT DATEADD(day, - (1 * DATEPART(dw, RegisterDateTime)), CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, RegisterDateTime)))) AS Week,
COUNT(ProductRegistrationID) AS RegistrationCount, SUM(CONVERT(TINYINT, ContentExpert)) AS ContentExpertCount
FROM ProductRegistrations
WHERE (RegisterDateTime > DATEADD(year, - 1, DATEADD(day, (1 * DATEPART(dw, GETDATE())), GETDATE())))
GROUP BY DATEADD(day, - (1 * DATEPART(dw, RegisterDateTime)), CONVERT(DATETIME, FLOOR(CONVERT(FLOAT, RegisterDateTime))))
ORDER BY Week DESC
-- My Attempt to convert
View init.rb
# works
require 'rest_client'
# broken
dependency 'rest-client'
# broken
dependency 'rest_client'
# this might work!?
View gist:22382
### The controller
def index
@products = Product.all(:order => [:model_number, :model_name])
display @products
end
### The model
belongs_to :manufacturer
View gist:22414
require 'rubygems'
require 'daemons'
puts 'I am not a daemon yet.'
# Become a daemon
Daemons.daemonize
loop do
puts 'Woo hoo!'
View snippet.rb
class LdapServer
include DataMapper::Resource
property :id, Serial
property :host, String, :length => 255
property :port, Integer, :default => 389
property :base_dn, String, :length => 255, :default => "dc=example,dc=com"
property :object_class, String, :default => "organizationalPerson"
property :email_attr, String, :default => "mail"
View snippet.rb
# Solved!
class Thing
# these associations are fine
belongs_to :user
belongs_to :assigned_user, :class_name => "User", :child_key => [:assigned_user_id]
# this is not working
has n, :subscriptions
has n, :subscribers, :through => :subscriptions, :class_name => 'User', :child_key => [:ticket_id], :remote_name => :user
View snippet.rb
class Book
belongs_to :group
has n, :subscriptions
has n, :subscribers, :through => :subscriptions, :class_name => 'User',
:child_key => [:book_id], :remote_name => :user
end
class Group
has n, :books
has n, :users, :through => Resource
View gist:37528
#!/usr/bin/env ruby
#
# Be sure to configure this node in the plugin configuration
# Memory stats must be run by root
# Ex:
# [passenger_memory]
# user root
# env.memory_stats_command path_to_passenger-memory-stats
#
View snippet.rb
### just post a string to a url, and we can figure out what type of post it is
chat_string = "Me: Hello
You: Hello back
Me: I need to get this blog done
Me: Like now
You: Yeah, you do
You: It really has been a while
Me: OK, that's enough from you"
View gist:44726
# Rails initializer for CouchDB
begin
config = YAML::load(File.open('config/couchdb.yml'))
rescue
puts "ERROR: Could not read config/couchdb.yml"
exit(1)
end
begin
RelaxDB.configure(config[RAILS_ENV])
You can’t perform that action at this time.