Skip to content

Instantly share code, notes, and snippets.

View JEG2's full-sized avatar

James Edward Gray II JEG2

View GitHub Profile
s = "james"
subs = (1..s.size).inject([ ]) { |a, l| a.push(*s.split("").each_cons(l)) }
p subs
#!/usr/bin/env ruby -w
require "enumerator"
require "pstore"
prefs = PStore.new(
File.expand_path("~/Library/Preferences/com.macromates.textmate.add_whit")
)
scope = ENV["TM_PROJECT_DIRECTORY"] || ENV["TM_FILEPATH"] || :global
used = prefs.transaction(true) { prefs[scope] || 0 }
class TNT
class Timer
def initialize
@time_left = 42
end
def time_left
@time_left -= 1
end
end
@JEG2
JEG2 / keybindings.el
Created March 25, 2012 22:32
An attempt to duplicate one of my favorite TextMate commands in Emacs.
(defun jeg2s-duplicate-line-or-region ()
"Duplicate the current region, or line, and leave it selected."
(interactive)
(unless (region-active-p)
(unless (bolp)
(beginning-of-line))
(set-mark-command nil)
(next-line))
(kill-region (region-beginning) (region-end))
(yank)
@JEG2
JEG2 / keybindings.el
Created March 26, 2012 15:02
I'm trying to understand how to write a command that leaves an active region.
(defun jeg2s-yank-and-select ()
"This is a test command for how to create a selection."
(interactive)
(kill-new "selected")
(yank)
;; what can I replace to following with to activate the selection
(exchange-point-and-mark))
(global-set-key (kbd "C-c y") 'jeg2s-yank-and-select)
@JEG2
JEG2 / keybindings.el
Created March 26, 2012 15:27
This is a solution, but it seems non-ideal.
(defun jeg2s-yank-and-select ()
"This is a test command for how to create a selection."
(interactive)
(kill-new "selected")
(yank)
;; the following works, but I would like to be able to do it without a macro
(kmacro-exec-ring-item (quote ("" 0 "%d")) nil))
(global-set-key (kbd "C-c y") 'jeg2s-yank-and-select)
@JEG2
JEG2 / keybindings.el
Created March 26, 2012 16:51
This works when there is an active region, but fails to leave the selection when it defaults to using the whole line.
;; Vim's o and O
(defun jeg2s-newline-below (skip-eol)
"Insert a new line below the current line and indent it."
(interactive "P")
(unless (or (eolp) skip-eol)
(end-of-line))
(newline-and-indent))
(global-set-key (kbd "C-c o") 'jeg2s-newline-below)
(defun jeg2s-newline-above ()
"Insert a new line above the current line and indent it."
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.
/Users/james/.rvm/rubies/ruby-1.9.2-p136/bin/ruby extconf.rb
creating Makefile
CFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -mdynamic-no-pic -std=gnu99 -Os -pipe -Wmissing-prototypes -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-parameter -Wunused-variable -Wunused-value -Wuninitialized -Wunknown-pragmas -Wshadow -Wfour-char-constants -Wsign-compare -Wnewline-eof -Wconversion -Wshorten-64-to-32 -Wglobal-constructors -pedantic' /usr/bin/clang -isysroot /Applications/Xcode.app/Contents/Developer/SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -mdynamic-no-pic -std=gnu99 -dead_strip -framework CoreServices -o '/Users/james/.rvm/gems/ruby-1.9.2-p136@aep/gems/rb-fsevent-0.4.3.1/bin/fsevent_watch' fsevent/fsevent_watch.c
fseve
@JEG2
JEG2 / tweet_oge_price_signal.rb
Created August 1, 2012 19:20
A simple bot for tweeting OGE's daily price signal
require "rest_client"
require "twitter"
URL = "http://www.oge.com/residential-customers/products-and-services/" +
"Positive-Energy-Smart-Grid/Pages/PriceSignal.aspx"
DATE_RE = Time.now.strftime("%A,\\s+%B\\s+%d,\\s+%Y")
unless ARGV.size == 4
abort "USAGE: #{$PROGRAM_NAME} CONSUMER_KEY CONSUMER_SECRET " +
"OAUTH_TOKEN OAUTH_TOKEN_SECRET"
@JEG2
JEG2 / fizzbuzz.rb
Created August 1, 2012 21:07
Writing FizzBuzz without modulus division
fizz = [nil, nil, "Fizz"].cycle
buzz = [nil, nil, nil, nil, "Buzz"].cycle
numbers = 1..100
numbers.zip(fizz, buzz) do |n, f, b|
fizzbuzz = [f, b].join
puts(fizzbuzz.empty? ? n : fizzbuzz)
end