Skip to content

Instantly share code, notes, and snippets.

View stevebartholomew's full-sized avatar

Stephen Bartholomew stevebartholomew

View GitHub Profile
func tableView(tableView: NSTableView, acceptDrop info: NSDraggingInfo, row: Int, dropOperation: NSTableViewDropOperation) -> Bool {
var pasteboard = info.draggingPasteboard()
var rowData = pasteboard.dataForType(MyRowType)
if(rowData != nil) {
var dataArray = NSKeyedUnarchiver.unarchiveObjectWithData(rowData!) as! Array<NSIndexSet>,
func tableView(tableView: NSTableView, writeRowsWithIndexes: NSIndexSet, toPasteboard: NSPasteboard) -> Bool {
var data = NSKeyedArchiver.archivedDataWithRootObject([writeRowsWithIndexes])
toPasteboard.declareTypes([MyRowType], owner:self)
toPasteboard.setData(data, forType:MyRowType)
return true
let MyRowType = “MyRowType"
override func viewDidLoad() {
// …
tableView.registerForDraggedTypes([MyRowType, NSFilenamesPboardType])
//…
}
func tableView(tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableViewDropOperation) -> NSDragOperation {
tableView.setDropRow(row, dropOperation: NSTableViewDropOperation.Above)
return NSDragOperation.Move
}
[
{
"name": "Stephen Bartholomew",
"email": "[email protected]",
"age": 34,
"languages": ["Ruby", "Javascript"]
},
{
"name": "Tim Peat",
"email": "[email protected]",
@stevebartholomew
stevebartholomew / gist:1feab9d6fa5128f618c4
Last active June 27, 2020 20:45
Ruby refactoring exercise
class Array
def to_annotated_xml(root)
output = "<#{root}>"
each do |i|
if i.is_a?(Fixnum)
output << "<number>#{i}</number>"
elsif i.is_a?(String)
if i.match(/@/)
output << "<email>#{i}</email>"
@stevebartholomew
stevebartholomew / gist:1639128
Created January 19, 2012 09:56
time a block of ruby code
# Example:
# rendered_content = t("rendering layout") do
# layout.render('item' => self, 'contents' => contents)
# end
#
def t(title, &block)
puts "==========="
puts title
beginning_time = Time.now
result = yield
@stevebartholomew
stevebartholomew / gist:1033077
Created June 18, 2011 12:59
Excluding all but specified files in git
*
!y.php
!x.php
!folder_xy
@stevebartholomew
stevebartholomew / js_test.rake
Created February 22, 2011 11:30
Quick & Dirty JS test runner
# Quick and dirty JS test runner
#
# Required files:
# {testdir}
# /index.html (rails specific sample below)
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
# "http://www.w3.org/TR/html4/loose.dtd">
# <html>
# <head>
# <link rel="stylesheet" href="<%= JS_TEST_BASE %>/qunit.css" type="text/css" media="screen" />