Skip to content

Instantly share code, notes, and snippets.

View ecoologic's full-sized avatar

Erik ecoologic

View GitHub Profile
@ecoologic
ecoologic / cc.coffee
Created May 2, 2014 06:28
credit card validation
cardType = (cc) ->
result = "unknown"
result = "mastercard" if /^5[1-5]/.test(cc)
result = "visa" if /^4/.test(cc)
result = "amex" if /^3[47]/.test(cc)
result
luhn = (cc) ->
sum = 0
alt = false
@ecoologic
ecoologic / x.md
Last active August 29, 2015 14:05
Template Inheritance

Similarly to the Layout Inheritance logic, if a template or partial is not found in the conventional path, the controller will look for a template or partial to render in its inheritance chain. For example:

# in app/controllers/application_controller
class ApplicationController < ActionController::Base
end

# in app/controllers/admin_controller
@ecoologic
ecoologic / basic_oo_principles.md
Last active August 29, 2015 14:06
Slides about basic principles to code Object Oriented

class: center, middle

@net_engine

@erikecoologic

Slides available at ???????


class: center, middle

Boundaries

Faster Development

I'm looking for techniques to produce the same or better result in less time (without sacrificing quality). I'd be happy to read a good fluent book on the topic.

I work for a small web app development consultancy company. Our code doesn't need to be perfect and our clients are happy to have a few non-critical bugs / imperfection and save some money. I understand.

I hate when I'm in the middle of my development and I discover some detail that forces me to rewrite part of my envisioned solution. Once I TDD a controller API that turned out to be completely useless. It didn't take too long, but it's the sort of waste I'm referring to. Another time I learned how to use a small library, but never used it. Since then I've been doing some research to avoid useless development and become more effective in general.

Searching around "faster development" or similar keywords produces mostly results that focus on tools, like snippet and shortcuts for IDE, ZSH tricks etc, I think I'm setup fine for

@ecoologic
ecoologic / when_monkeypatching
Created February 3, 2015 04:16
avoid getting screwed when you update a gem you monkey-patch
# If the behaviour the gem you're monkey patching changes
# your monkey patch might not work anymore
if Gem::Specification.all_names.detect { |gem_v| gem_v == 'haml-3.1.8' }
# my monkey patch here
else
raise "Please check this gem works with the above monkey patch"
end
@ecoologic
ecoologic / return.rb
Last active August 29, 2015 14:17
How to use return statement
# One return per line makes it easy to understand / debug
def done?
return false if no_one_done_it?
return false if not_found?
return true if you_did_it?
false
end
# Special case pattern (!= NullObject)
# Some, including Kent Beck and Martin Fowler argue that one or more guard clauses

Recycling in Brisbane

Items that can be placed in a recycling bin include:

  • All paper (including junk mail, magazines, newspapers, window envelopes)
  • Cans - aluminium and tin-plated steel cans and lids (e.g. food tins)
  • Cardboard
  • Clean kitchen aluminium foil (alfoil)
  • Empty aerosol cans (full or partially full aerosol cans are considered hazardous waste)
  • Foil pie trays
@ecoologic
ecoologic / show_presenter.rb
Created June 18, 2011 17:30
presenter for codeschool rails best practices
# /app/presenters/tweets/show.rb
module Tweets
class ShowPresenter
def initialize(tweet)
@tweet = tweet
end
def tweet
@tweet
end
@ecoologic
ecoologic / lsof3000
Created September 22, 2011 09:01
lsof | grep 3000
> lsof | grep 3000
dbus-daem 1248 emanuele 74u unix 0xf6923000 0t0 10964 socket
gvfsd 1355 emanuele 3u unix 0xee9a3000 0t0 6807 socket
tomboy 1379 emanuele mem REG 8,6 195452 1838262 /usr/lib/libgnomecanvas-2.so.0.3000.1
tomboy 1379 emanuele mem REG 8,6 84544 1838246 /usr/lib/libgnome-2.so.0.3000.0
gnome-pan 1381 emanuele mem REG 8,6 195452 1838262 /usr/lib/libgnomecanvas-2.so.0.3000.1
gnome-pan 1381 emanuele mem REG 8,6 84544 1838246 /usr/lib/libgnome-2.so.0.3000.0
nautilus 1382 emanuele mem REG 8,6 195452 1838262 /usr/lib/libgnomecanvas-2.so.0.3000.1
nautilus 1382 emanuele mem REG 8,6 84544 1838246 /usr/lib/libgnome-2.so.0.3000.0
firefox-b 1387 emanuele mem REG 8,6 30008 40566 /usr/lib/firefox-3.6.22/components/libdbusservice.so
# /etc/sysctl.conf
vm.overcommit_memory=1
# /etc/redis.conf
# comments on the same line gave problems
# custom conf 1gb, will solve a warning
maxmemory 1073741824
# commenting these three lines will avoid redis to dump the db at all