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
{-# LANGUAGE GeneralizedNewtypeDeriving, FlexibleInstances #-} | |
module Sized where | |
import Data.Monoid | |
newtype Size = Size { getSize :: Int } | |
deriving (Eq, Ord, Show, Num) | |
class Sized a where | |
size :: a -> Size |
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
{-# LANGUAGE OverloadedStrings #-} | |
module PraseJsonSample where | |
import Data.Aeson ((.:), (.:?), decode, FromJSON(..), Value(..)) | |
import Control.Applicative ((<$>), (<*>)) | |
import Data.Time.Format (parseTime) | |
import Data.Time.Clock (UTCTime) | |
import System.Locale (defaultTimeLocale) | |
import Control.Monad (liftM) | |
import qualified Data.HashMap.Strict as HM |
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 Optional a = Invalid | Valid a | |
deriving (Show) | |
optionalToString :: (Show a) => Optional a -> String | |
optionalToString Invalid = "Not Valid" | |
optionalToString (Valid value) = show value | |
safeRoot :: Double -> Optional Double | |
safeRoot x | |
| x >= 0 = Valid (sqrt x) |
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
def self.to_csv(options: { col_sep: "," } , column_names: self.column_names, messages: limit(1000)) | |
CSV.generate(options) do |csv| | |
csv << column_names.push(*["Annotation Reason", "Annotation Notes"]) | |
messages.each do |message| | |
attributes = message.attributes.values_at(*column_names) | |
attributes.push(*get_annotation_data_for_message(message)) | |
csv << attributes | |
end | |
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! OpenTestOrProduction() | |
let current_file_without_extension = expand("%:r") | |
let filename_parts = split(current_file_without_extension, "_") | |
let target_file = "" | |
if IsInTestFile() | |
let main_name_parts = filename_parts[0:-2] | |
let target_file = CreateTargeFilename(main_name_parts) | |
else | |
let target_file = CreateTargeTestFilename(current_file_without_extension) | |
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 'net/http' | |
require 'json' | |
module Bing | |
class Search | |
BASE_URL = "https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Composite?" | |
SINGLE_QUOTE_ENCODED = "%27" | |
def initialize(api_key) | |
@api_key = api_key |
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
(defn swap-pairs [items] | |
(into (empty items) | |
(interleave (take-nth 2 (drop 1 items)) | |
(take-nth 2 items)))) | |
(swap-pairs [1 2 3 4 5 6]) ;=> [2 1 4 3 6 3] |
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
class Mutator | |
def initialize(ruby_file) | |
@ruby_file = ruby_file | |
end | |
def run_test | |
spec_file_name = @ruby_file.split(/\./)[0] | |
system("rspec #{spec_file_name}_spec.rb") | |
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
(define make-pair (a, b) | |
(lambda (pick) | |
(cond (= pick 1) a) | |
(cond (= pick 2) b))) | |
(define car (x) (x 1)) | |
(define cdr (x) (x 2)) |
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
class Closest | |
MAX = 2000000000000 | |
def to_zero(input) | |
raise IllegalArgumentException if input.nil? || input.empty? | |
closest_to_zero = MAX | |
@least_distance = MAX | |
input.each do |num| | |
if closer_to_zero(num) |