Hackermonthly Issue024
Hackermonthly Issue024
A Senseless
Conversation
Issue 24 May 2012
Curator
Lim Cheng Soon
Contributors
Zach Barnett
Tom Preston-Werner
Kenton White
Matt Might
Henry Prcheur
Ben Dowling
Chris Wenham
Elijah Manor
Kenneth Reitz
Peep Laja
Chris Eidhof
Advertising
Published by
Netizens Media
46, Taylor Road,
11600 Penang,
Malaysia.
Contact
Proofreaders
Emily Griffin
Sigmarie Soto
Printer
MagCloud
Hacker Monthly is published by Netizens Media and not affiliated with Y Combinator in any way.
Contents
FEATURES
04 A Senseless Conversation
By Zach
Barnett
STARTUPS
10
SPECIAL
By TOM PRESTON-WERNER
13
By Peep Laja
A $5000 Chair
By Kenton White
37
By Chris Eidhof
PROGRAMMING
14
32
By Matt Might
18
By Henry Prcheur
20
By Ben Dowling
22
By Chris Wenham
26
By Elijah Manor
30
By Kenneth reitz
FEATURES
A Senseless Conversation
By Zach Barnett
Background credit: flickr.com/photos/zooboing/5376513937/
The following dialogue first appears in THINK 29, Vol. 10 (Autumn 2011) published by Cambridge University Press:
2011 Royal Institute of Philosophy All Rights Reserved
4 FEATURES
showed me a brain-computer
interface, which would allow me
to communicate with Douglas not
by talking, but by thinking. He
would speak into a microphone,
and I would hear his voice in
my minds ear. To reply, I would
think my responses back to him,
and he would receive my thoughts
as text. It was a bit sci-fi for me,
but Douglas reassured me. He told
me that the whole experiment
would not take too long and that
he would let me out as soon as
it was over. I trusted him. With a
deep breath, I entered the tank, and
Douglas closed the lid.
There was a moment of stillness.
I couldnt see anything, and when I
tried to move, I couldnt feel myself
moving. When I tried to speak, I
couldnt hear myself speaking. Suddenly, and to my surprise, I could
hear Douglass voice:
DOUGLAS: How are you doing in there?
Feeling comfortable yet?
ZACH: This is pretty weird. But Im okay.
DOUGLAS: Great.
6 FEATURES
8 FEATURES
STARTUPS
10 STARTUPS
11
Charlock_Holmes (general
purpose character encoding
detection)
12 STARTUPS
A $5000 Chair
By Kenton White
13 STARTUPS
PROGRAMMING
Why SSH?
As recently as 2001, it was not uncommon to log in to
a remote Unix system using telnet. Telnet is just above
netcat in protocol sophistication, which means that
passwords were sent in the clear. As wifi proliferated,
telnet went from security nuisance to security disaster. While an undergrad, I remember running ethereal
(now wireshark) in the school commons area, snagging
about a dozen root passwords in an hour.
SSH, which encrypts and authenticates connections,
had been in development since 1995, but it seemed to
become adopted nearly universally and almost overnight around 2002.
It is worth configuring SSH properly:
This article covers less common SSH use cases, such as:
14 PROGRAMMING
Configuring sshd
The options most frequently
tweaked are:
PasswordAuthentication: set
this to no to disallow password
Host mm
User matt
HostName might.net
IdentityFile ~/.ssh/matt.id_dsa
Host *.lab.ucaprica.edu
User u8193
15
Then, connect to
localhost:localport to connect
to B:remoteport. If you use add -g,
then anyone that can reach A may
connect to B:remoteport through
A:localport. This is useful for
evading firewalls.
For example, suppose your
work banned reddit.com. Run the
following:
# ssh yourserver -L 80:reddit.
com:80
GatewayPorts yes
$ sshfs remote-host:
local-mount-directory
Matt Might is a professor of Computer Science at the University of Utah. His research
interests include programming language
design, static analysis and compiler optimization. He blogs at matt.might.net/articles
and tweets from @mattmight
Reprinted with permission of the original author.
First appeared in hn.my/sshtricks (matt.might.net)
16 PROGRAMMING
17
a = [1, 2, 3]
We didnt copy the list referenced by a. We just created a new tag b and attached it to the list pointed by
a. Like in the picture below:
18 PROGRAMMING
>>> id(b)
3080501452L
>>> c = [] # Create a new list
>>> id(c)
3080609228L
a and b really do point to the same memory address
while c points to a new empty list, different from the
one referenced by a and b.
my_tuple = (1, 2, 3)
my_list = list(my_tuple)
print my_list
2, 3]
list creates a new list and copies the portion into this
new list.
>>> a = [1, 2, 3, 4]
>>> a[1:3]
[2, 3]
>>> id(a)
3080104140L
>>> id(a[1:3])
3080513612L
>>> a[1:]
[2, 3, 4]
19
Curl
Curl is a network transfer tool thats very similar to
wget, the main difference being that by default wget
saves to file, and curl outputs to the command line.
This makes is really simple to see the contents of a
website. Here, for example, we can get our current IP
from the ifconfig.me website:
$ curl ifconfig.me
93.96.141.93
20 PROGRAMMING
Curls -i (show headers) and -I (show only headers) option make it a great tool for debugging HTTP
responses and finding out exactly what a server is sending to you:
$ curl -I news.ycombinator.com
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: private
Connection: close
The -L option is handy, and makes Curl automatically follow redirects. Curl has support for HTTP Basic
Auth, cookies, manually settings headers, and much,
much more.
Siege
Siege is an HTTP benchmarking tool. In addition
to the load testing features, it has a handy -g option
that is very similar to curl -iL except it also shows
you the request headers. Heres an example with
www.google.com (Ive removed some headers for
brevity):
$ siege -g www.google.com
GET / HTTP/1.1
Host: www.google.com
User-Agent: JoeDog/1.00 [en] (X11; I; Siege
2.70)
Connection: close
HTTP/1.1 302 Found
Location: http://www.google.co.uk/
Content-Type: text/html; charset=UTF-8
Server: gws
Content-Length: 221
Connection: close
GET / HTTP/1.1
Host: www.google.co.uk
User-Agent: JoeDog/1.00 [en] (X11; I; Siege
2.70)
Connection: close
HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
X-XSS-Protection: 1; mode=block
Connection: close
Concurrency:
Successful transactions:
Failed transactions:
Longest transaction:
Shortest transaction:
19.53
1400
0
4.08
0.08
Ngrep
For serious network packet analysis theres Wireshark,
with its thousands of settings, filters, and different
configuration options. Theres also a command line
version, tshark. For simple tasks I find Wireshark can
be overkill, so unless I need something more powerful,
ngrep is my tool of choice. It lets you do with network
packets what grep does with files.
For web traffic you almost always want the -W
byline option, which preserves linebreaks, and -q, a
useful argument which suppresses some additional
output about non-matching packets. Heres an example
that captures all packets that contain GET or POST:
ngrep -q -W byline "^(GET|POST) .*"
21
22 PROGRAMMING
well as how to find bugs in existing code without having to reimplement the whole routine from
scratch.
Poor Understanding
of the Languages
Programming Model
Deficient Research
Skills/Chronically Poor
Knowledge of the Platforms
Features
Modern languages and frameworks now come with an awesome breadth and depth of built-in
commands and features, with some
leading frameworks (Java, .Net,
Cocoa) being too large to expect
any programmer, even a good one,
to learn in anything less than a
few years. But a good programmer
will search for a built-in function
that does what they need before
they begin to roll their own, and
excellent programmers have the
skill to break-down and identify
the abstract problems in their task,
then search for existing frameworks,
patterns, models, and languages that
can be adapted before they even
begin to design the program.
Symptoms
These are only indicative of the
problem if they continue to appear
in the programmers work long
after he should have mastered the
new platform.
1. Re-inventing or laboring without basic mechanisms that are
built into the language, such as
events-and-handlers or regular
expressions
2. Re-inventing classes and functions that are built into the
framework (e.g.: timers, collections, sorting and searching
algorithms)*
23
24 PROGRAMMING
Inability to Comprehend
Pointers
Remedies
Get your feet wet and be prepared
for some stack overflows. Begin by
writing code with only one basecondition check and one recursive
call that uses the same, unmodified
parameter that was passed. Stop
coding even if you have the feeling that its not enough, and run it
anyway. It throws a stack-overflow
exception, so now go back and pass
a modified copy of the parameter
in the recursive call. More stack
overflows? Excessive output? Then
do more code-and-run iterations,
switching from tweaking your
base-condition test to tweaking
your recursive call until you start to
intuit how the function is transforming its input. Resist the urge to
use more than one base-condition
test or recursive call unless you
really Know What Youre Doing.
Your goal is to have the confidence to jump in, even if you dont
have a complete sense of where
you are in the imaginary recursive path. Then when you need to
write a function for a real project
youd begin by writing a unit test
first, and proceeding with the same
technique above.
Distrust of Code
Symptoms
1. Writing IsNull() and IsNotNull(), or IsTrue(bool) and
IsFalse(bool) functions
25
Differences Between
jQuery bind(), live(),
delegate() and on()
By Elijah Manor
26 PROGRAMMING
The .bind() method will attach the event handler to all of the
anchors that are matched! That is not good. Not only is it expensive to implicitly iterate over all of those items to attach an event
handler, but it is also wasteful since it is the same event handler
over and over again.
Pros
This methods works across various browser implementations.
Cons
The method attaches the same event handler to every
matched element in the selection.
Pros
There is only one event handler registered
instead of the numerous event handlers
that could have been registered with the
.bind() method.
Cons
This method is deprecated as of jQuery
1.7, and you should start phasing out its
use in your code.
Using event.stopPropagation() is no
longer helpful because the event has
already delegated all the way up to the
document.
27
28 PROGRAMMING
Cons
Changing from a .bind() to a .delegate() method isnt as
straight forward.
With that in mind, the usage of the new .on() method looks
something like the following:
/* The jQuery .bind(), .live(), and .delegate() methods
are just one line pass throughs to the new jQuery 1.7
.on() method */
// Bind
$( "#members li a" ).on( "click", function( e ) {} );
$( "#members li a" ).bind( "click", function( e ) {} );
//
$(
{}
$(
Live
document ).on( "click", "#members li a", function( e )
);
"#members li a" ).live( "click", function( e ) {} );
//
$(
$(
{}
Delegate
"#members" ).on( "click", "li a", function( e ) {} );
"#members" ).delegate( "li a", "click", function( e )
);
Youll notice that how I call the .on() method changes how
it performs. You can consider the .on() method as being overloaded with different signatures, which in turn changes how
the event binding is wired-up. The .on() method brings a lot of
consistency to the API and hopefully makes things slightly less
confusing.
Pros
Brings uniformity to the various event-binding methods.
Simplifies the jQuery code base and removes one level of redirection since the .bind(), .live(), and .delegate() call this
method under the covers.
Still provides all the goodness of the .delegate() method,
while still providing support for the .bind() method if you
need it.
Cons
Brings confusion because the behavior changes based on how
you call the method.
Conclusion (tl;dr)
If you have been confused about the various
different types of event binding methods then
dont worry, there has been a lot of history
and evolution in the API over time. There
are many people that view these methods as
magic, but once you uncover some of how
they work, you understand how to better
code inside of your projects.
The biggest take-aways:
29
30 PROGRAMMING
Have an Issue
The first step to developing something great is to have a real problem. You cant solve a problem
properly if you dont experience it
firsthand.
On the consumer app side of
things, a great example of this is
Microsoft OneNote. Have you used
OneNote? Its incredible.
Essentially, OneNote is hierarchical freeform note-taking software
that assumes nothing: you can type,
use handwriting, embed files, crosslink notes, sync them online, etc.
Unfortunately, OneNote is only
available on Windows. This kills me.
I would love to think that Microsoft would port this lovely piece of
software to OS X, but I doubt it
will ever happen.
If I ever decide to actually ship
a consumer product, it will be
something akin to OneNote for OS
X. It would be incredible. It may
not be for many, but for people
that resonate with my problem, it
will work wonderfully. It would be
a reaction to a real problem, not
an engineered app an entrepreneur
thinks will fill a gap so he can make
some fast cash.
Build
Now that you know what your
API is: Build it. Make it happen. If
theres a significant amount of complexity behind a simple call, make
a layered API: a porcelain interface
Manifesto
Build things that you want. Build
things that you need. Build things
for you.
The Golden Rule:
Do unto others as you would have
them do to you.
Adapted to:
Build tools for others that you
want to be built for you. n
Kenneth Reitz is a software architect
and minimalist, consumed with elegant
tools and interfaces. He works at Heroku,
designing the Python Stack. Kenneth
also writes The GitHub Reflog and loads
of open source projects, available at
github.com/kennethreitz
Reprinted with permission of the original author.
First appeared in hn.my/howid (kennethreitz.com)
31
SPECIAL
be
persuasive. The
power to influence people to
get what you want is sometimes all
it takes to be successful. These are
some tactics, discovered through
psychological research, that you
have probably not yet heard about,
but which have the potential to
increase your persuasive abilities.
Im not going to cover reciprocity, scarcity, or social proof and all
those widely known persuasion
principles. You already know all
about those (in case you dont,
stop everything and read Influence:
The Psychology of Persuasion by
Cialdini).
ou want to
32 SPECIAL
33
34 SPECIAL
35
36 SPECIAL
Chris Eidhof is an independent software developer from The Netherlands, living in Berlin. He used to do high-level functional programming in Haskell but converted to Objective-C: he now builds iPhone
and iPad apps, and dabbles in big data.
Reprinted with permission of the original author.
First appeared in hn.my/idea (eidhof.nl)
37