Sunday, October 19, 2014
hackerrank scala template for i/o (reading and writing) from STDIN and STDOUT
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
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
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
Process vs. Product
Exercise
Summary
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
* 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!
Wednesday, January 23, 2013
AutoHotKey script to disable windows key, capslock, etc for games
#ifwinactive World of Warcraft
{
LWin::!F12
!Tab::!F11
Capslock::!F10
F12::LWin
}
Friday, October 26, 2012
Rails 3.2 Double-Post on adding AJAX
Wednesday, October 24, 2012
Rails 3.2.8 AJAX super-basic example
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
First do these steps
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
Anyways, it's pretty easy. Just
cd ~and make it look like this
vim .psqlrc
SET AUTOCOMMIT OFFviola! 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:- Take it out
- 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


