This file contains 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
listName: | |
item1 | |
item2 | |
item3 |
This file contains 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 Main where | |
First, import all the needed modules. | |
> import Text.Parsec hiding (State) | |
> import Text.Parsec.Indent | |
> import Control.Monad.State | |
Next, define our new Parser type. This replaces the Identity monad | |
with the (State SourcePos) monad. |
This file contains 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 #-} | |
module Main where | |
-- Using strict imports so that we know where stuff comes from. | |
import Data.Generics (Data, Typeable) | |
import Text.JSON.Generic (JSValue, toJSON) | |
import Text.JSON.Pretty (render, pp_value) | |
data SuperHeroes = Batman { phrase :: String } |
This file contains 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
saveGrams :: (Serialize a, Serialize b) => DB -> [(a, b)] -> IO () | |
saveGrams db pairs = mapM_ put' pairs | |
where | |
put' (gram, indicies) = put db [] (encode gram) (encode indicies) |
This file contains 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 #-} | |
module Main where | |
import Data.Generics (Data, Typeable) | |
import qualified Data.Binary as B | |
import Data.Binary.Generic -- binary-generic package | |
import Text.JSON.Generic (JSValue, toJSON) | |
import Text.JSON.Pretty (render, pp_value) |
This file contains 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
/** | |
* A simple program to print a sequence of messages. | |
**/ | |
#include <stdint.h> | |
#include <stdio.h> | |
/* A message holds the string we want to print and has a slot to store the next | |
* message to be printed (should one be queued up). */ | |
typedef struct Message_S { |
This file contains 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
$ pry | |
[1] pry(main)> x = {} | |
=> {} | |
[2] pry(main)> x["hello"] = 1 | |
=> 1 | |
[3] pry(main)> x['hello'] = 2 | |
=> 2 | |
[4] pry(main)> x | |
=> {"hello"=>2} |
This file contains 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
# This function asks svn to list the status of all | |
# files in the repository. Then we filter out files | |
# that aren't versioned and aren't files. | |
# See also: svn help st | |
# $ svn help st | |
# status (stat, st): Print the status of working copy files and directories. | |
# ... | |
# With -v, print full revision information on every item. |
This file contains 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
# To install prerequisites for this sample code, run | |
# the following commands in a directory with all the | |
# files in this gist: | |
# | |
# > gem install bundler | |
# > bundler install | |
source "http://rubygems.org/" | |
gem "thor", "0.15.4" |
This file contains 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 String | |
# This method will return an array of MatchData's rather than the | |
# array of strings returned by the vanilla `scan`. | |
def match_all(regex) | |
match_str = self | |
match_datas = [] | |
while match_str.length > 0 do | |
md = match_str.match(regex) | |
break unless md | |
match_datas << md |