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 Helper | |
| # ... | |
| class << self | |
| def included(base) | |
| base.class_eval do | |
| (class << self; self; end).class_eval do | |
| alias_method :__new, :new | |
| private :__new | |
| define_method(:new) do |*args| |
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 Window < Gtk::Window | |
| include Helper | |
| def initialize | |
| # @stocks, @icons, etc will already be defined at this point | |
| end | |
| end | |
| window = Window.new |
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 Fixnum | |
| def to_fixnum | |
| self | |
| end | |
| end | |
| class Bignum | |
| def to_fixnum | |
| self[Fixnum::BITS] == 1 ? ~(~(self) & Fixnum::MAX) : self & Fixnum::MAX | |
| 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
| class Proc | |
| def to_proc | |
| if lambda? | |
| takes = arity | |
| flexible = takes < 0 | |
| required = flexible ? ~takes : takes | |
| proc do |*args, &block| | |
| args = args.size == 1 && Array === args[0] ? args[0] : args | |
| given = args.size | |
| if not flexible and given > required |
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
| shane@awub:~$ irb | |
| irb(main):001:0> class A | |
| irb(main):002:1> def self.foo | |
| irb(main):003:2> 'foo' | |
| irb(main):004:2> end | |
| irb(main):005:1> end | |
| => nil | |
| irb(main):006:0> class B < A | |
| irb(main):007:1> end | |
| => nil |
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
| tr = (^2) . ((-)1) . (2*) | |
| tl n = tr n - 2 * (n - 1) | |
| br n = tr n - 4 * (n - 1) | |
| bl n = tr n - 6 * (n - 1) | |
| putStrLn $ show $ (+1) $ sum $ map (\f -> sum $ map f [2..501]) [tr, tl, br, bl] |
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
| factory :ShoppingAssistant do | |
| creating :ShoppingList | |
| subtypes :SinglePerson, :Couple, :RetiredCouple | |
| creators :Weekday, :Weekend, :SummerHoliday, :WinterHoliday | |
| end | |
| data :SinglePerson do | |
| Weekday "Sandwich" | |
| Weekend "Pizza" | |
| SummerHoliday "Sangria" |
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
| import Data.Char | |
| atLeastOneFollowedByAndThen f c g [] = False | |
| atLeastOneFollowedByAndThen f c g (x:xs) = f x && yys /= [] && y == c && g ys | |
| where yys = dropWhile f xs | |
| ~(y:ys) = yys | |
| isEmail = atLeastOneFollowedByAndThen isAlphaNum '@' isDomain | |
| isDomain = atLeastOneFollowedByAndThen isAlphaNum '.' (\t -> isTerminator t || isDomain t) | |
| isTerminator = (`elem` ["com", "net", "org", "ie"]) |
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
| path "div" (do n <- getParam "n" | |
| writeBS $ B.pack $ show $ div (100::Int) (read $ B.unpack $ fromJust n)) |
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 DeriveDataTypeable #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| module Server(templateServer,server,AppConfig(..),emptyServerConfig) where | |
| import Control.Applicative | |
| import Control.Concurrent | |
| import Control.Exception (SomeException) | |
| import Control.Monad.CatchIO | |
| import Data.ByteString.Char8 (ByteString) |
OlderNewer