Sunday, October 19, 2014

hackerrank scala template for i/o (reading and writing) from STDIN and STDOUT

https://www.hackerrank.com is a fun way to hone your programming skills in algorithms, functional programming, and other areas.

You do small exercises and get computer feedback immediately, which is what makes it so great. Some of the exercises have you just fill out a method body, but other ones require you to process from STDIN and write to STDOUT.

This makes it a bit harder to test in an IDE. Here is a simple template for Scala which lets you just plug in what you will copy back to hackerrank.

This example does the factorial function, with inputs of 2, 3 and 5. Once you're done testing your solution, copy the Solution object only back to hackerrank.

https://gist.github.com/cngdean/3702b7be4b6d298dd69c

I am still in the process of learning Scala so apologies for any non-idiomatic Scala above :)

Monday, August 25, 2014

Tips for Going Through Khanacademy Math as an Adult Learner

as influenced by the Learning How To Learn MOOC

My degree in math is 10 years old. I was never really "good" at math. It was always hard, a struggle, I missed things, didn't understand pieces, and generally had a rough time of it. The only reason I made it through with a BA in math is persistence and luck.

It is 10 years later and I still think about math a lot.I still wonder about things I missed. I still wish I was "good" at it. Every couple of years, I would pick up a book and try to refresh my knowledge. Then came khanacademy! www.khanacademy.com. It is a great platform for reviewing, filling in the gaps, and proving that you *know* the material. It has gamification makes it fun and makes it clear what you should work on next. You can pick a "mission", be it algebra, geometry, or all of math (mostly High School). It has exercises that are thorough and brutal and change. You don't get through to knowing an exercises until you can do it perfectly 5 times in a row. Once you've gotten through it, you have to "master" it, by doing it again, spaced out in intervals.

I found all sorts of gaps in my knowledge. Things I didn't remember, or never learned. I never really learned how to complete the square, I would always get around it with the quadratic formula. Memorized the volume formulas for 3-dimensional solids? Nope.

So I have been going through it. All of it. From the beginning. 2nd grade. And it is helping me in other areas of my life! It is teaching me how to pay attention, how to read carefully. And I am learning things I never knew and even building up a bit of confidence!

My goal is primarily:
 * Get through 90%+ of all the exercises

I recently took a Learning How to Learn course and am going to explain how I am going to apply key things I learned in that course in my quest to win khanacademy. I hope that they will be applicable to other learners, especially older learners going through khanacademy.

Spaced Repetition

Spaced Repetition is a method of getting knowledge from your short-term memory into your long-term memory. It is one of the big things I was missing in my academic life. I would do reasonably well in a class, but months later have nearly forgotten everything I learned.

Khanacademy builds in some spaced repetition via the mastery challenges. Even if you have "mastered" something, a question about it will come up every so often to make sure you remember it. I am also going to add on top of it some flashcards, especially for the things that don't really "stick." If I hit a formula or especially method that seems new, or doesn't immediately stick, I will add it to my new flashcard pile. I am going to apply spaced repetition algorithms similar to Anki's to my deck which will hopefully work for long-term retention.

Recall

When learning new skills, and reviewing old ones, before trying it I try to understand it, then look away and explain it.This was shown to be better that just re-reading it, or just looking at the worked examples.I also try to think through the problems on walks, and see if I can explain it to myself successfully.

Process vs. Product

Focusing on the process instead of the product can be enormously helpful in reducing anxiety and frustration. Sometimes I would get mad that I didn't master a certain skill, or that a grade level was taking too long. Now, instead I just commit to doing 1 25 minute session a day for as long as it takes to get through all the material. In that session, I will do my best to learn and master skills, but I am not going to attach myself to finishing any certain number of skills. I will be using the Pomodoro technique for this!

Exercise

One of the great things I learned in Learning How to Learn was just how crucial exercise is to learning, as was borne out by the research. That is another thing I was definitely missing out on in my academic years. I do exercise pretty often now, but I will commit to doing it more, and realizing more how important it is to learning! It is a great time to live in the "diffuse" mode of learning, and helps our brains process new information better.

Summary

Here is a photo of my progress on all the math skills on khanacademy. I have been working at for about 20-30 minutes a day for over a year. We will see if these new techniques allow me to progress any faster! I hope they can help you through your khanacademy journey as well.






References


A Mind For Numbers (Oakley)
https://www.goodreads.com/book/show/18693655-a-mind-for-numbers?ac=1

Learning How to Learn Coursera Course
https://class.coursera.org/learning-001/

The Pomodoro Technique
http://pomodorotechnique.com/









Sunday, April 6, 2014

Droid 4 - Cyanogenmod 11 KitKat 4.4 - WifiTether - 2014-04-06

This is an older device but the Droid 4's qwerty keyboard is still very nice! I had some trouble getting WiFi tethering to work, so I am posting for the googlers out there.
  * Root your phone
  * Install cyanogenmod 11
  * Install wifi tether
  * Run WiFi tether in AdHoc mode Worked for me!

Thursday, March 21, 2013

Best Place To Swing Dance in Denver!

Overstreet is amazing! They have great classes and a great venue. http://www.overstreetdancegallery.com/

Wednesday, January 23, 2013

AutoHotKey script to disable windows key, capslock, etc for games

Here is a small AutoHotKey script that will disable alt+tab, left windows key, and caps lock while you are in a certain window. It maps them to Alt+F1x so you can map those in the game. F12 then becomes the Windows key for when you need to get out. http://www.autohotkey.com
#ifwinactive World of Warcraft
{
 LWin::!F12
 !Tab::!F11
 Capslock::!F10
 F12::LWin
} 

