thumbs up for express js and sideways for quo vadis

2 February 2012 | 3:11 pm by codeboxer

I've just been checking out some stuff lately and have been dying to try out express.js, which is built on the node.js framework. It is easy to use, super fast, and very cool. I highly recommend it for a lightweight and snappy front-end.

Also, I am finally making the jump to Rails 3.2, and for that reason am porting my entire gmgpulse app, complete with new auth layer and switching from prototype to jQuery. It's a lot of work but will pay many dividends. Essentially I am paying off some existing technical debt and moving the whole enterprise back into the black! I am trying out a very simple and effective auth gem called 'quo_vadis' but currently it has a problem with the 3.2 release so I am crossing my fingers that the guy who manages the gem will merge the pull request soon - it has already been fixed. I figure since I have about 30-60 days before it needs to work, I may be all right.


strange delete syntax with join for mysql

13 December 2011 | 4:14 pm by codeboxer

With MySQL 5, there are two rules if you need to join to another table in order to delete records from somewhere.
  • Rule 1: no aliases allowed. Refer only to tables as themselves - better hope the names aren't very long!
  • Rule 2: specify table name from which to delete before the FROM clause.
Like so:
  DELETE sales from sales
    JOIN retailers on sales.retailer_id = retailers.id
   WHERE retailers.merchant in ('Test Merchant', 
                                'Other merchants that should not be here')

Epigrams in programming

15 November 2011 | 1:20 am by codeboxer
An ode to Alan Perlis, copied from Yale:

