This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-oriented-language/ | |
| module DoAsYouPlease | |
| Object.send :include, self | |
| def method_missing(name, *args, &block) | |
| self.class.const_get(name).call(*args, &block) | |
| end | |
| end | |
| Foo = proc { 42 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| def find_deps(cookbook_dir) | |
| nel = Hash.new { |h, k| h[k] = [] } | |
| Dir.glob("#{cookbook_dir}/*/").each do |r| | |
| deps_for(r, nel) | |
| end | |
| nel | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # request.port is unfortunately useless from within the app, as it | |
| # does not reflect the backend bind port, but the frontend proxy. | |
| # So we have to reverse lookup the PID to figure out our port. | |
| def backend_server_port | |
| Thread.current[:backend_server_port] ||= begin | |
| logger.debug "Attempting to reverse-lookup server port from PID file" | |
| port = nil | |
| Dir["#{RAILS_ROOT}/tmp/pids/thin.*.pid"].each do |f| | |
| pid = File.read(f).chomp.to_i | |
| if pid == $$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Include an anonymous module | |
| # | |
| # Useful for defining a class with a base module. So, instead of: | |
| # | |
| # class Foo | |
| # module Base | |
| # def bar | |
| # # ... | |
| # end | |
| # end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function echo (str) { | |
| return str | |
| } | |
| echo("Hello") | |
| (function() { | |
| echo("Goodbye") | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module EventMachine | |
| class StderrHandler < EventMachine::Connection | |
| def initialize(connection) | |
| @connection = connection | |
| end | |
| def receive_data(data) | |
| @connection.receive_stderr(data) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # git lye | |
| # An attempt to make rebasing easy, by draining unnessarcy commit noise. | |
| # No warranty, use at own risk. | |
| # Author Hannes Tydén <hannes@tyden.name> | |
| # Contributor Tobias Schmidt <ts@soundcloud.com> | |
| # TODO | |
| # - Don't sign off all commits are by current user. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| Version 2, December 2004 | |
| Copyright (C) 2011 Jed Schmidt <http://jed.is> | |
| Everyone is permitted to copy and distribute verbatim or modified | |
| copies of this license document, and changing it is allowed as long | |
| as the name is changed. | |
| DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; jneira's solution to Transitive Closure | |
| ;; https://4clojure.com/problem/84 | |
| (fn [s] | |
| (let [f #(for [[a b] % [c d] % | |
| :when (= c b)] [a d])] | |
| (->> s (iterate #(let [n (into % (f %))] | |
| (when (not= % n) n))) | |
| (take-while identity) | |
| (last)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; hyone's solution to Longest Increasing Sub-Seq | |
| ;; https://4clojure.com/problem/53 | |
| (fn longest-inc-seq [coll] | |
| (reduce #(let [len-a (count %1) | |
| len-b (count %2)] | |
| (if (and (> len-b 1) (> len-b len-a)) %2 %1)) | |
| [] | |
| (reductions | |
| (fn [xs y] |
OlderNewer