Hackermonthly Issue035
Hackermonthly Issue035
Hackermonthly Issue035
k
c
a
H
k
c
u
D
k
c
u
D
Create instant answer plugins for DuckDuckGo
duckduckhack.com
3
Curator
Lim Cheng Soon
Contributors
Martin Legeer
Andrew Chalkley
Grant Mathews
Bryan Kennedy
Patrick Wyatt
Pete Keen
Craig Kerstiens
Amber Feng
Alex Baldwin
John Biesnecker
Rachel Kroll
Proofreaders
Advertising
Published by
ads@hackermonthly.com
Netizens Media
46, Taylor Road,
11600 Penang,
Malaysia.
Contact
contact@hackermonthly.com
Emily Griffin
Sigmarie Soto
Ebook Conversion
Ashish Kumar Jha
Printer
MagCloud
Hacker Monthly is published by Netizens Media and not affiliated with Y Combinator in any way.
Contents
FEATURES
Legeer
Chalkley
PROGRAMMING
16
SPECIAL
36
By Grant Mathews
19
By Alex Baldwin
By Bryan Kennedy
22
37
By John Biesnecker
By Patrick Wyatt
28
38
By Rachel Kroll
By Pete Keen
30
By Craig Kerstiens
34
By Amber Feng
FEATURES
6 FEATURES
8 FEATURES
10 FEATURES
Christmas
break from work I
wanted to learn somever the
thing new.
Ive been eyeing up Arduino for
some time now, and for Christmas I
got an Arduino UNO R3 board.
What is Arduino?
Arduino is an open-source electronics prototyping platform based on
flexible, easy-to-use hardware and
software. It is intended for artists,
12 FEATURES
void setup()
{
}
void loop()
{
}
Now that we have the basic skeleton in place, we can do the Hello,
World program of microcontrollers,
a blinking an LED.
Programming Arduino
For the example Im showing, youll
only need the Arduino UNO R3
board itself and the required USB
cable to transfer the program from
your computer to the board.
On the board left of the Arduino
logo theres an LED, short for Light
Emitting Diode, a small light, with
the letter L next to it.
Were going to switch it on and
off and then look into making it
blink on and off for 2 seconds at a
time.
When you first plug your USB
cable into your Arduino and your
computer, you may notice that this
LED is blinking. Not to worry! Its
The Code
The code you write for your Arduino are known as sketches. They are
written in C++.
Every sketch needs two void type
functions, setup() and loop(). A
void type function doesnt return
any value.
The setup() method is run once
just after the Arduino is powered
up and the loop() method runs
continuously afterwards. The
setup() is where you want to
do any initialization steps, and in
loop() you run the code you want
to run over and over again.
So, your basic sketch or program
should look like this:
13
We do this by calling
another special method called
digitalWrite(). This also takes
two values, the pin number and the
level, HIGH or the on state or LOW
the off state.
void setup()
{
void setup()
{
pinMode(ledPin, OUTPUT);
}
}
void loop()
{
}
void loop()
{
digitalWrite(ledPin, LOW);
}
14 FEATURES
What next?
The Arduino platform is an incredibly easy
and versatile platform to get started with. Its
open-source hardware, meaning that people can
collaborate to improve, remix and build on it.
Its the brains to some of the most popular
devices that are driving the next Industrial
Revolution, the 3D printer. [makerbot.com]
And as Massimo Banzi says, You dont need
anybodys permission to create something
great. So what you waiting for? n
Andrew Chalkley is an Expert Teacher at Treehouse,
Co-founder of iOS app development company Secret
Monkey Science and technical writer on Screencasts.org.
In his spare time he hacks around with hardware such as
Arduino, Raspberry Pi and Kinect.
Reprinted with permission of the original author.
First appeared in hn.my/arduino (forefront.io)
15
PROGRAMMING
recently converted a
Initial impressions:
Haxe compiles really fast.
I see compile times from 0.1 to 1 second usually 0.1. As a comparison, the same project used to see
compile times from 2-15 seconds in AS3. This is great
when youre testing out lots of small changes rapidly.
16 PROGRAMMING
Language differences
Stronger type system.
Generics
This is a huge, huge win for Haxe. If youve used AS3,
you might be familiar with how they have a parameterized Vector.<T>. Youre probably familiar with how
you got your hopes up for properly generic types and
functions, only to have them dashed when it turned
out Vector.<T> is an Adobe hardcode and you cant do
anything like it. Haxe, on the other hand, has generics
built into the language, so you can make both functions
and objects generic.
Function types
In AS3, functions have one type: Function. In Haxe,
they have many. For instance, a function that takes
an Int and converts it to a String would be Int ->
String. This catches many bugs.
No more Object.
The problem with Object from AS3 is that its
not type safe. In AS3 you can do something like this:
The first is TypedDictionary<Key, Value>. TypedDictionary is your typical key-value store: put in a key
of one type, get out a value of another.
The second is typedef. typedef is really similar to
struct from C. If youre not familiar with struct, you
can also think of it as an AS3 Object that you cant add
any more properties to. Heres an example.
typedef User = {
var age : Int;
var name : String;
}
var u : User = { age : 26, name : "Tom" };
u.age = 32;
trace(u.name);
u.xyz = 557; //Error!
for (x in 0...10)
trace(x)
Enumerations
17
Using
The using keyword allows you to add additional
methods onto existing types. The classic example of
using is the Lambda class. The Lambda class has a bunch
of static methods on it. Well use Lambda.exists as an
example. The definition looks like this:
Nice, huh?
Problems
No cross-platform Dictionary type.
The AS3 target has TypedDictionary, but sadly
it doesnt exist on all platforms. The NME target has
ObjectHash, but the problem with ObjectHash is that it
cant have primitive types (Int,String, Float, Bool)
as keys.
To solve this problem, I wrote SuperObjectHash.hx
[hn.my/soh] which combines ObjectHash and Hash
into a single interface that you can use without having
to worry about having primitive typed values.
(It was pointed out on #haxe that ObjectHash is
planned to be introduced to Haxe, and will make it in
by Haxe 3. Then my SuperObjectHash wont even be
necessary.)
18 PROGRAMMING
Closing thoughts
My overall impression? As a suffering AS3 developer,
Haxe is a dream come true. It has all the features I
wished AS3 would have and a few more. It compiles
faster than AS3 and it has better autocompletion than
AS3. It optimizes code better than AS3 (which is to say
not at all AS3 optimizes absolutely nothing). It even
has macros. Yep, a language with macros that doesnt
have parenthesis all over the place (not to speak badly
of Lisp, of course). Haxe is impressive.
Even better, Haxe doesnt feel like a dead end language. I can cross-compile to any number of platforms
with NME, which is exciting. Ive been experimenting
with using NME, which is admittedly a bit shakier than
using the AS3 libraries, but its there, and its exciting.
I no longer feel nervous about the world moving to
HTML5. Nicolas Cannasse and the Haxe team move
incredibly fast. Just the other day I noticed they were
writing a Haxe shader language and a set of generic
3D bindings that will interoperate between Flashs
Stage3D, HTML5s WebGL, and more. Wow.
I have to feel like one of the big reasons that Haxe
hasnt seen more widespread attention is that its not
English. The documentation is full of imprecise wording that feels amateur. (In fact, I spent some time cleaning it up the other day.) Its easy to draw the conclusion that the language is like the docs mismatched
and awkward but its not.
Check it out. The possibilities are wild. n
Grant Mathews is a 22-year-old senior currently attending Stanford University. He wants to prove that games can be art, and
invent the tools to make it happen.
Reprinted with permission of the original author.
First appeared in hn.my/haxe (grantmathews.com)
need
to be complicated. My security philosophy is simple:
adopt principles that will protect
you from the most frequent attack
vectors, while keeping administration efficient enough that you wont
develop security cruft. If you use
your first 5 minutes on a server
wisely, I believe you can do that.
Any seasoned sysadmin can
tell you that as you grow and add
more servers and developers, user
administration inevitably becomes
a burden. Maintaining conventional
access grants in the environment of
a fast-growing startup is an uphill
battle youre bound to end up
with stale passwords, abandoned
intern accounts, and a myriad of
I have sudo access to Server A,
but not Server B issues. There are
account sync tools to help mitigate
this pain, but IMHO the incremental benefit isnt worth the time nor
the security downsides. Simplicity is
the heart of good security.
19
Install Fail2ban
vim /etc/ssh/sshd_config
Setup A Firewall
vim /home/deploy/.ssh/authorized_keys
ufw
ufw
ufw
ufw
ALL=(ALL) ALL
ALL=(ALL) ALL
20 PROGRAMMING
I think were at a solid place now. In just a few minutes, weve locked down a server and set up a level of
security that should repel most attacks while being easy
to maintain. At the end of the day, its almost always
user error that causes break-ins, so make sure you keep
those passwords long and safe! n
Bryan Kennedy is the Co-Founder and CTO of Sincerely, helping
to scale thoughtfulness across the world. Bryan is a YCombinator
alum and an angel investor. On warm summer nights he runs
MobMov.org, a worldwide collective of guerrilla drive-ins.
Reprinted with permission of the original author.
First appeared in hn.my/5mins (plusbryan.com)
Update the file to look like below. You should probably keep updates disabled and stick with security
updates only:
Unattended-Upgrade::Allowed-Origins {
"Ubuntu lucid-security";
//
"Ubuntu lucid-updates";
};
All Done!
21
t a certain point in
every programmers
career we each find a
bug that seems impossible because
the code is right, dammit! So it
must be the operating system, the
tools, or the computer thats causing the problem. Right?!?
Todays story is about some of
those bugs Ive discovered in my
career.
22 PROGRAMMING
if (UnitIsHarvester(unit))
return X;
if (UnitIsFlying(unit)) {
if (UnitCannotAttack(unit))
return Z;
return Y;
}
... many more lines
if (! UnitIsHarvester(unit))
return Q;
return R;
23
24 PROGRAMMING
25
26 PROGRAMMING
27
Photo: flickr.com/photos/zagrobot/2731084578/
time I used
zoneedit.com as my DNS
provider of choice. All of
my important domains were hosted
there, and they never really did
me wrong. A few months back I
decided that I wanted to learn how
DNS actually works in the real
world though. Like, what does it
actually take to run my own DNS
servers?
or the longest
28 PROGRAMMING
prgmr (teroknor.bugsplat.info): 1
core, 1024MiB ram, 24GiB Disk,
160GiB transfer
ramnode (empoknor.bugsplat.
info): 4 core, 2048MiB ram,
30GiB SSD-backed Disk,
4000GiB transfer
Conclusion
Step 4: Logging
One of the more interesting aspects
of this whole project has been
getting a comprehensive view of
everything that goes on in my
little empire. The other day I set
up global logging using Papertrail
[papertrailapp.com], a hosted logging service. It doesnt do a whole
lot; mostly it just seeps up logs from
all of my services, including these
two VPSs and a bunch of Heroku
apps, makes them searchable for
a few days, and drops tarballs of
them onto S3 nightly. It has given
me really valuable insight into at
least two things: my Gmail backup
wasnt working, and I get hit a lot
by Chinese and India SSH breakin
attempts. Still working on how to
deal with that one, but the Gmail
backup is up and running.
29
a weekly basis and not uncommonly multiple times in a single week I get
this question:
n at least
30 PROGRAMMING
Editor
Ensuring youve exported your
preferred editor to the environment variable EDITOR when you run
\e will allow you to view and edit
your last run query in your editor of
choice. This works for vim, emacs,
or even sublime text.
export EDITOR=subl
psql
\e
Gives me:
SELECT *
FROM users
LIMIT 1;
id | first_name | last_name |
email
|
data
1 | Rosemary | Wassink
| rosemary@yahoo.com | "sex"=>"F"
With toggling the output and re-running the same query, we can see
how its now formatted:
\x
Expanded display is on.
craig=# SELECT * from users limit 1;
-[ RECORD 1 ]-------------------------id
| 1
first_name | Rosemary
last_name | Wassink
email
| rosemary@yahoo.com
data
| "sex"=>"F"
Using \x auto will automatically put this in what Postgres believes is the
most intelligible format to read it in.
psql history
Hopefully this needs no justification. Having an unlimited history of all
your queries is incredibly handy. Ensuring you set the following environment variables will ensure you never lose that query you ran several
months ago again:
export HISTFILESIZE=
export HISTSIZE=
\d
The last item on the list of the first things I do when connecting to any
database is check out whats in it. I dont do this by running a bunch of
queries, but rather by checking out the schema and then poking at definitions of specific tables. \d and variations on it are incredibly handy for this.
Here are a few highlights below:
Listing all relations with simply \d:
Note you need to make sure you connect with psql and have your editor
set. Once you do that, saving and
exiting the file will then execute the
query.
\x auto
psql has long had a method of for-
\d
List of relations
Schema |
Name
|
Type
| Owner
--------+------------------+---------------+------public | products
| table
| craig
public | products_id_seq | sequence
| craig
public | purchases
| table
| craig
public | purchases_id_seq | sequence
| craig
public | redis_db0
| foreign table | craig
public | users
| table
| craig
public | users_id_seq
| sequence
| craig
(7 rows)
31
n
Craig Kerstiens is part of the team at Heroku. He writes code in
Python, curates Postgresguide.com and Postgres Weekly, and
frequently speaks at conferences on those topics among others.
Reprinted with permission of the original author.
First appeared in hn.my/postgres (craigkerstiens.com)
32 PROGRAMMING
33
34 PROGRAMMING
Webhooks
Stripe uses webhooks to let our
users know when some interesting
event has happened. This ranges
from events triggered by an API
call, like charge.succeeded or
charge.refunded, to asynchronous
events like customer.subscription.trial_will_end.
35
SPECIAL
Goldeneye 64s
Inspirational Startup Story
By Alex Baldwin
rowing up,
GoldenEye
had a special place in
my heart; it was the first
game my parents wouldnt let me
buy. I saved up allowances and dug
up couch treasures for months to
taste the forbidden fruit. The effort
turned into one of the pillars of my
childhood experiences. I still vividly
remember where to place the proximity mines on Temple to get crazy
spawn point kill streaks against my
little brother. Fifteen years later, its
still inspiring me, but not for the
proximity mines.
Its hard to imagine that this
game almost didnt exist. Rares
studio head, Mark Betteridge, was
quoted as saying,
When Nintendo asked if we
wanted to do it, we said, well not
reallywe were trying to build
our on IP, and film tie-ins meant
a lot of ownership by the film
company.
The team faced insane amounts
of adversity and uncertainty. Starting out, they didnt even know
what the specs were for the new
platform. Wikipedia on the games
development:
Final N64 specifications and development workstations were not initially available to Rare: a modified
Sega Saturn controller was used
for some early play testing, and the
36 SPECIAL
people
have something that I call a
Forever Project a project
that, despite its audacity and seeming impossibility, simply will not
put itself to bed. A project that
comes creeping back into your
consciousness when you sit down
for a break from real work. A project that is hard to imagine actually
embarking on, but whose mental
cost of abandonment is far too high
to even consider. A project that
youd totally do if you had the time,
and the money, and the talent, and
the
I dont know about you, but I
adore my Forever Project (mine
happens to be a game that Ive
been punting around in various
forms since the late 1990s, and I
wouldnt be surprised if yours was
also a game of some sort). I might
not have made the progress on it
that I wish I would have, but just
having it out there as something to
think about gives me a warm, fuzzy
feeling.
think most creative
37
time there is a
romantic notion of teams
pulling crazy hours and
working all-nighters frequently. The
idea is that you can cheat the night
(or morning, for that matter) and
continue coding, writing, or doing
whatever it is you that you do.
Sometimes this is driven by maniacal managers, but other times it
comes from within.
Now, Ive already written
[hn.my/wrong] about the occasional flashes of insight which lead
to a late evening here and there.
Thats something else. Thats where
you have a fire burning inside of
you and you need to get that fire
routed through your fingers and
turned into code. You dont do
this often. Its just when things get
really good and all get flushed into
the computer at once.
This is more about the relentless
push to keep working night after
night even when theres nothing
special going on. Enough has been
written about it, but it always seems
to get really complicated in how its
described. I want to give it a simple
name that anyone can remember
and anyone else can understand.
I call it the stupid hour. When
talking about myself, I call it my
stupid hour. Its the point when
Ive been awake for too long and
anything I create is sure to be suboptimal. The late hour has drained
enough out of me to where I turn
stupid and my output shows this.
rom time to
38 SPECIAL
{
join: 'Intensive Online Bootcamp',
learn: 'Web Development',
goto: 'http://www.gotealeaf.com'
}
{
join: 'Intensive Online Bootcamp',
learn: 'Web Development',
goto: 'http://www.gotealeaf.com'
}
Tealeaf
Academy
an online school for developers
Learn Ruby on Rails | Level up Skills | Launch Products | Get a Job
39
HOSTING
Rent your IT infrastructure from
Memset and discover the incredible
benefits of cloud computing.
$0.091/GByte/month or less
99.999999% object durability
99.995% availability guarantee
RESTful API, FTP/SFTP and CDN Service
From $0.020/hour
to 4 x 2.9 GHz Xeon cores
31 GBytes RAM
2.5TB RAID(1) disk
HOSTING
hosting