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
from collections import defaultdict | |
def str_md(lexicon,key, value): | |
"""Generic append key, value to lexicon""" | |
lexicon.setdefault(key,value) | |
# Desired sort order | |
complist = ['Red', 'Apple', 'Green', 'Tea', 'Purple', 'Haze'] | |
# Dictionary order | |
alphalist = sorted(complist) | |
# Create empty dictionary |
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
x <- c("dplyr", "ggmap", "ggplot2", "RColorBrewer", "rgdal", "classInt", "RCurl", "grid","gridExtra") | |
lapply(x, library, character.only = TRUE) | |
no_ylab = ylab("") | |
no_xlab = xlab("") | |
plain_theme = theme(axis.text=element_blank()) + theme(panel.background = element_blank(), panel.grid = element_blank(), axis.ticks = element_blank()) | |
remove.farflung = function(.df) { | |
subset(.df, |
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
Alabama | 01 | AL | |
---|---|---|---|
Alaska | 02 | AK | |
Arizona | 04 | AZ | |
Arkansas | 05 | AR | |
California | 06 | CA | |
Colorado | 08 | CO | |
Connecticut | 09 | CT | |
Delaware | 10 | DE | |
District of Columbia | 11 | DC | |
Florida | 12 | FL |
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
intervals = function(.df, ...){ | |
argList = match.call(expand.dots=FALSE)$... | |
for(i in 1:length(argList)){ | |
colName <- argList[[i]] | |
series_colName = eval(substitute(colName), envir=.df, enclos=parent.frame()) | |
min <- min(series_colName) | |
max <- max(series_colName) | |
diff <- max - min | |
std <- sd(series_colName) | |
equal.interval <- seq(min, max, by = diff/6) |
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
x = c("ggplot2", "classInt", "dplyr", "rgdal", "maptools", "mapproj", "rgeos", "RCurl") | |
lapply(x, library, character.only = TRUE) | |
intervals = function(.df, ...){ | |
argList = match.call(expand.dots=FALSE)$... | |
for(i in 1:length(argList)){ | |
colName <- argList[[i]] | |
series_colName = eval(substitute(colName), envir=.df, enclos=parent.frame()) | |
min <- min(series_colName) | |
max <- max(series_colName) | |
diff <- max - min |
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
> ls(pattern = 'all') | |
[1] "allid" "allpct" "allpop" | |
> objs <- ls(pattern = 'all') | |
> str(objs) | |
chr [1:3] "allid" "allpct" "allpop" | |
> class(objs) | |
[1] "character" | |
> mode(objs) | |
[1] "character" | |
> typeof(objs) |
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
import nltk | |
from nltk.chunk import * | |
from nltk.chunk.util import * | |
from nltk.chunk.regexp import * | |
from nltk import Tree | |
cp = nltk.RegexpParser('CHUNK: {<NN> <VB> <IN> <NN>}') | |
bucket = [] | |
brown = nltk.corpus.brown | |
for sent in brown.tagged_sents(): |
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
-- readyaml.hs demonstration | |
{-# LANGUAGE OverloadedStrings #-} -- yaml | |
import Control.Applicative | |
import Data.Yaml | |
import Data.Maybe (fromJust) | |
data ReadData = ReadData { stripComments :: Bool -- these are constructors | |
, stripLable :: Bool | |
, zeroDot :: Bool | |
, justifyLeft :: Bool |
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
import Control.Monad.IO.Class (liftIO) | |
import Control.Monad.Trans.Resource | |
import Data.Conduit | |
import qualified Data.Conduit.Binary as CB | |
import qualified Data.Conduit.List as CL | |
import qualified Data.Conduit.Text as CT | |
main :: IO () | |
main = runResourceT |
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
# KJVurl.py | |
# convert a list of verse citations, one to a line in the form 'Judges 2:2' into markdown formatted links to the corresponding verse in an online service | |
# this example depends on a correspondence of the url to the verse by simple substitution of a hyphen for each blank or colon | |
# for iOS7 pythonista, due to reliance on clipboard module | |
import re | |
import clipboard | |
# site whose citation scheme will be usef | |
baseref = "http://www.kingjamesbibleonline.org/" |
OlderNewer