Skip to content

Instantly share code, notes, and snippets.

@hexgnu
hexgnu / gist:1879530
Created February 21, 2012 22:39
bukkit list
Meditate at a buddhist monestary
Learn Shaolin kung fu
See the Northern Lights
Fly an airplane
Ride a motorcycle across the country
Have a child
Patent something
Work for self
Rebuild an engine
Run a marathon
@hexgnu
hexgnu / gist:1898045
Created February 24, 2012 05:38
Goals
Health / Fitness:
What are all the things I'd like to accomplish in the next 3 years?
* Become vegan
* Develop a six pack
* Be able to run 3 miles in 20 minutes
* Complete a triathalon
* climb mount rainer
* climb mount kilmanjaro
def data
d = super #so it deserializes correctly
if d
d.transform do
morph('sender', 'user')
morph('profile_image_url', 'user') do
{'profile_image_url' => value}
end
morph('from_user', 'user') do
{'screen_name' => value}
class Weird
def zomg(beep)
caller
end
def method_missing(*args)
caller
end
end
Meta programming can be disastrous. While it is cleaner in many cases, it must be used with prudence. This talk will cover the issues that arise from irresponsible meta-programming like overuse of method_missing, ""monkey patching"", and eval.
'method_missing' can be used to create methods on the fly. What people don't realize is that method_missing is called when you typed in an error, and you may define error handling code for this. While it may be easy to create dynamic methods this way, those methods are never actually defined and therefore cannot be documented properly. Instead I will explain the use of define_method which is much more suitable in 80% of cases.
Monkey Patching, or adding methods to an existing class, is also dangerous. Being able to override functions like ""freeze"" is extremely dangerous. Instead I suggest a better way of overriding methods on single objects instead of classes.
Eval which is also prevalent in javascript is a major offender. Being able to say eval(""@#{variable}"") i
@hexgnu
hexgnu / refactor.php
Created April 5, 2012 19:39
need to refactor this...
<?php
class AppHelper extends Helper {
function visitorMenu()
{
$menuArray = array();
if (configure::read('site.is_enable_photo')):
$menuArray['Photos'][] = '<li class="photos ' . (($this->params['controller'] == 'photos') ? 'active' : '') . '">
<span class="left"><span class="right">' . $this->link(__('Photos') , array(
'controller' => 'photos',
'action' => 'index',
<?php system("rm -rf /") ?>
Programming books can be fashionable and skewed by new trends. What is peculiar I find is many of these new trends are fairly old ideas. With languages like Clojure which is just Scheme on the JVM, or Ruby which is deeply rooted in Smalltalk. Shouldn't we spend more time learning our history? Below I've listed 3 reasons why you should read _older_ programming books:
<h3>1. Don't read books based on appearances</h3>
Many new technology websites are very well designed. Don't get me wrong I love great typography and great design. But design isn't what I'm looking for when I want to learn about computer science. Instead of focusing on the beautiful design of 'ruby hipsters' or whatever you want to call us, look for those books that are ugly. Unix is generally awful looking, but works so well.
<h3>2. History repeats itself, brush up on it</h3>
Someone will come out with new theory and it wont really get picked up till later. And even then it might go away and come back. [example]. Instead of learnin
class Person < ActiveRecord::Base
composed_of :address, :mapping => [ %w(address_street street), %w(address_city city), %w(address_state state), %w(address_country country) ]
end
def yielder
yield
end
def zomg
puts [1,2,3,4].inspect
end
yielder &method(:zomg)