Skip to content

Instantly share code, notes, and snippets.

@bodhi
bodhi / Emacs 23 patch for non-file url drag-n-drop
Created December 19, 2009 10:55
Emacs 23 patch for non-file url drag-n-drop
commit d37cb54df270fd6bd1b7464af2bc3e285079cdc5
Author: bodhi
Date: Sat Dec 19 21:53:27 2009 +1100
Create event when drag-n-dropping non-file URLs on Nextstep
diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el
index 157b2dd..13bd0ac 100644
--- a/lisp/term/ns-win.el
+++ b/lisp/term/ns-win.el
pasokun:myasics bodhi$ ruby -Itest test/m_test.rb
Loaded suite test/m_test
Started
..E
Finished in 0.002001 seconds.
1) Error:
test_mock_should_fail(MTest):
Mocha::ExpectationError: unexpected invocation: #<Object:0x109c3fc30>.to_s()
unsatisfied expectations:
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.0.beta3)
* actionpack (3.0.0.beta3)
* activemodel (3.0.0.beta3)
* activerecord (3.0.0.beta3)
* activeresource (3.0.0.beta3)
* activesupport (3.0.0.beta3)
* arel (0.3.3)
* builder (2.1.2)
irb> x = [1,2,"",3, "", ""]
=> [1, 2, "", 3, "", ""]
irb> x.pop while x.last.blank?
=> nil
irb> x
=> [1, 2, "", 3]
irb> x = [1,2,"",3]
=> [1, 2, "", 3]
class A
def a; "A#a" end
module B
def b; "B#b" end
end
include B
end
@bodhi
bodhi / gist:2780922
Created May 24, 2012 11:32
revert-buffer-with-sudo
(defun revert-buffer-with-sudo ()
"reopen file in current buffer with sudo"
(interactive)
(let* ((filename (buffer-file-name (current-buffer)))
(sudo-filename (concat "/sudo::" filename)))
(kill-buffer)
(find-file sudo-filename)))
@bodhi
bodhi / index.md
Last active May 22, 2018 15:39
Implementation of Elixir's pipeline operator `|>` in Haskell

Elixir's pipeline operator |> apparently passes the result of each step as the first parameter to the next, so

iex> [1, [2], 3] |> List.flatten |> Enum.map(fn x -> x * 2 end)
[2, 4, 6]

is equivalent to

@bodhi
bodhi / gist:8d737af94e2e1063dc0a
Last active August 29, 2015 14:06
iOS 8 Dynamic text CSS sizing

Font Scale

(letter spacing is only correct for non-bold text system setting)

// font: 11px / 13px; letter-spacing: 0.22px
// font: 12px / 16px; letter-spacing: 0.21px;
// font: 13px / 18px; letter-spacing: 0.2px
// font: 14px / 19px; letter-spacing: 0.17px; 0.1px @500
// font: 15px / 20px; letter-spacing: 0.13px; 0.063px @500
@bodhi
bodhi / fizzbuzz.hs
Created October 13, 2014 23:45
Dumb implementation of FizzBuzz
fizz = cycle [[], [], "fizz"]
buzz = cycle [[], [], [], [], "buzz"]
numbers = [1..]
fizzbuzz = zip3 fizz buzz numbers
toFizzBuzz [] [] x = show x
toFizzBuzz fizz buzz x = fizz ++ buzz
@bodhi
bodhi / README.md
Last active August 29, 2015 14:09
Happy Numbers

Implementations of Happy Numbers

Haskell

Simple recursive version that stores the previous steps in the sequence in an array, and checks for duplicates to detect cycles.

Can get up to 250,000,000 numbers in ~5s, with no memoisation:

$ time ./happy_numbers 350000000