Skip to content

Instantly share code, notes, and snippets.

"""
Imagine you have a stream of data.
As long as the stream keeps streaming you must keep reading the data.
You can only read in x bytes of data at a time.
You must count all occurances of a search term y in the stream until
the stream stops.
Edge cases:
search term is empty
import collections
def first_unique(some_list):
dict_of_items = collections.OrderedDict()
for item in some_list:
if item in dict_of_items:
dict_of_items[item] +=1
else:
dict_of_items[item] = 1
for key in dict_of_items:
def reverse_sentence_order(forward_sentence):
backwards_sentence = ""
words_in_stack = forward_sentence.split(" ")
for x in range(0,len(words_in_stack)):
backwards_sentence = backwards_sentence+" "+ words_in_stack.pop()
return backwards_sentence[1:]
"""
Code Breakdown
--------------
@jonhurlock
jonhurlock / pleaseEscape.py
Created June 20, 2012 15:07
Example Python Code showing cURLing data and POSTing data to Elastic Search, but fails with escaped speech marks
############# My Clusters Health
curl -XGET 'http://127.0.0.1:9200/_cluster/health?pretty=true'
{
"cluster_name" : "TweetHadoop",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 15,
@jonhurlock
jonhurlock / readingfile.php
Created October 10, 2011 15:19
Example of how to read files in PHP
<html>
<head>
<title>PHP Reading from a file</title>
</head>
<body>
<h1>Output</h1>
<?php
// start of php code,
// @author Jon Hurlock (http://cs.swan.ac.uk/~csjonhurlock/)
@jonhurlock
jonhurlock / crawl.py
Created October 1, 2011 09:10
Python Web Crawler - jonhurlock
#!/usr/bin/env python
"""
Simple Indexer
=================================
Author: Jon Hurlock, October 2011
This script basically crawls a domain (not just a page) and
then extracts all links <a href=""></a>, and finds all links
on that domain it also is able extract different file types
@jonhurlock
jonhurlock / dan_jquery_ani.html
Created September 22, 2011 14:25
jquery animations for menu
<html>
<head>
<script src="http://www.sucs.org/~jonhurlock/assets/js/jquery-latest.js"></script>
<style>
#menulist li {float: left; list-style: none; padding-left: 1em;}
</style>
<script type="text/javascript">
$(document).ready(function() {