1. One man's constant is another man's variable.
2. Functions delay binding; data structures induce binding. Moral: Structure data late in the programming process.
3. Syntactic sugar causes cancer of the semicolon.
4. Every program is a part of some other program and rarely fits.
5. If a program manipulates a large amount of data, it does so in a small number of ways.
6. Symmetry is a complexity-reducing concept (co-routines include subroutines); seek it everywhere.
7. It is easier to write an incorrect program than understand a correct one.
8. A programming language is low level when its programs require attention to the irrelevant.
9. It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures.
10. Get into a rut early: Do the same process the same way. Accumulate idioms. Standardize. The only difference(!) between Shakespeare and you was the size of his idiom list - not the size of his vocabulary.
11. If you have a procedure with ten parameters, you probably missed some.
12. Recursion is the root of computation since it trades description for time.
13. If two people write exactly the same program, each should be put into microcode and then they certainly won't be the same.
14. In the long run every program becomes rococo - then rubble.
15. Everything should be built top-down, except the first time.
16. Every program has (at least) two purposes: the one for which it was written, and another for which it wasn't.
17. If a listener nods his head when you're explaining your program, wake him up.
18. A program without a loop and a structured variable isn't worth writing.
19. A language that doesn't affect the way you think about programming, is not worth knowing.
20. Wherever there is modularity there is the potential for misunderstanding: Hiding information implies a need to check communication.
21. Optimization hinders evolution.
22. A good system can't have a weak command language.
23. To understand a program you must become both the machine and the program.
24. Perhaps if we wrote programs from childhood on, as adults we'd be able to read them.
25. One can only display complex information in the mind. Like seeing, movement or flow or alteration of view is more important than the static picture, no matter how lovely.
26. There will always be things we wish to say in our programs that in all known languages can only be said poorly.
27. Once you understand how to write a program get someone else to write it.
28. Around computers it is difficult to find the correct unit of time to measure progress. Some cathedrals took a century to complete. Can you imagine the grandeur and scope of a program that would take as long?
29. For systems, the analogue of a face-lift is to add to the control graph an edge that creates a cycle, not just an additional node.
30. In programming, everything we do is a special case of something more general -- and often we know it too quickly.
31. Simplicity does not precede complexity, but follows it.
32. Programmers are not to be measured by their ingenuity and their logic but by the completeness of their case analysis.
33. The eleventh commandment was "Thou Shalt Compute" or "Thou Shalt Not Compute" - I forget which.
34. The string is a stark data structure and everywhere it is passed there is much duplication of process. It is a perfect vehicle for hiding information.
35. Everyone can be taught to sculpt: Michelangelo would have had to be taught not to. So it is with great programmers.
36. The use of a program to prove the 4-color theorem will not change mathematics - it merely demonstrates that the theorem, a challenge for a century, is probably not important to mathematics.
37. The most important computer is the one that rages in our skulls and ever seeks that satisfactory external emulator. The standarization of real computers would be a disaster - and so it probably won't happen.
38. Structured Programming supports the law of the excluded muddle.
39. Re graphics: A picture is worth 10K words - but only those to describe the picture. Hardly any sets of 10K words can be adequately described with pictures.
40. There are two ways to write error-free programs; only the third one works.
41. Some programming languages manage to absorb change, but withstand progress.
42. You can measure a programmer's perspective by noting his attitude on the continuing vitality of FORTRAN.
43. In software systems, it is often the early bird that makes the worm.
44.Sometimes I think the only universal in the computing field is the fetch-execute cycle.
45. The goal of computation is the emulation of our synthetic abilities, not the understanding of our analytic ones.
46. Like punning, programming is a play on words.
47. As Will Rogers would have said, "There is no such thing as a free variable."
48. The best book on programming for the layman is "Alice in Wonderland"; but that's because it's the best book on anything for the layman.
49. Giving up on assembly language was the apple in our Garden of Eden: Languages whose use squanders machine cycles are sinful. The LISP machine now permits LISP programmers to abandon bra and fig-leaf.
50. When we understand knowledge-based systems, it will be as before -- except our fingertips will have been singed.
51. Bringing computers into the home won't change either one, but may revitalize the corner saloon.
52. Systems have sub-systems and sub-systems have sub- systems and so on ad infinitum - which is why we're always starting over.
53. So many good ideas are never heard from again once they embark in a voyage on the semantic gulf.
54. Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy.
55. A LISP programmer knows the value of everything, but the cost of nothing.
56. Software is under a constant tension. Being symbolic it is arbitrarily perfectible; but also it is arbitrarily changeable.
57. It is easier to change the specification to fit the program than vice versa.
58. Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it.
59. In English every word can be verbed. Would that it were so in our programming languages.
60. In seeking the unattainable, simplicity only gets in the way.
61. In programming, as in everything else, to be in error is to be reborn.
62. In computing, invariants are ephemeral.
63. When we write programs that "learn", it turns out that we do and they don't.
64. Often it is the means that justify the ends: Goals advance technique and technique survives even when goal structures crumble.
65. Make no mistake about it: Computers process numbers - not symbols. We measure our understanding (and control) by the extent to which we can arithmetize an activity.
66. Making something variable is easy. Controlling duration of constancy is the trick.
67. Think of all the psychic energy expended in seeking a fundamental distinction between "algorithm" and "program".
68. If we believe in data structures, we must believe in independent (hence simultaneous) processing. For why else would we collect items within a structure? Why do we tolerate languages that give us the one without the other?
69. In a 5 year period we get one superb programming language. Only we can't control when the 5 year period will be.
70. Over the centuries the Indians developed sign language for communicating phenomena of interest. Programmers from different tribes (FORTRAN, LISP, ALGOL, SNOBOL, etc.) could use one that doesn't require them to carry a blackboard on their ponies.
71. Documentation is like term insurance: It satisfies because almost no one who subscribes to it depends on its benefits.
72. An adequate bootstrap is a contradiction in terms.
73. It is not a language's weakness but its strengths that control the gradient of its change: Alas, a language never escapes its embryonic sac.
74. Is it possible that software is not like anything else, that it is meant to be discarded: that the whole point is to see it as a soap bubble?
75. Because of its vitality, the computing field is always in desperate need of new cliches: Banality soothes our nerves.
76. It is the user who should parameterize procedures, not their creators.
77. The cybernetic exchange between man, computer and algorithm is like a game of musical chairs: The frantic search for balance always leaves one of the three standing ill at ease.
78. If your computer speaks English, it was probably made in Japan.
79. A year spent in artificial intelligence is enough to make one believe in God.
80. Prolonged contact with the computer turns mathematicians into clerks and vice versa.
81. In computing, turning the obvious into the useful is a living definition of the word "frustration".
82. We are on the verge: Today our program proved Fermat's next-to-last theorem.
83. What is the difference between a Turing machine and the modern computer? It's the same as that between Hillary's ascent of Everest and the establishment of a Hilton hotel on its peak.
84. Motto for a research laboratory: What we work on today, others will first think of tomorrow.
85. Though the Chinese should adore APL, it's FORTRAN they put their money on.
86. We kid ourselves if we think that the ratio of procedure to data in an active data-base system can be made arbitrarily small or even kept small.
87. We have the mini and the micro computer. In what semantic niche would the pico computer fall?
88. It is not the computer's fault that Maxwell's equations are not adequate to design the electric motor.
89. One does not learn computing by using a hand calculator, but one can forget arithmetic.
90. Computation has made the tree flower.
91. The computer reminds one of Lon Chaney -- it is the machine of a thousand faces.
92. The computer is the ultimate polluter: its feces are indistinguish- able from the food it produces.
93. When someone says "I want a programming language in which I need only say what I wish done," give him a lollipop.
94. Interfaces keep things tidy, but don't accelerate growth: Functions do.
95. Don't have good ideas if you aren't willing to be responsible for them.
96. Computers don't introduce order anywhere as much as they expose opportunities.
97. When a professor insists computer science is X but not Y, have compassion for his graduate students.
98. In computing, the mean time to failure keeps getting shorter.
99. In man-machine symbiosis, it is man who must adjust: The machines can't.
100. We will never run out of things to program as long as there is a single program around.
101. Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve.
102. One can't proceed from the informal to the formal by formal means.
103. Purely applicative languages are poorly applicable.
104. The proof of a system's value is its existence.
105. You can't communicate complexity, only an awareness of it.
106. It's difficult to extract sense from strings, but they're the only communication coin we can count on.
107. The debate rages on: is PL/I Bachtrian or Dromedary?
108. Whenever two programmers meet to criticize their programs, both are silent.
109. Think of it! With VLSI we can pack 100 ENIACS in 1 sq. cm.
110. Editing is a rewording activity.
111. Why did the Roman Empire collapse? What is Latin for office automation?
112. Computer Science is embarrassed by the computer.
113. The only constructive theory connecting neuroscience and psychology will arise from the study of software.
114. Within a computer natural language is unnatural.
115. Most people find the concept of programming obvious, but the doing impossible.
116. You think you know when you can learn, are more sure when you can write, even more when you can teach, but certain when you can program.
117. It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?
118. If you can imagine a society in which the computer- robot is the only menial, you can imagine anything.
119. Programming is an unnatural act.
120. Adapting old programs to fit new machines usually means adapting new machines to behave like old ones.

