Friday, October 30, 2015

get the grs v1 site up and running on imac27




perl-mysql


##################################################
# create local mysql db
##################################################
create database groundschool;
GRANT ALL PRIVILEGES ON groundschool .* TO grs@'%' IDENTIFIED BY 'grs';
GRANT ALL PRIVILEGES ON groundschool .* TO grs@'localhost' IDENTIFIED BY 'grs';
flush privileges;
show grants for grs;


##################################################
# httpd.conf
##################################################
[smr@smr ~]$ bbedit /private/etc/apache2/httpd.conf

# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf


##################################################
# httpd-vhosts.conf
##################################################
[smr@smr ~]$ bbedit /private/etc/apache2/extra/httpd-vhosts.conf

#groundschool-alt.com.local
<VirtualHost *:80>
  <Directory /Users/smr/Sites/groundschool-alt.com/html/>
    Options +FollowSymlinks +SymLinksIfOwnerMatch
    AllowOverride All
  </Directory>
    DocumentRoot "/Users/smr/Sites/groundschool-alt.com/html/"
  ScriptAlias /cgi-bin/ "/Users/smr/Sites/groundschool-alt.com/cgi-bin/"
    ServerName groundschool-alt.local
    ErrorLog "/private/var/log/apache2/groundschool-alt.local-error_log"
    CustomLog "/private/var/log/apache2/groundschool-alt.local-access_log" common
</VirtualHost>


##################################################
# hosts
##################################################
[smr@smr ~]$ bbedit /private/etc/hosts

127.0.0.1 groundschool-alt.local


Thursday, October 29, 2015

install ruby 1.9.3 on osx 10.10. yosemite 10-29-15

awhile back i attempted this without success, but now it looks like there are some patches applied as part of the install and the install succeeds.


Last login: Mon Oct 26 17:26:44 on ttys001
[smr@macbook ~]$ rvm list

rvm rubies

   ruby-2.2.0 [ x86_64 ]
=* ruby-2.2.2 [ x86_64 ]

# => - current
# =* - current && default
#  * - default


[smr@macbook ~]$ rvm install 1.9.3
ruby-1.9.3-p551 - #removing src/ruby-1.9.3-p551..
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.10/x86_64/ruby-1.9.3-p551.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
==> Upgrading 2 outdated packages, with result:
libksba 1.3.3, openssl 1.0.2d_1
==> Upgrading libksba
==> Installing libksba dependency: libgpg-error
==> Downloading https://homebrew.bintray.com/bottles/libgpg-error-1.19.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libgpg-error-1.19.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/libgpg-error/1.19: 17 files, 352K
==> Installing libksba
==> Downloading https://homebrew.bintray.com/bottles/libksba-1.3.3.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libksba-1.3.3.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/libksba/1.3.3: 12 files, 372K
==> Upgrading openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2d_1.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2d_1.yosemite.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2d_1: 464 files, 18M
Certificates in '/usr/local/etc/openssl/cert.pem' are already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/smr/.rvm/rubies/ruby-1.9.3-p551, this may take a while depending on your cpu(s)...
ruby-1.9.3-p551 - #downloading ruby-1.9.3-p551, this may take a while depending on your connection...
ruby-1.9.3-p551 - #extracting ruby-1.9.3-p551 to /Users/smr/.rvm/src/ruby-1.9.3-p551....
ruby-1.9.3-p551 - #applying patch /Users/smr/.rvm/patches/ruby/GH-488.patch.
ruby-1.9.3-p551 - #applying patch /Users/smr/.rvm/patches/ruby/1.9.3/CVE-2015-1855-p484.patch.
ruby-1.9.3-p551 - #configuring...............................................
ruby-1.9.3-p551 - #post-configuration.
ruby-1.9.3-p551 - #compiling...............................................................................................|
ruby-1.9.3-p551 - #installing...........
ruby-1.9.3-p551 - #making binaries executable..
ruby-1.9.3-p551 - #downloading rubygems-2.4.8
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  437k  100  437k    0     0   226k      0  0:00:01  0:00:01 --:--:--  226k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-1.9.3-p551 - #extracting rubygems-2.4.8....
ruby-1.9.3-p551 - #removing old rubygems.........
ruby-1.9.3-p551 - #installing rubygems-2.4.8......................
ruby-1.9.3-p551 - #gemset created /Users/smr/.rvm/gems/ruby-1.9.3-p551@global
ruby-1.9.3-p551 - #importing gemset /Users/smr/.rvm/gemsets/global.gems...............................................
ruby-1.9.3-p551 - #generating global wrappers........
ruby-1.9.3-p551 - #gemset created /Users/smr/.rvm/gems/ruby-1.9.3-p551
ruby-1.9.3-p551 - #importing gemsetfile /Users/smr/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-1.9.3-p551 - #generating default wrappers........
ruby-1.9.3-p551 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-1.9.3-p551 - #complete
WARNING: Please be aware that you just installed a ruby that is no longer maintained (2014-02-23), for a list of maintained rubies visit:

    http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering

