Skip to content

Instantly share code, notes, and snippets.

@ChadSki
ChadSki / FieldControlSelector.cs
Last active August 29, 2015 14:01
Databinding to Dynamic Objects?
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Quickbeam.Low;
namespace MetroIde.Controls.MetaEditor
{
public class FieldControlSelector : DataTemplateSelector
{
# ensure plugins are loaded
if len(plugin_classes) == 0:
load_plugins()
def load_map(map_path=None):
"""Loads a map from Halo.exe's memory, or from disk if given a filepath. Loading a
map requires that plugins have already been loaded.
"""
# end result, constructed now (because we need the reference) but init'd at the end
halomap = HaloMap()
@mbklein
mbklein / restart_masterfile.rb
Last active August 29, 2015 14:04
How to restart a hung MasterFile in Matterhorn
empty = ActiveFedora::SimpleDatastream.xml_template.to_xml
mf = MasterFile.find(pid) # Load the MasterFile.
if mf.workflow_id.present?
begin
Rubyhorn.client.stop(mf.workflow_id) # Stop the existing workflow.
rescue # Keep going even if stopping the workflow fails.
end # This means there might be more cleanup later.
end
mf.mhMetadata.content = empty # Remove all Matterhorn-related fields.
@ChadSki
ChadSki / gist:847c99f4342e51541ba5
Last active August 29, 2015 14:08
Rob Pike Interview Excerpt
Interviewer:

Recently on the Google Labs Aptitude Test there was a question: "What's broken with Unix? How would you fix it?"

What would you have put?

Rob Pike:

Ken Thompson and I started Plan 9 as an answer to that question. The major things we saw wrong with Unix when we started talking about what would become Plan 9, back around 1985, all stemmed from the appearance of a network. As a stand-alone system, Unix was pretty good. But when you networked Unix machines together, you got a network of stand-alone systems instead of a seamless, integrated networked system. Instead of one big file system, one user community, one secure setup uniting your network of machines, you had a hodgepodge of workarounds to Unix's fundamental design decision that each machine is self-sufficient.

Nothing's really changed today. The workarounds have become smoother and some of the things we can do with networks of Unix machines are pretty impressive, but when ssh is the foundation of your security architecture, you

@fuzzyalej
fuzzyalej / functional_javascript.js
Last active August 29, 2015 14:16
Functional JS Workshop
function cell(value) {
return {
value: value,
next: null //null is cool
};
}
function cons(value, list) {
var tmp = cell(value);
tmp.next = list || null;
@ysinc88
ysinc88 / controllers.rb
Last active August 29, 2015 14:27
Create json nested attributes
class UsersController < ApplicationController
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
@ryanlecompte
ryanlecompte / gist:3281509
Created August 7, 2012 04:16
ActiveRecord memory leak with multiple threads?
# It appears that when I perform a query with AR via multiple threads,
# the instantiated objects do not get released when a GC is performed.
threads = Array.new(5) { Thread.new { Foo.where(:status => 2).all.first(100).each { |f| f.owner.first_name } } }
threads.each(&:join)
threads = nil
GC.start
ObjectSpace.each_object(Foo).count # => instances still exist
@dre1080
dre1080 / varbinary_migration_columns_initializer.rb
Created August 24, 2012 14:18
Setup varbinary columns or any other unsupported data type in rails migrations
# Provide varbinary columns in a Migration.
# Probably a better way to do this?
#
# Usage:
# => t.varbinary :column, :limit => 20, ....[options]
#
ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
def type_to_sql_with_varbinary(type, limit = nil, precision = nil, scale = nil)
return type_to_sql_without_varbinary(type, limit, precision, scale) unless :varbinary == type.to_sym
  1. Install XCode

  2. Install Command Line Tools from XCode Preferences

  3. Install Homebrew

  4. Install rvm or rbenv

  5. Install Matterhorn dependencies within Homebrew

@shu0115
shu0115 / file0.txt
Created February 27, 2013 11:02
Rails4.0.0.beta1 + ActionController::Live + JavaScript EventSource ref: http://qiita.com/items/9369360774edfcc3c13c
require 'reloader/sse'
class ProgressController < ApplicationController
include ActionController::Live
def index
# SSE expects the `text/event-stream` content type
response.headers['Content-Type'] = 'text/event-stream'
sse = Reloader::SSE.new(response.stream)