This file contains hidden or 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
#The sum of the squares of the first ten natural numbers is, | |
#12 + 22 + ... + 102 = 385 | |
#The square of the sum of the first ten natural numbers is, | |
#(1 + 2 + ... + 10)2 = 552 = 3025 | |
#Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640. | |
#Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum | |
ruby-1.9.2-p180 :004 > (1..10).to_a.reduce(:+)**2 - (1..10).to_a.map { |x| x**2 }.reduce(:+) | |
=> 2640 | |
ruby-1.9.2-p180 :005 > (1..100).to_a.reduce(:+)**2 - (1..100).to_a.map { |x| x**2 }.reduce(:+) |
This file contains hidden or 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
# Convert ssh-rsa key to pem | |
ssh-keygen -f infile.pub -e -m PKCS8 > outfile.pem | |
# Encrypt a file using public key pem | |
openssl rsautl -encrypt -inkey public.pem -pubin -in file.txt -out file.ssl | |
# Decrypt using private key | |
openssl rsautl -decrypt -inkey private.pem -in file.ssl -out decrypted.txt |
This file contains hidden or 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
require 'prime' | |
Prime.take(10001).last |
This file contains hidden or 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
# Square root calculation using Newton-Raphson | |
# from Practical Programming (1968) | |
a = 256 | |
x = (1 + a) / 2.0 | |
loop do | |
ox = x | |
x = (x + a.to_f / x) / 2.0 |
This file contains hidden or 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
fib=->(n){_=5**0.5;(((1+_)**n-(1-_)**n)/(2**n*_)).to_i} |
This file contains hidden or 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
# ruby getimage.rb -e production -c config/getimage.rb |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# A simply utility to show character counts for each line of input and | |
# highlight lines longer than 80 characters. | |
# | |
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html | |
# | |
# Examples: | |
# | |
# $ hilong Gemfile |
This file contains hidden or 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
SIXTYTWO = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a | |
def to_s_62(i) | |
return '0' if i == 0 | |
s = '' | |
while i > 0 | |
s << SIXTYTWO[i.modulo(62)] | |
i /= 62 | |
end | |
s.reverse |
This file contains hidden or 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 -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf("%0o ",k);print}' |
This file contains hidden or 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
sudo tcpdump -vi eth0 port 53 |