Please consider upgrading to ruby-2.2.2 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri
[smr@macbook ~]$

extract audio from a video file using vlc on the command line; mp3






/Applications/VLC.app/Contents/MacOS/VLC -I dummy "/Users/smr/Desktop/e-dancing.m4v" --sout='#transcode{acodec=mp3,vcodec=dummyvcodec}:standard{access=file,mux=raw,dst="/Users/smr/Desktop/test2.mp3"}' vlc://quit



Wednesday, October 28, 2015

multi-line description in an advanced installer updates.txt file



;aiu;

[2016_100]
Name = Prepware 2016_100
ProductVersion = 16.1.0
URL = http://updates.prepware.com.s3.amazonaws.com/Install_Prepware_2016_100_win.exe
Size = 356235776
MD5 = 03ad573db06a698a995d13b24d052d60
ServerFileName = Install_Prepware_2016_100_win.exe
Flags = NoCache
RegistryKey = HKUD\Software\ASA\Prepware\Version
Version = 16.1.0
Description = This updater will update your installation of Prepware 2016 to version 2016_100.
Description1 = <b>Note for Prepware 2014 Users:</b> ASA provides updates for 2 years. Prepware 2014 is no longer supported with updates. If you must access the question databases represented by your old activation(s), do not do run update because it is going to remove all access to this old activation.
Feature = 10-2015 question databases
AutoCloseApplication = [APPDIR]Prepware.exe|;Prepware


Monday, October 26, 2015

add-android-metadata-to-db.pl



#!/usr/bin/perl -w
use strict;
use File::Find;
# dbs used by devices need an "android metadata table"
# sqlite> .schema
# CREATE TABLE android_metadata (locale TEXT);
use strict;
use DBI;


my $path = shift @ARGV;
die "please specify a path\n" unless $path;

find(\&wanted, $path);

sub wanted
{
if (/falcon\.db/)
{
my $filename = $_; #filename
my $full_path = $File::Find::name; #full path
my $dir = $File::Find::dir; #containing directory
print "processing $full_path\n";

my $path_to_db = $filename;
my $table_name = "android_metadata";
my $dbh = DBI->connect("dbi:SQLite:dbname=$path_to_db","","",{ AutoCommit => 0 }) or die $DBI::errstr;

#create table
$dbh->do( "drop table if exists $table_name" );
$dbh->do( "create table $table_name (locale TEXT)" );
$dbh->do( "insert into $table_name values('en_US')" );
$dbh->commit or die $dbh->errstr;
$dbh->disconnect();
}
}









python script to colorize logcat output

Thursday, October 22, 2015

pwo updates 10-2015 - verify pwo changes


these two tools are useful for verifying changes:
http://pwo-dev.prepware.com/testmaps
http://pwo-dev.prepware.com/topics_map


Turboprop (added) testmap

1.9.3-p286 :010 > y QuizDefinition.find_by_name("Turboprop (added)").testmap
---
1: 0
2: 0
3: 0
4: 8
5: 10
6: 10
7: 0
8: 0
9: 6
10: 5
11: 0
12: 0
13: 11

 => nil 

pvt chapter 11

1.9.3-p286 :008 > y Book.find_by_title("Private Pilot").chapters.find_by_chapnum(11).topics
---
- !ruby/object:Topic
  attributes:
    id: 741
    topicnum: 1
    title: Phraseology, Techniques, and Procedures
    chapter_id: 104
- !ruby/object:Topic
  attributes:
    id: 742
    topicnum: 2
    title: Airport Traffic Area Communications and Light Signals
    chapter_id: 104
- !ruby/object:Topic
  attributes:
    id: 743
    topicnum: 3
    title: Radar Assistance to VFR Aircraft
    chapter_id: 104
- !ruby/object:Topic
  attributes:
    id: 744
    topicnum: 4
    title: Transponder
    chapter_id: 104
- !ruby/object:Topic
  attributes:
    id: 745
    topicnum: 5
    title: Emergency Locator Transmitter (ELT)
    chapter_id: 104


atp chapter 5