Friday, October 26, 2012

Rails 3.2 Double-Post on adding AJAX

If you're seeing a double-post after adding AJAX, and you have ever precompiled your assets, try deleting everything from public/assets.

Wednesday, October 24, 2012

Rails 3.2.8 AJAX super-basic example

This is an updated-for-rails 3.2.8 super-simple AJAX tutorial, for people who have already followed a basic rails tutorial. I found a lot of rails AJAX tutorials but just enough has changed since 3.2.8 I wanted to show an updated version.
First, my versions of things I am using!

carmen@ubuntu:~/ws$ uname -a
Linux ubuntu 3.2.0-31-generic #50-Ubuntu SMP Fri Sep 7 16:16:45 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
carmen@ubuntu:~/ws$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
carmen@ubuntu:~/ws$ rails -v
Rails 3.2.8

Now on to the good stuff!

rails new ponies
cd ponies
rails generate scaffold Pony name:string profession:string
rake db:migrate
rails s

Make some ponies...

http://localhost:3000/ponies/new

Update your destroy line in index.html.erb. Add :remote => true, :class => 'delete_pony' to app/views/ponies/index.html.erb. The line should now look like:

    <%= link_to 'Destroy', pony, method: :delete, data: { confirm: 'Are you sure?' }, :remote => true, :class => 'delete_pony' %> 

Create a file, destroy.js.erb, put it next to your other .erb files (under app/views/ponies). It should look like this:

$('.delete_pony').bind('ajax:success', function() {  
        $(this).closest('tr').fadeOut();
});  

Add format.js { render :layout => false } to your controller (app/controllers/ponies_controller.rb). Your destroy method should now look like this:

  # DELETE /ponies/1
  # DELETE /ponies/1.json
  def destroy
    @pony = Pony.find(params[:id])
    @pony.destroy

    respond_to do |format|
      format.html { redirect_to ponies_url }
      format.json { head :no_content }
      format.js   { render :layout => false }
    end
  end

Restart your server, and click 'Delete' on some ponies (Preferably Rainbow Dash), and viola, they just fade out! In Rails 3.2.8.

Saturday, August 8, 2009

Ruby and Postgres

I've been trying to learn Ruby recently (rails comes later), and as an exercise I decided to write an ETL connector to load transaction data into my financial database. getting it to work with Postgres was a few steps so I thought I'd post it here as it's a pretty self-contained example.

First do these steps
  • install postgres-server-dev
  • sudo gem install postgres
  • sudo gem install pg
  • gem contents pg will allow you to view examples



  • Here's my code that converts the csv file and loads it up. I could not figure out how to turn of autocommit (we all know how I feel about autocommit) so I just start a transaction asap. I also couldn't figure out how to see how many rows are inserted with each insert statement like in perl, so I just used the PK. Enjoy!



    require 'rubygems'
    require 'pg'
    raise 'usage: ruby usbank.rb csvfile' if not ARGV[0]

    @conn = PGconn.new({:host=>'localhost',:user=>'DBUSER',:dbname=>'DBNAME'})
    @conn.setnonblocking(true)
    @conn.exec('BEGIN')

    def getid
    @conn.exec('select max(txn_id::numeric)+1 as txn_id from txn')[0]['txn_id']
    end

    file = File.new(ARGV[0], "r")
    file.gets

    begin_id = getid()

    while (line = file.gets)
    @array = line.split(",")
    date = @array[0]
    item = "#{@array[1]} #{@array[2]} #{@array[3]}"
    amount = @array[4]
    amount.chomp!
    puts "#{amount} #{date} #{item}"

    query = "insert into txn (date, amount, cat_id, item, source_id, txn_id)
    select
    \'#{date}\',
    #{amount},
    0,
    \'#{item}\',
    5,
    ( select nextval('txn_id_seq'))
    where not exists (
    select 1 from txn where date= \'#{date}\' and amount=#{amount}
    );\n
    "
    @conn.exec(query)
    end

    end_id = getid()
    puts "#{Integer(end_id) - Integer(begin_id)} updated."

    @conn.exec('COMMIT')
    @conn.finish
    file.close

    turn off autocommit for psql

    Every time I fire up a new instance of postgres, I forget how to turn off autocommit for psql. Searching on it, mostly I found a series of people saying "just begin a transaction." This makes NO sense! All it takes is one time of forgetting to begin a transaction, then one forgotten or ill-formed where clause on your delete statement and you're sitting on the floor crying. I am not sure why this is the default. So here is a post that will hopefully bubble above the People Not Answering The Question.

    Anyways, it's pretty easy. Just

    cd ~
    vim .psqlrc
    and make it look like this
    SET AUTOCOMMIT OFF
    viola! Now you may enjoy the wonders of Postgres (including transactional ddl, my favorite), without having to keep looking over your shoulder.

    Friday, December 26, 2008

    How to Test the Coil on a 2003 Ford Focus

    I suspected my coil was bad on my 2003 Ford Focus and decided to figure out exactly how to test it. Unfortunately it was not completely clear so I had to aggregate multiple sources. Here is a (hopefully) coherent version:

    1. Take it out
    2. Measure the primary and secondary resistances according to this picture. If something is infinite, the coil may be broken. Be careful though, make sure you are testing it right and getting a solid connection.

    My car just needed new plugs & wires. I wanted to be sure that was the problem before I just replaced them willy-nilly though!









    Check out this thread for more info: http://www.focusfanatics.com/forum/showthread.php?t=180606