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
puts UDPSocket.open { |s| s.connect('www.example.com', 1); s.addr.last } |
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
#include <stdio.h> | |
#define TWO_TO_THE(POWER) (1 << POWER) | |
#define JTH_BIT(BITS, J) ((TWO_TO_THE((J-1)) & BITS) != 0) | |
int main(int argc, char *argv[]) { | |
printf("JTH_BIT(8, 1) = %d\n", JTH_BIT(8, 1)); | |
printf("JTH_BIT(8, 2) = %d\n", JTH_BIT(8, 2)); | |
printf("JTH_BIT(8, 3) = %d\n", JTH_BIT(8, 3)); | |
printf("JTH_BIT(8, 4) = %d\n", JTH_BIT(8, 4)); |
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
#!/bin/bash | |
# extract IP addresses from ifconfig command using Perl | |
if [ "$1" = "-v6" ]; then | |
ifconfig | perl -ne '/inet6 addr: (([0-9a-f]*:?)*\/\d+)/ && print "$1\n"' | |
else | |
ifconfig | perl -ne '/addr:((\d{1,3}\.?){4})/ && print "$1\n"' | |
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
Verifying myself: My Bitcoin username is +tlehman. https://onename.io/tlehman |
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 gpa(grades) | |
points = {:A => 4.0, :B => 3.0, :C => 2.0, :D => 1.0, :F => 0} | |
grade_values = grades.merge(points) { |grade,value,number| (number.to_f)*value } | |
numer = grades.values.inject(:+).to_f | |
denom = grade_values.values.inject(:+).to_f | |
((numer/denom)*10).round(3) | |
end | |
# ==> nil |
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
a = proc { return 1 } | |
# ==> #<Proc:0x007f96d280a118@(irb):1> | |
b = lambda { return 1 } | |
# ==> #<Proc:0x007f96d3002438@(irb):3 (lambda)> | |
a.call | |
# =LocalJumpError: unexpected return | |
# = from (irb):1:in `block in irb_binding' | |
# = from (irb):5:in `call' |
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
#!/bin/sh | |
curl -s https://multco.us/elections/november-2014-general-election-results | ruby -e 'STDIN.readlines.each {|line| puts line if /<pre>/ =~ line .. /<\/pre>/ =~ line }' |
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
# Starting with a simple String object: | |
hello = "Hello, World" | |
def output_class_hierarchy(object) | |
o = object | |
while o.class!=Class || (o != nil && o != NilClass) | |
if o.is_a? Class | |
puts " #{o} -> #{o.superclass.inspect} [label=superclass,color=red];" | |
o = o.superclass | |
else |
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
→ ls | |
file1.txt file14.txt file19.txt file23.txt file28.txt file32.txt file37.txt file41.txt file46.txt file50.txt file55.txt file6.txt | |
file10.txt file15.txt file2.txt file24.txt file29.txt file33.txt file38.txt file42.txt file47.txt file51.txt file56.txt file7.txt | |
file11.txt file16.txt file20.txt file25.txt file3.txt file34.txt file39.txt file43.txt file48.txt file52.txt file57.txt file8.txt | |
file12.txt file17.txt file21.txt file26.txt file30.txt file35.txt file4.txt file44.txt file49.txt file53.txt file58.txt file9.txt | |
file13.txt file18.txt file22.txt file27.txt file31.txt file36.txt file40.txt file45.txt file5.txt file54.txt file59.txt | |
~/tmp/files 2014-11-26 12:09:55 | |
→ for f in $(ls); do newnum=$(ruby -e "/file(?<num>\d+).txt/ =~ '$f'; puts num.rjust(2,'0')"); mv $f file$newnum.txt; done | |
mv: ‘file10.txt’ and ‘file10.txt’ are the same file | |
mv: ‘file11.txt’ and ‘file11.txt’ are the same file |
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
git log --pretty="%H" --follow main.py | for commit in $(cat -); do git show $commit; read; done |
OlderNewer