Skip to content

Instantly share code, notes, and snippets.

@ctdk
ctdk / node_test.rb
Created July 2, 2014 03:49
Create a bunch of nodes & clients with chef-api and fauxhai
#!/usr/bin/env ruby
require 'chef-api'
require 'fauxhai'
include ChefAPI::Resource
ChefAPI.configure do |config|
config.endpoint = 'http://nineveh.local:4545'
config.client = 'admin'
{
"apt": {
"1.1.2": {
"dependencies": {
},
"location_path": "http://nineveh.local:4545/cookbooks/apt/1.1.2",
"location_type": "chef_server"
}
},
"build-essential": {
@ctdk
ctdk / velikij.go
Last active August 29, 2015 14:06
A sample plugin for gosudar.
package main
// A demonstration of a gosudar plugin. For now, place the compiled binary in /tmp/plugins.
import (
"net"
"net/rpc/jsonrpc"
"os"
)
@ctdk
ctdk / gist:9a1109f198ac924e308d
Last active August 29, 2015 14:07
First light
nineveh:goiardi-test jeremy$ knife raw /organizations
{
"default": "http://nineveh.local:4545/organizations/default"
}
nineveh:goiardi-test jeremy$ knife raw /organizations/default
{
"name": "default",
"full_name": "default org",
"guid": "1d40f87ac0b9438f8c20f67c684c32c1"
begin
require "memcached"
rescue LoadError
puts "You need the memcached (the libmemcached client, not the other one) gem to use the Memcached moneta store"
exit
end
# uses the memcached gem properly, and traps the weirdass exception a get on an undefined key throws. May be worth changing
# further to allow the extra flags memcached lets you use, like marshal => true|false or the various memcached flags
begin
require "memcached"
rescue LoadError
require "memcache"
rescue LoadError
puts "You need the memcache or the memcached gem to use the Memcache moneta store"
exit
end
module Moneta
class MessageController < ApplicationController
def index
@messagee = User.by_name(params[:nick])
end
def newpmthr
if request.post?
pmthr = PMThread.new
unless (pmthr)
raise "Something's wrong"
class StoryController < ApplicationController
#require 'utility'
def index
@story = Story.get(params[:id])
#@comments = repository(:default).adapter.query('SELECT comments.id, story_id, user_id, parent_id, time, sid, cid, pid, subject, recrate, trollrate, raters, commentip, comment, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id)
#@comments = Comment.find_by_sql(['SELECT comments.id, subject, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id])
# experiment...
clist = repository(:default).adapter.query('SELECT comments.id, story_id, user_id, parent_id, time, sid, cid, pid, subject, recrate, trollrate, raters, commentip, comment, nickname from comments left join users on comments.user_id = users.id where story_id = ?', @story.id)
chash = Hash.new
def self.treeify_comments(clist, pid = 0)
chash = Hash.new # comments grouped by parent_id
comhash = Hash.new # comments in a hash, w/ comment id as key
comments = Array.new # for the ordered comments
depth_tree = Hash.new # comment depth
clist.collect { |x| comhash[x.id] = x }
# ?
clist.collect do |c|
chash[c.parent_id] ||= Array.new
# what breaks
<% blogs = @story.user.blogs %>
# with:
Cannot find the child_model Blogadmin for User
# the relationship in User
# doesn't work