Skip to content

Instantly share code, notes, and snippets.

View dnch's full-sized avatar

Dan Cheail dnch

  • melbourne, au
View GitHub Profile
@dnch
dnch / gist:667486
Created November 8, 2010 08:46
Ruby or Perl?
Zip::ZipFile.open(f).read("data.txt").to_a.map { |x| x.chomp.split("|") }.delete_if { |x| x[2] == "KX" }.map { |a| BigDecimal(a.last) }.inject(0) { |sum, x| sum + x }
@dnch
dnch / intro.md
Created October 11, 2010 04:42 — forked from radar/intro.md

Ruby Intro - Setlist

  • no fucking semi-colons (unless you really want them)
  • irb
  • local variable definition
  • +, *, /, - are all methods
  • puts vs print
  • multiplying strings
  • using if & when
  • defining a method
Because ImageMagick likes to remove tarballs, we're downloading their
stable release from their SVN repo instead. But they only serve the
repo over HTTPS, and have an untrusted certificate, so we auto-accept
this certificate for you.
If this bothers you, open a ticket with ImageMagick to fix their cert.
Feature: Starting the Applcation
In order to avoid reprimands from my boss
As a disobedient little hacker, desperate to flagrantly break IT policy
I want to use Twitter in a stealthy manner
ZSH_THEME_GIT_PROMPT_PREFIX=""
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_CLEAN=" %F{46}±"
ZSH_THEME_GIT_PROMPT_DIRTY=" %F{196}±"
function codeape_prompt {
# set up the biggest possible middle padding we'd need
(( spare_width = ${COLUMNS} ))
prompt=" "
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jquery => case Rails.env
when "production" then ["http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js", "application", "etc"]
when "development" then %w(jquery jquery-ui jquery-typewatch rails application)
end
= form_for @enquiry || Enquiry.new, :remote => true, :builder => Paragon::Builder, :html => { :class => "paragon" } do |f|
%fieldset.horizontal
= f.text_field :name
= f.text_field :company_name
= f.text_field :email_address
= f.text_field :contact_number
= f.text_area :message
require 'net/imap'
imap = Net::IMAP.new("imap.gmail.com", { :ssl => true })
imap.login("username", "password")
imap.status("INBOX", ["UNSEEN"])
imap.select("INBOX")
imap.search(["UNSEEN"]) # => message ids
t = imap.fetch(message_id, "RFC822").first.attr["RFC822") # => whole message in RFC822
Mail.new(t)
var CallbackObject = {
task_a_done = false,
task_b_done = false,
trigger = function(which_task) {
if(which_task == "A") { this.task_a_done = true; }
if(which_task == "B") { this.task_a_done = true; }
if(this.task_a_done && this.task_b_done) {
trigger_task_c();
}
grey='\e[0;90m'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$grey%}("
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$grey%}) %{$fg[yellow]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$grey%})"
function pat_prompt {
(( spare_width = ${COLUMNS} ))
prompt=" "