Yahoo geocoder is gone

2 November 2011 | 2:06 pm by codeboxer
Yahoo quietly discontinued it's geocoding feature in September. I kept getting 503 errors until I looked at the Yahoo developer maps page. I wonder if they were just using google maps on the backend and couldn't afford the new pricing structure. Bummer, because I used it for almost everything I do with calculating latitude and longitude values on the fly. I am now refactoring to use google maps instead. One might argue that I should have done that to start with.

the fizzbuzz problem

29 October 2011 | 3:16 pm by codeboxer
I got the idea to try this from this article after reading this article. I stumbled a little on the mod function, I thought you could write 'mod' instead of using the '%' operator. So it took me just under 4 minutes. Hopefully that puts me somewhere above the middle of the pack. Also, for the record I built a directory for the script and made sure it ran correctly within those three minutes. I saw a guy who says he did it in C in 30 seconds, and I'm pretty sure he didn't compile or run it in that time. Cheater!
AirAxel:fizzbuzz pi$ ruby testfb.rb 
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz
16
17
fizz
19
buzz
fizz
22
23
fizz
buzz
26
fizz
28
29
fizzbuzz
31
32
fizz
34
buzz
fizz
37
38
fizz
buzz
41
fizz
43
44
fizzbuzz
46
47
fizz
49
buzz
fizz
52
53
fizz
buzz
56
fizz
58
59
fizzbuzz
61
62
fizz
64
buzz
fizz
67
68
fizz
buzz
71
fizz
73
74
fizzbuzz
76
77
fizz
79
buzz
fizz
82
83
fizz
buzz
86
fizz
88
89
fizzbuzz
91
92
fizz
94
buzz
fizz
97
98
fizz
buzz
AirAxel:fizzbuzz pi$

if it were not for Steve

5 October 2011 | 8:16 pm by codeboxer
If it were not for Steve:
  • I would probably still be a Windows developer.
  • My laptop would be a lot uglier.
  • I would probably still have a cable TV subscription.
  • I wouldn't love to hate iTunes so much.
  • I wouldn't be tempted every day to buy an iPhone.
  • I wouldn't be tempted every day to buy an iPad.
  • The software development community would probably be very different and certainly for the worse.
  • Finding Nemo would never have made me cry.
  • Today would not be such a sad day.
Rest in peace, great man.



This is also cool - the simple but unprecedented Google tribute:

get rid of the patch gem_dependency.rb:119 error

2 August 2011 | 6:20 pm by codeboxer Hate this error?
fix version_requirements is deprecated 
and will be removed on or after August 2010.
Use #requirement


Use this:



copied from here

Just remember to switch out the directory after -d with wherever gem_dependency.rb lives on your system (it’s in the warning message). It is probably bad practice to patch your system gems, but to get rid of this warning we can make an exception... If something goes wrong, reverse the patch with:


setting up a MacBook Air 2011