1.9.3-p286 :009 > y Book.find_by_title("Airline Transport Pilot").chapters.find_by_chapnum(5).topics
---
- !ruby/object:Topic
  attributes:
    id: 53
    topicnum: 1
    title: Center of Gravity Computation
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 54
    topicnum: 2
    title: Stabilizer Trim Setting
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 55
    topicnum: 3
    title: Changing Loading Conditions
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 56
    topicnum: 4
    title: C208 Weight and Balance
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 57
    topicnum: 5
    title: Beech 1900 Weight and Balance
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 58
    topicnum: 6
    title: Helicopter Weight and Balance
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 59
    topicnum: 7
    title: ! 'Helicopter Weight and Balance: CG Shifts'
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 60
    topicnum: 9
    title: ! 'Helicopter Weight and Balance: Load Limits'
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 61
    topicnum: 9
    title: ! 'Helicopter Weight and Balance: Lateral CG'
    chapter_id: 49
- !ruby/object:Topic
  attributes:
    id: 62
    topicnum: 10
    title: Floor Loading Limits
    chapter_id: 49
 => nil 
1.9.3-p286 :010 > 



prepware updates 10-2015 - change Turboprop (added) testmap

falcon failed integrity checks.
cause: Turboprop (added) testmap.


old:
1.9.3-p286 :004 > y QuizDefinition.find_by_name("Turboprop (added)").testmap

1: 0
2: 1
3: 0
4: 8
5: 10
6: 10
7: 0
8: 0
9: 5
10: 5
11: 0
12: 0

13: 11

at the moment, have to do this by hand.
log onto dev.
RAILS_ENV=staging bundle exec rails console


1.9.3-p286 :010 > QuizDefinition.find_by_name("Turboprop (added)").test_map_entries.find_by_chapnum(2).update_attributes!(numq:0)
1.9.3-p286 :011 > QuizDefinition.find_by_name("Turboprop (added)").test_map_entries.find_by_chapnum(9).update_attributes!(numq:6)

new:
1.9.3-p286 :004 > y QuizDefinition.find_by_name("Turboprop (added)").testmap

1: 0
2: 0
3: 0
4: 8
5: 10
6: 10
7: 0
8: 0
9: 6
10: 5
11: 0
12: 0
13: 11

Wednesday, October 21, 2015

prepware updates 10-2015 - tweaks to fix discontiguous topic numbers


SELECT * FROM questions WHERE db_identifier='pvt' AND asachapter='11' AND topicnumber='4'

UPDATE `questions` set `topicnumber`=3 WHERE db_identifier='pvt' AND asachapter='11' AND topicnumber='4'
UPDATE `questions` set `topicnumber`=4 WHERE db_identifier='pvt' AND asachapter='11' AND topicnumber='5'
UPDATE `questions` set `topicnumber`=5 WHERE db_identifier='pvt' AND asachapter='11' AND topicnumber='6'

private chapter 11

11 1 Phraseology, Techniques, and Procedures
11 2 Airport Traffic Area Communications and Light Signals
11 3 Radar Assistance to VFR Aircraft
11 4 Transponder
11 5 Emergency Locator Transmitter (ELT)

atp chapter 5

changed my tab-delimited text (i use this to import topics into falcon) to:
5          1          Center of Gravity Computation
5          2          Stabilizer Trim Setting
5          3          Changing Loading Conditions
5          4          C208 Weight and Balance
5          5          Beech 1900 Weight and Balance
5          6          Helicopter Weight and Balance
5          7          Helicopter Weight and Balance: CG Shifts
5          8          Helicopter Weight and Balance: Load Limits
5          9          Helicopter Weight and Balance: Lateral CG
5          10        Floor Loading Limits



Friday, October 16, 2015

batch file that gets a reg key value



reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ASA\Prepware /v Version
pause




Friday, October 9, 2015

create activerecord text column with size limit larger than 65k


  def self.up
    # create_table(:far_sections, :options => 'ENGINE=MyISAM DEFAULT CHARSET=utf8') do |t|
    create_table :far_sections do |t|
      t.integer :part_id
      t.integer :subpart_id
      t.string :sectiontype
      t.string :sectionnum
      t.text :title
      t.text :html, limit: 4.megabytes   #The default value of limit is 65535

      t.timestamps
    end
    execute 'CREATE FULLTEXT INDEX fulltext_far_sections ON far_sections (html)'
  end

  def self.down
    drop_table(:far_sections)
  end

end

activerecord specify tablename

