Skip to content

Instantly share code, notes, and snippets.

View technocrat's full-sized avatar

Richard Careaga technocrat

  • Woodinville, WA, USA
  • 08:30 (UTC -12:00)
View GitHub Profile
@technocrat
technocrat / comp.py
Created January 13, 2015 02:50
Python snippet to sort in arbitrary order
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
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,
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
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)
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
> 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)
@technocrat
technocrat / gist:9ae8db10da4be357efd8
Created October 9, 2015 01:45
Preparation of text to find specific pattern of words and then collect matches with a specific keyword in a list
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():
@technocrat
technocrat / readyaml.hs
Created December 26, 2015 00:43
Demonstration of reading yaml from file
-- 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
@technocrat
technocrat / lineatime.hs
Created December 26, 2015 01:33
Read from file and output one line at a time
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
@technocrat
technocrat / KJVurl.py.py
Created January 19, 2014 05:58
KJVurl.py
# 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/"