20 June 2011 | 7:07 pm by codeboxer
This was copied from this great post by Frederico Araujo, with some small modifications for my own use case. MacPorts is still a smart way to go, I tried Homebrew first and ended up in Ruby gem hell. Also, read all the way to the bottom before you start (you may need to add wget via MacPorts before step 3).

Requirements:

  • Snow Leopard 10.6.4 or greater
  • Xcode 3.2.3, 2.4.1 or greater
  • Admin privileges on your mac.

Software preliminary:

  • Mysql 5.1.49 (macports)
  • Ruby 1.8.7 (macports)
  • Rubygems (download)

1. Preparing System

If you are upgrading from Leopard to Snow Leopard, I recommend you delete your old installation.

sudo rm -rf \
    /opt/local \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0 \
    ~/.macports
Note: I was setting up a new MacBook Air, so I didn't need to do this, but I left it here for reference.

1.1 Prepare PATH environment:

$vim ~/.bash_profile

Edit your ~/.bash_profile file and add these 2 lines.
Check if they are not there already.

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH

1.2 Download and Install Xcode

http://developer.apple.com/technologies/xcode.html

Here I used the XCode install from my Snow Leopard disc, the above link is from the original post. The link includes the XCode SDK, I think, so it's a bigger download (4gb) whereas the Snow Leopard XCode install is only 2.7gb which is all you need for just Rails stuff and with a smallish hard drive, every gb counts. Also, I did the install via driveshare from my other MacBook Pro.

1.3 Download Macports and install

Download Page: http://www.macports.org/install.php

Download Direct Link: http://distfiles.macports.org/MacPorts/MacPorts-1.9.2-10.6-SnowLeopard.dmg

You might use this guide for installing Macports:

Full Install Guide: http://guide.macports.org/#installing

1.3.1 Update macports

sudo port -v selfupdate

2. Mysql

2.1 Install Mysql

sudo port -v install mysql5-server mysql5

2.2 Make mysql autoload on startup

sudo port load mysql5-server
sudo -u mysql mysql_install_db5

3. Ruby, Rubygems, Rails, other gems

3.1 Install Ruby from macports

sudo port -v install ruby
$ ruby -v
ruby 1.8.7 (2010-08-08 patchlevel 302) [x86_64-darwin10]

3.2 download rubygems from http://rubygems.org/pages/download

cd /tmp
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar xpf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb

3.3 Install rails, rake, rspec etc.

You may want a lot of other gems, I added xml-simple, fastercsv, calendar_helper, etc., so add gems as needed, especially the mysql gem which you will need - but do that as specified in the next step.
sudo gem install rake rails ruby-debug

3.4 install mysql gem

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \ 
--with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
DO THIS BEFORE step 3: I had to run
sudo port install wget
before I was able to get the RubyGems install package (wget does not ship with Snow Leopard). Other things I had to do:

I had to install git from a package here.

good luck!

prawn for Rails

23 April 2011 | 2:02 am by codeboxer
I had a question from @rcstolle on how to use Prawn, so here is a short primer. There are two ways to go - Prawn gives a pretty good amount of control via the built-in methods, so if your layout is static enough you can just build a report with what amounts to something of a cursor. Somehow it feels vaguely like Crystal Reports for those dinosaurs like me who actually used to use that once upon a time. You set the fill color, you build the table, you move to cursor down a few pixels, et cetera. Everything is pixel based and although it feels pretty solid, you don't get any CSS, you can't float anything, and in the end the use-cases are sort of limited. The other route is to use the grid-based option, which allows greater control and flexibility but also forces you to delve a little deeper into the Prawn object model. Here are some code samples to show how the Prawn::Document::Grid class can be used in practice. Starting with the document class: the page: the section: and the supporting classes: which leans heavily on the Forwardable module. Here, although you are still working very much with pixel values, you also are specifying rows which can help with complex layouts. If you need some reference for the Prawn Grid module it is here. So, the bottom line is that Prawn can handle whatever you throw at it. It is a very powerful tool and I don't know of anything that even comes close in terms of pure Ruby solutions to writing PDF reports.

The change you wanted was rejected.

7 April 2011 | 2:32 pm by codeboxer
Maybe you tried to change something you didn't have access to.

If you see this on your Rails-based Facebook app, try disabling 'protect_from_forgery' in your ApplicationController. Facebook uses signed_request that you can decode and use to verify that the request actually comes from Facebook, so protect_from_forgery is unnecessary for applications that are accessible through the facebook canvas only.

reverse string function

18 March 2011 | 3:53 pm by codeboxer
Good times.

My Site Links

If you visit gmgpulse, you may login as demo/demo.

Rockstar Television


© 2008-11 Krister Axel and codeboxer.com