Sunday, January 31, 2016

Duration of execution: Comparison Between Perl & C

Perl script counting from 1 to 1,000,000,000:
$ time ./countlargenumber.pl
500000000500000000
real 0m43.157s
user 0m43.013s
sys 0m0.019s


Executable written in C counting from 1 to 1,000,000,000:
$ time ./countlargenumber.out
500000000500000000
real 0m2.057s
user 0m2.028s
sys 0m0.002s

AWK: Extracting the Values of Specified Columns Separated by a Delimiter

Extracting the second column values from lines with delimiter '|' separating each columns:

awk -F'|' '{print $2}' ./lines.txt

Women's rights: Free the Nipple?

Gender equality



  • Gender equality (男女同権)
  • Women's rights
  • Social equality

MD5: Testing Out MD5 Behaviour

MD5 hash using s option:
md5 -s "test string"
MD5 ("test string") = 6f8db599de986fab7a21625b7916589c


MD5 hash using pipe:
echo -n test string | md5
6f8db599de986fab7a21625b7916589c


MD5 hash using pipe, but echo without n option:
echo test string | md5
f299060e0383392ebeac64b714eca7e3

Sed: Replacing Delimiter Characters to Create Comma-Separated Values

Replacing all vertical lines '|' with comma ',':

cat ./lines.txt | sed s/\|/,/g

Saturday, January 30, 2016

AWK: Appending Characters to Each Line

Appending '|' character to the end of each lines:

awk '{print $0"|"}' ./input.txt > ./output.txt

Debugging: Cron: % sign

Error message:

/bin/sh: -c: line 0: unexpected EOF while looking for matching `]'
/bin/sh: -c: line 1: syntax error: unexpected end of file


The source code:

*/10 * * * * perl -le 'sleep rand 60' && head -$[${RANDOM} % `wc -l < /Users/username/lines.txt` + 1] /Users/username/lines.txt | tail -1 | ruby /Users/username/tweet.rb

Crontab man page:

The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. Percent-signs (%) in the command, unless escaped with backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

Fixed source code:

*/10 * * * * perl -le 'sleep rand 60' && head -$[${RANDOM} \% `wc -l < /Users/username/lines.txt` + 1] /Users/username/lines.txt | tail -1 | ruby /Users/username/tweet.rb

Friday, January 29, 2016

Cron: Tweet a Line Every 10-19 Minutes

Cron - Tweet a line every 30-40 mins:

*/10 * * * * perl -le 'sleep rand 540' && head -$[${RANDOM} \% `wc -l < /Users/username/lines.txt` + 1] /Users/username/lines.txt | tail -1 | ruby /Users/username/lines.rb

lines.rb - using standard input:

require 'json'
require 'oauth'

consumer_key = ''
consumer_secret = ''
access_token = ''
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 = STDIN.gets

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

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

Wednesday, January 27, 2016

Sara Takanashi (高梨沙羅): 女王復活にかける高梨沙羅の本音

Sara Takanashi

Japan vs. Iran (日本×イラン): 2016 AFC U-23 Championship (AFC U-23選手権2016): Quarterfinal (準々決勝): January 22, 2016 (2016年1月22日)

Swift: Adding Sample to Health Store

Swift
@IBAction func addPotassiumTapped(sender : AnyObject){

let potassiumType = HKQuantityType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDietaryPotassium)

let potassiumQuantity = HKQuantity(unit: HKUnit.gramUnit(), doubleValue: 0.0055)

let potassiumSample = HKQuantitySample(type: potassiumType!, quantity: potassiumQuantity, startDate: NSDate(), endDate: NSDate())

let healthKitStore:HKHealthStore = HKHealthStore()

healthKitStore.saveObject(potassiumSample, withCompletion: { (success, error) -> Void in

if( error != nil ) {

print("Error saving Potassium sample: \(error!.localizedDescription)")

} else {

print("Potassium sample saved successfully!")

}
})
}

Who Ever Said No Two Snowflakes Were Alike?

Tuesday, January 26, 2016

Swift: Request Authorization to Dietary Potassium Data

Swift

@IBOutlet weak var aButton: UIButton!

@IBAction func buttonTapped(sender : AnyObject){

let healthKitStore:HKHealthStore = HKHealthStore()

let healthKitTypesToWrite = Set(
arrayLiteral: HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierDietaryPotassium)! )

healthKitStore.requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes:nil){ (success, error) -> Void in
if success == false {
}
}

}

Swift: Display an alert

Swift
@IBOutlet weak var aButton: UIButton!

@IBAction func buttonTapped(sender : AnyObject){

let alertController = UIAlertController(title: "My alert", message:

"This is an alert!", preferredStyle: UIAlertControllerStyle.Alert)

alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))

self.presentViewController(alertController, animated: true, completion: nil)
}

Leonard Susskind: Eternal Inflation of a Cosmic Landscape

Sunday, January 24, 2016

Saturday, January 23, 2016

Eddi Reader: Ae Fond Kiss

Eddi Reader

Janis Ian: Society's Child (1967)

Janis Ian

Janis Ian: At Seventeen (Live, 1976)

Janis Ian

Jesse Puljujärvi: 2015 IIHF WJC Highlights

Jesse Puljujärvi

Billy Corgan: Reverend BC1 Signature Guitar

Billy Corgan

Billy Corgan: Enough Misogyny In Pro Wrestling, Women Are Badass Too

Billy Corgan

Joe Hisaishi (久石譲): Summer

Joe Hisaishi

Frozen soap bubbles

Ding Ning (丁寧): WTTC 2015 Highlights: DING Ning vs LIU Shiwen (FINAL)

Ding Ning

Jacqueline Goordial: Nearing the cold-arid limits of microbial life in permafrost of an upper dry valley, Antarctica

Jacqueline Goordial
Some of the coldest and driest permafrost soils on Earth are located in the high-elevation McMurdo Dry Valleys (MDVs) of Antarctica, but little is known about the permafrost microbial communities other than that microorganisms are present in these valleys. Here, we describe the microbiology and habitable conditions of highly unique dry and ice-cemented permafrost in University Valley, one of the coldest and driest regions in the MDVs (1700 m above sea level; mean temperature −23 °C; no degree days above freezing), where the ice in permafrost originates from vapour deposition rather than liquid water. We found that culturable and total microbial biomass in University Valley was extremely low, and microbial activity under ambient conditions was undetectable. Our results contrast with reports from the lower-elevation Dry Valleys and Arctic permafrost soils where active microbial populations are found, suggesting that the combination of severe cold, aridity, oligotrophy of University Valley permafrost soils severely limit microbial activity and survival.
http://www.nature.com/ismej/journal/vaop/ncurrent/full/ismej2015239a.html