Skip to content

Instantly share code, notes, and snippets.

View lee-dohm's full-sized avatar
😴
Taking some well-deserved naps

Lee Dohm lee-dohm

😴
Taking some well-deserved naps
View GitHub Profile
@lee-dohm
lee-dohm / gist:2993650
Created June 26, 2012 06:01
Proper way to handle path arguments in Ruby methods
def callee(arg)
path = arg.path if arg.respond_to?(:path)
path ||= arg.to_path if arg.respond_to?(:to_path)
path ||= arg.to_str if arg.respond_to?(:to_str)
raise "Invalid path `#{arg}`" unless path
# ... do something with path
end
@lee-dohm
lee-dohm / rscript.R
Created July 18, 2012 18:57 — forked from ssimeonov/rscript.R
Rscript discovery & reloading
rscript.stack <- function()
{
# Returns the stack of Rscript files.
#
# Returns:
# Stack of files.
Filter(Negate(is.null), lapply(sys.frames(), function(x) x$ofile))
}
@lee-dohm
lee-dohm / gist:3439284
Created August 23, 2012 17:40
Detect the debugger using Objective-C on iOS or OS X
#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/sysctl.h>
static bool AmIBeingDebugged(void)
// Returns true if the current process is being debugged (either
// running under the debugger or has a debugger attached post facto).
{
@lee-dohm
lee-dohm / gist:3461122
Created August 25, 2012 05:14
An assembly line in Go
import "fmt"
func main() {
c1 = make(chan string)
c2 = make(chan T)
c3 = make(chan U)
go readStuff(c1)
go parseStuff(c1, c2)
go calculateStuff(c2, c3)
for value := range c4 {
@lee-dohm
lee-dohm / linktastic.css
Created August 25, 2012 20:23 — forked from psyked/linktastic.css
CSS: Automatic link type icons
a[href^="http:"] {
display:inline-block;
padding-right:14px;
background:transparent url(/Images/ExternalLink.gif) center right no-repeat;
}
a[href^="mailto:"] {
display:inline-block;
padding-left:20px;
line-height:18px;
background:transparent url(/Images/MailTo.gif) center left no-repeat;
@lee-dohm
lee-dohm / gist:4103861
Last active October 12, 2015 23:28
License: MIT
The MIT License (MIT)
Copyright © 2013 Lee Dohm, Lifted Studios
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
def hello
puts 'Hello'
end
# a equals nil and prints 'Hello'
a = true && hello
# b equals false
b = false && hello
@lee-dohm
lee-dohm / class-a.java
Last active December 17, 2015 18:29
Code examples for "Dynamic Typing Makes for Testability" article
class A
{
private B b;
public A(B b)
{
this.b = b;
}
public void store()
@lee-dohm
lee-dohm / documented.rb
Last active December 18, 2015 03:59
Code samples for blog article: "The Importance of Documenting Code"
# Indicates whether `color` is a valid SVG color string.
#
# [SVG color descriptions](http://www.w3.org/TR/SVG/types.html#DataTypeColor) are one of the following:
#
# * RGB values
# * `#rgb`
# * `#rrggbb`
# * `rgb(255, 0, 0)` - *not currently supported by KangaRuby*
# * `rgb(100%, 0%, 0%)` - *not currently supported by KangaRuby*
# * [Color names](http://www.w3.org/TR/SVG/types.html#ColorKeywords)
@lee-dohm
lee-dohm / test.rb
Last active December 18, 2015 07:10
Code samples for blog article: "Text File Line Endings"
Get-Content -Encoding byte test.rb