This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gitmergeopen() { | |
eval "$EDITOR \$(git diff --name-status --diff-filter=U | sed -re 's/^.+\s//')" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gitopen() { | |
if [ -z $1 ]; then # Open all changed files | |
eval "$EDITOR \$(git status --porcelain --untracked-files=all | sed -re 's/^.+\s//')" | |
else # All files changed in the last number of specified commits | |
eval "$EDITOR \$(git show -$1 --name-only --oneline | sed -re '/^.*[0-9]+.*/d')" | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Expects characters to be separated by a single space, with words separated by three spaces. | |
def morse_to_eng(morse) | |
t,r,n = [32,69,84,73,65,78,77,83,85,82,87,68,75,71,79,72,86,70,95,76,95,80,74,66,88,67,89,90,81,95,95],[],0 | |
morse.bytes do |b| | |
n = case b | |
when 46, 45 then 2 * n + 1 + (46 - b) | |
else r << t[n] unless n == 0 && r[-1] == 32; 0 | |
end | |
end | |
r.pack('c*') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim $(git show --name-only --oneline | sed -re "/^[0-9]+.*/d") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim $(git status --porcelain --untracked-files=all | sed -re "s/^.+\s//") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Finds longest palindromic substring in O(m*n) time | |
def find_longest_palindrome(string) | |
matrix, s, size = {}, string.reverse, string.size | |
0.upto(size-1) do |x| | |
0.upto(size-1) do |y| | |
matrix[[x,y]] = (matrix[[x-1,y-1]] || 0) + 1 if string[x] == s[y] | |
end | |
end | |
string[matrix.key(m=matrix.values.max).first-m+1, m] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def xor(key) | |
''.tap do |result| | |
self.size.times do |n| | |
result << (self[n].ord ^ key[n % key.size].ord).chr | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_longest_palindrome(string) | |
(string.length/2).downto(1) do |i| | |
backrefs = "\\#{(-i..-1).map(&:abs).join("\\").sub(i.to_s, "#{i}?")}" | |
string.scan(/#{'(.)'*i}(#{backrefs})/).tap do |a| | |
return a.take(i).join unless a.empty? | |
end | |
end | |
end |