Friday, January 29, 2016

Getting Random Line Number -1

Bash line to generate random line number from 1 to max - 1.
echo $(ruby -e 'print rand') $(wc -l < "./lines.txt") | awk '{printf("%d\n", $1*$2)}'

African American Inventors

Henry E. Baker
Benjamin Banneker
James Forten
Ben Montgomery
Norbert Rillieux
Jan Ernst Matzeliger
Elijah McCoy
George Franklin Grant
Lewis Howard Latimer
Granville Woods
Garrett Morgan
George Washington Carver
Madam C. J. Walker
Sarah E. Goode
Sarah Boone
Alice H. Parker
Patricia Bath

Thursday, January 28, 2016

Ruby: Tweeting Using OAuth gem

Package needed:

gem install oauth

Ruby script: tweet.rb

require 'json'
require 'oauth'

consumer_key = '' # Your consumer key
consumer_secret = '' # Your consumer secret
access_token = '' # Your access token
access_token_secret = '' # Your access token secret

consumer = OAuth::Consumer.new(
consumer_key,
consumer_secret,
site:'https://api.twitter.com/'
)
endpoint = OAuth::AccessToken.new(consumer, access_token, access_token_secret)

# STATUS
status = ARGV[0]

# POST
response = endpoint.post('https://api.twitter.com/1.1/statuses/update.json', status: status )
result = JSON.parse(response.body)



Execute the ruby script:

ruby ./tweet.rb "Good morning! (おはようございます。)"

Generating Random Password

Generating 32-character random password

$ cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1

This is the same:

$ cat /dev/urandom | env LC_CTYPE=C tr -dc '[:alnum:]' | fold -w 32 | head -n 1

Generating Random 15-Character User Name

Generating random 15-character:
$ cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-z0-9' | fold -w 15 | head -n 1
This is the same:
$ $ cat /dev/urandom | env LC_CTYPE=C tr -cd '[:lower:][:digit:]' | fold -w 15 | head -n 1

Walter Payton

Walter Payton

Lawrence Taylor: Crack and Cocaine Nearly Ruined His Life

Lawrence Taylor

Lawrence Taylor: NFL MVP

Lawrence Taylor

Lawrence Taylor: Highlights of New York Giants Hall of Fame Linebacker

Lawrence Taylor

Jim Brown: More racism now than any time in history

Jim Brown


  • White supremacy (白人至上主義)

Jim Brown: Greatest Running Back Ever! Compilation

Jim Brown

Jim Brown: Highlights

Jim Brown

Jerry Rice: Rivalry with Deion Sanders

Jerry Rice

Jerry Rice: 1985 NFL Draft: 49ers almost miss out on Hall of Fame wide Receiver

Jerry Rice