Skip to content

Instantly share code, notes, and snippets.

View let.tcl
#!/usr/bin/env TEST=1 tclsh
proc let {block args} {
try {
set captured_vars [uplevel [list capture [block args]]]
set all_var_names [uplevel {info vars}]
foreach var [block args] value $args {
uplevel [list catch [list unset $var]]
uplevel [list set $var $value]
View git-track
#!/bin/sh
branch=$(git branch 2>/dev/null | grep ^\*)
[ x$1 != x ] && tracking=$1 || tracking=${branch/* /}
git config branch.$tracking.remote origin
git config branch.$tracking.merge refs/heads/$tracking
echo "tracking origin/$tracking"
View gist:42974
require "tcl"
module Tcl
class ExprEvaluator
def initialize
@interp = Tcl::SafeInterp.new
commands = @interp.list_to_array(@interp._!(:info, :commands)) - %w(info set unset rename expr)
(commands + %w(rename)).each { |command| @interp._!(:rename, command, "") }
end
View gist:64431
H:\Projects\sprockets>rake
C:/ruby/bin/ruby -Ilib;test "C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader.rb" "test/test_concatenation.rb" "test/test_environment.rb" "test/test_helper.rb" "test/test_pathname.rb" "test/test_preprocessor.rb" "test/test_secretary.rb" "test/test_source_file.rb" "test/test_source_line.rb"
(in H:/Projects/sprockets)
Loaded suite C:/ruby/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake/rake_test_loader
Started
.E.F.EFFFFF..........E.E.EEEFFE......F............
Finished in 2.922 seconds.
1) Error:
test_save_to(ConcatenationTest):
View gist:70357
var BackgroundIteration = Class.create({
initialize: function(iterator, produceNextValue) {
this.iterator = iterator;
this.produceNextValue = produceNextValue;
this.callbacks = [];
this.results = [];
this.next = this.next.bind(this);
this.next.defer();
},
View gist:72527
def extract_options_from(arguments)
arguments.values_at *(indexes_for(arguments) - argument_indexes_for(arguments))
end
def extract_arguments_from(arguments)
arguments.values_at *argument_indexes_for(arguments)
end
def indexes_for(arguments)
(0...arguments.length).to_a
View gist:105760
# Back up your iTunes library to S3
git clone git://github.com/sstephenson/mackerel.git
ruby -rubygems mackerel/examples/itunes_backup.rb amazon-s3://YOUR_ACCESS_KEY_ID:YOUR_SECRET_ACCESS_KEY@s3.amazonaws.com/YOUR_BUCKET_NAME/itunes.mackerel
View gist:107031
var DateHelper = {
timeAgoInWords: function(from) {
return this.distanceOfTimeInWords(new Date(), from);
},
distanceOfTimeInWords: function(to, from) {
var distance_in_seconds = ((to - from) / 1000);
var distance_in_minutes = (distance_in_seconds / 60).floor();
if (distance_in_minutes <= 0) return "less than a minute";
View harpers.rb
# A library for downloading issues of Harpers from the archives.
#
# To use, log in to the archives from your web browser. Then set the
# HARPERS_ARCHIVE_COOKIE environment variable to the value of the .harpers.org
# "archive" cookie, which you can find by visiting the following URL while on
# the Harpers website:
#
# javascript:prompt("HARPERS_ARCHIVE_COOKIE",document.cookie.match(/(?:;|^)\s*archive=(.+?)(?:;|$)/)[1])
#
# Example:
View gist:109704
module Tcl
class << self
# Returns a well-formed Tcl list from the given array of strings.
def array_to_list(array)
array.map { |element| string_to_word(element.to_s) }.join(" ")
end
# Returns a well-formed Tcl word from the given string.
def string_to_word(string)
should_be_braced?(string) ? brace_string(string) : escape_string(string)