Skip to content

Instantly share code, notes, and snippets.

View dyba's full-sized avatar

M. Daniel Dyba dyba

View GitHub Profile
@dyba
dyba / example.clj
Created December 3, 2012 16:49
Maintaining State in Clojure
(defn ^:private progress-input-stream
[^java.io.InputStream input-stream size]
(let [total-read (atom 0)]
(proxy [java.io.InputStream] []
(available []
(.available input-stream))
(close []
(.close input-stream))
(read
([]
@dyba
dyba / movie.rb
Created August 6, 2012 05:41
Testing a class method
class Movie < ActiveRecord::Base
def self.all_ratings
# debugger
find_by_sql("SELECT DISTINCT rating FROM movies").map(&:rating)
end
end
@dyba
dyba / application_helper.rb
Created August 1, 2012 03:04
Testing a helper method with a minimalist approach
module ApplicationHelper
def highlight_tag_if(condition, tag, &block)
if condition
content_tag tag, :class => 'hilite', &block
else
content_tag tag, &block
end
end
end
@dyba
dyba / asa_cmds_rule_deletion.rb
Created January 27, 2012 16:18
Cisco ASA Firewall Rule Deletion Generator via RedSeal Device Cleanup Analysis Results
#
# PURPOSE:
# The purpose of this script is to generate a list of commands to delete unused access rules from a
# Cisco PIX or ASA firewall. This script is appropriate if you use the RedSeal application:
# http://www.redsealnetworks.com. Currently the results are printed to the screen only.
#
# INSTRUCTIONS:
# When you want to clean up unused rules on a firewall. Use the RedSeal application to run a cleanup:
# Tools > Manage Device Cleanup (Alt+T, C). When finished, export the results as a CSV file. Don't
# forget to include the .CSV extension. Run this script and type the name of the file with the
@dyba
dyba / recursions.clj
Created January 21, 2012 00:14
Clojure Koans - Factorial
;; Earlier attempt
(defn factorial [n]
(loop [n n
result n]
(if (<= n 1)
1
result)
(recur (dec n) (* result (dec n)))))
;; Working so far
@dyba
dyba / recursions.clj
Created January 16, 2012 01:30
Clojure Koans - Stuck
(defn is-even? [n]
(if (= n 0)
(not false)
(recur (is-even? (dec n)))))
(meditations
"Recursion ends with a base case"
(= true (is-even? 0))
"And starts by moving toward that base case"
@dyba
dyba / karate_chop_2.rb
Created November 10, 2011 23:58
Karate Chop - Take Two
def chop(int, array_of_int)
return -1 if array_of_int.empty?
@max ||= array_of_int.size - 1
@min ||= 0
@mid ||= @max / 2 + @min
return @mid if int == array_of_int[@mid]
return -1 if @mid == @max
@dyba
dyba / application.html.haml
Created November 1, 2011 02:35
Jasmine YML file
!!! 5
%html
%head
%title TESTAPP
= stylesheet_link_tag "application"
= javascript_include_tag "application", "registration"
= csrf_meta_tag
%body
%header
%h1#logo