http://stackoverflow.com/questions/4613574/how-do-i-explicitly-specify-a-models-table-name-mapping-in-rails
  def self.up
    create_table(:shazbat) do |t|
      t.string :name
      t.text :info

      t.timestamps
    end
    execute 'CREATE FULLTEXT INDEX fulltext_people ON shazbat (info)'
  end
class Person < ActiveRecord::Base
  self.table_name = "shazbat"
  attr_accessible :info, :name
end

Wednesday, October 7, 2015

rails 3.2.22 mysql FULLTEXT search and boolean mode


http://stackoverflow.com/questions/3923891/ruby-on-rails-migration-change-table-to-myisam

http://stackoverflow.com/questions/1039512/mysql-full-text-search-in-ruby-on-rails

http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html

class CreatePeople < ActiveRecord::Migration
  # def change
  #   create_table(:people, :options => 'ENGINE=MyISAM DEFAULT CHARSET=utf8') do |t|
  #     t.string :name
  #     t.text :info

  #     t.timestamps
  #   end
  #   # this way gives an 'without a key length' mysql error
  #   # add_index(:people, :name, type: :fulltext)

  #   # specifying an index name
  #   # execute 'CREATE FULLTEXT INDEX fulltext_person_info ON people (info)'
  #   execute 'CREATE FULLTEXT INDEX ON people (info)'
  # end

  def self.up
    create_table(:people, :options => 'ENGINE=MyISAM DEFAULT CHARSET=utf8') do |t|
      t.string :name
      t.text :info

      t.timestamps
    end
    execute 'CREATE FULLTEXT INDEX fulltext_people ON people (info)'
  end

  def self.down
    # execute 'DROP INDEX fulltext_people ON people'
    drop_table(:people)
  end

end
# index added using MySQL

# http://stackoverflow.com/questions/3923891/ruby-on-rails-migration-change-table-to-myisam
# http://stackoverflow.com/questions/1039512/mysql-full-text-search-in-ruby-on-rails


# I created a project (Rails 2.3.2, Ruby 1.9.1 MySQL 5.0) to emulate this.
# With one record in the database, I got the same results you did. When I
# added more records, the Photo.search command found the record.

# This could be because "words that are present in 50% or more of the rows are
# considered common and do not match". Ref.

# The 50% threshold does not apply in binary mode. Ref.

# IN BINARY MODE belongs inside the parentheses: AGAINST ('baceno' IN BOOLEAN
# MODE)


# 2.2.2 :013 > Person.find_by_sql("select * from people where match(info) against('Lorem' in boolean mode)")
#   Person Load (0.3ms)  select * from people where match(info) against('Lorem' in boolean mode)
#  => [#<Person id: 2, name: "fdfdfd", info: "Lorem ipsum dolor sit amet, consectetur adipisicing...", created_at: "2015-10-06 21:54:41", updated_at: "2015-10-06 21:54:41">, #<Person id: 3, name: "fdfdfd", info: "Lorem ipsum dolor sit amet, consectetur adipisicing...", created_at: "2015-10-06 21:54:41", updated_at: "2015-10-06 21:54:41">, #<Person id: 4, name: "fdfdfd", info: "Lorem ipsum dolor sit amet, consectetur adipisicing...", created_at: "2015-10-06 21:54:41", updated_at: "2015-10-06 21:54:41">, #<Person id: 5, name: "fdfdfd", info: "Lorem ipsum dolor sit amet, consectetur adipisicing...", created_at: "2015-10-06 21:54:41", updated_at: "2015-10-06 21:54:41">] 


# another approach to fix the "Mysql::Error: BLOB/TEXT column 'column-name'
# used in key specification without a key length": adjust the way the schema.rb file is generated.
# http://stackoverflow.com/questions/5147827/full-text-mysql-search-in-rails
# http://ablogaboutcode.com/2010/11/21/fulltext-index-and-spatial-index-mysql-compatible-rake-tasks/


##################################################
# boolean operators 
##################################################
# 2.2.2 :008 > Person.find_by_sql(["select * from people where match(info) against(? in boolean mode)", "+assumenda autem"]).count
#   Person Load (0.7ms)  select * from people where match(info) against('+assumenda autem' in boolean mode)
#  => 26 


Friday, October 2, 2015

ruby HoA - hash of arrays

#!/usr/bin/env ruby

items = %w(one two three one one two)
seen = {}
# step 1: init the seen hash keys
items.each { |item|
  seen[item] = []
}
# step 2: push items onto the arrays
items.each { |item|
  seen[item] << item
}

p seen

# [smr@smr Desktop]$ ./test.rb
# {"one"=>["one", "one", "one"], "two"=>["two", "two"], "three"=>["three"]}