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
| CREATE OR REPLACE FUNCTION lock_head() RETURNS SETOF jobs AS $$ | |
| DECLARE | |
| unlocked integer; | |
| job jobs%rowtype; | |
| BEGIN | |
| SELECT id INTO unlocked | |
| FROM jobs |
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
| var palindrome = function(center){ | |
| var first = center.slice(0,1); | |
| var last = center.slice(-1); | |
| var mid = center.slice(1,-1); | |
| if(mid == "") { print("true"); return;} | |
| if(first == last) { palindrome(mid); } | |
| else { print("false"); } |
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
| (ns sicp | |
| (:use clojure.test)) | |
| (defn square [num] (* num num)) | |
| (defn sum-of-squares [x y] (+ (square x) (square y))) | |
| ; assume x != y != z | |
| (defn sum-of-larger-squares [x y z] | |
| (cond | |
| (and (< x y) (< x z));x is the smallest | |
| (sum-of-squares y z) |
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
| # copied from @solidsnack | |
| nethack on | |
| vbell on | |
| defutf8 on | |
| defscrollback 16384 | |
| backtick 1 1 1 date -u +%Y-%m-%dT%TZ | |
| logtstamp on |
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
| data = (1..1_000).to_a | |
| measure "sum" do | |
| data.sum { |n| n } | |
| end | |
| measure "inject" do | |
| data.inject(0) { |sum, element| sum + element} | |
| 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
| require 'extensions/all' | |
| class String | |
| def peel() | |
| return nil if self.length.zero? | |
| self.strip | |
| end | |
| end | |
| class Seeker | |
| attr_accessor :origin, :destination, :includes, :query |
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
| PRECISION = 0.0001 | |
| def newtonian_guess( guess,fx,fdx ) | |
| loop do | |
| better_guess = guess - ( fx.call( guess ).to_f / fdx.call( guess ).to_f ) | |
| return better_guess if ((better_guess - guess).abs <= PRECISION) | |
| guess = better_guess | |
| 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
| # Foraker, I wanted to give you a fresh code sample; not something that has been lying in my home dir. | |
| # for a year. | |
| # I was reading about tries the other day and decided to implement something in ruby. I built this code | |
| # this morning and it has not gone through any refactorings. | |
| # I want to showcase my ruby knowledge along with knowledge of data structures & algorithms. | |
NewerOlder