Skip to content

Instantly share code, notes, and snippets.

(defn parse-lines [filename]
(with-open [rdr (clojure.java.io/reader filename)]
(line-seq rdr)))
(defn rhyme-list []
(parse-lines "Documents/dev/rhyme-finder/rhymes.txt"))
;; (count (rhyme-list))
;; IOException Stream closed java.io.BufferedReader.ensureOpen (BufferedReader.java:97)
function(doc) {
if(doc.base_doc === "CouchUser") {
var ll = new Date(doc.last_login);
var eula_date = new Date("2012-11-01");
if (!(doc.eula.signed) && (ll > eula_date ) {
emit(doc.username, doc.last_login, null);
}
}
}
rhyme-finder.core> (def poem-line (nth (get-poem "poems/test.txt") 2))
#'rhyme-finder.core/poem-line
rhyme-finder.core> (clojure.string/split poem-line #"\s")
["It" "is" "not" "quite" "the" "best"]
rhyme-finder.core> (map test-prons (clojure.string/split poem-line #"\s"))
(nil ["" "ih" "z"] ["" "n" "aa" "t"] ["" "k" "w" "ay" "t"] ["" "dh" "ah"] ["" "b" "eh" "s" "t"])
rhyme-finder.core> poem-line
"It is not quite the best"
rhyme-finder.core> (test-prons "it")
["" "ih" "t"]
; I'm trying to write this rhyme-scheme function which takes a poem(list of lines[strings]) and returns "abab" or "aabb" or "aaaa" for the rhyme scheme of the poem. THe length of the string should be the length of the line in the poems.
;I have this function classify-lines, that groups each line by it's end rhyme as shown below
;rhyme-finder.core> (classify-lines (get-poem "poems/abab.txt"))
;{("ey") ["i'm writing a poem today" "i don't care what you say"], ("eh" "l") ["i hope it turns out swell" "because we're all under a spell"]}
; This is how I started out, I'm kinda stuck on how the reduce function should go.
(defn rhyme-scheme [poem]
{ 'facets': { 'author': { 'facet_filter': { 'and': [ { 'term': { 'is_approved': True}}]},
'terms': { 'field': 'author', 'size': 9999}},
'license': { 'facet_filter': { 'and': [ { 'term': { 'is_approved': True}}]},
'terms': { 'field': 'license', 'size': 9999}},
'project_type': { 'facet_filter': { 'and': [ { 'term': { 'is_approved': True}}]},
'terms': { 'field': 'project_type',
'size': 9999}},
'region': { 'facet_filter': { 'and': [ { 'term': { 'is_approved': True}}]},
'terms': { 'field': 'region', 'size': 9999}}},
'filter': { 'and': [{ 'term': { 'is_approved': True}}]},
def _visited_in_timeframe_of_birth(case, days):
visit_time = _get_time_of_visit_after_birth(case)
time_birth = get_related_prop(case, "time_of_birth") or get_add(case) # use add if time_of_birth can't be found
if visit_time and time_birth:
print type(time_birth)
if isinstance(time_birth, datetime.date):
time_birth = datetime.combine(time_birth, datetime.time(datetime.now())) #convert date to datetime
return time_birth < visit_time < time_birth + timedelta(days=days)
return False
function (doc) {
if (doc.doc_type === 'FixtureOwnership') {
emit([doc.owner_type + ' by data_item', doc.domain, doc.data_item_id], doc.owner_id);
emit(['data_item by ' + doc.owner_type, doc.domain, doc.owner_id], doc.data_item_id);
emit(['by data_item and ' + doc.owner_type, doc.domain, doc.data_item_id, doc.owner_id], null);
}
}
function (doc) {
if (doc.doc_type === 'FixtureOwnership') {
emit([doc.owner_type + ' by data_item', doc.domain, doc.data_item_id], doc.owner_id);
emit(['data_item by ' + doc.owner_type, doc.domain, doc.owner_id], doc.data_item_id);
emit(['by data_item and ' + doc.owner_type, doc.domain, doc.data_item_id, doc.owner_id], null);
}
}
@yedi
yedi / gist:4422353
Last active December 10, 2015 10:39
pdis_by_id = {}
for pt, items in place_data_items.iteritems():
if pt == 'state':
for i in items:
print "update loop: %s" % i
pdis_by_id.update(dict((pdi.fields['id'], pdi) for pdi in items))
tree_root = []
for item in place_data_items["state"]:
item._children = []
if strict:
result = cls.view("domain/domains",
key=name,
reduce=False,
include_docs=True,
).first()
else:
result = cls.view("domain/domains",
key=name,