Skip to content

Instantly share code, notes, and snippets.

View mamonu's full-sized avatar
🎯
Focusing

Theodore M mamonu

🎯
Focusing
View GitHub Profile
@mamonu
mamonu / fizzbuzz.clj
Created June 14, 2015 22:43
fizzbuzz implementation in clojure ;)
(defn fizzbuzz [n]
(let [all-nums (range 0 n)
folder (fn [fb-str p-num fb-coll]
(mapcat (fn [x] (cons fb-str (rest x)))
(partition-all p-num fb-coll)))
fizz (folder "fizz" 3 all-nums)
buzz (folder "buzz" 5 fizz)
fizzbuzz (folder "fizzbuzz" 15 buzz)]
fizzbuzz))
@mamonu
mamonu / entropycalc.clj
Last active August 29, 2015 14:23
entropy calculation
;; Get a 1Mn random numbers to calculate entropy over
(def ps (vec (repeatedly 1e6 rand)))
;; entropy function
(defn entropy [p]
(* p (Math/log p)))
@mamonu
mamonu / piglatin.clj
Created June 14, 2015 23:19
piglatin function in clojure ;)
(def vowel? (set "aeiou")) ; sets are functions of their items (to test contains)
(defn pig-latin [word]
; word is expected to be a string
; which can be treated like a sequence of characters.
(let [first-letter (first word)] ; assigns a local variable
(if (vowel? first-letter)
(str word "ay") ; then part of if
(str (subs word 1) first-letter "ay")))) ; else part of if
@mamonu
mamonu / chr2int.clj
Created June 22, 2015 21:29
chr2int in clojure
(defn chr->int [c]
(-> (char c)
(str)
(Integer.)))
@mamonu
mamonu / echochamber.js
Created July 17, 2015 12:49
echochamber.js
<script id="echochamber">
var EchoChamber = window.EchoChamber || {};
(function() {
EchoChamber.discussionURL = window.location;
var script = document.createElement('script');
script.src = 'https://s3.amazonaws.com/echochamberjs/dist/main.js';
script.async = true;
var entry = document.getElementById('echochamber');
entry.parentNode.insertBefore(script, entry);
})();
@mamonu
mamonu / carcsv.py
Last active August 29, 2015 14:25 — forked from btashton/carcsv.py
pyspark csv
from pyspark import SparkContext
from pyspark.sql import SQLContext
from pyspark.sql.types import *
from IPython.display import display
sc = SparkContext(appName="CarCSV")
sqlContext = SQLContext(sc)
schema = StructType([StructField("year", IntegerType(), False),
StructField("make", StringType(), False),
@mamonu
mamonu / mydef.css
Created July 25, 2015 17:29
a default stylesheet
div, span {
box-sizing: border-box;
position: relative;
display: flex;
flex-direction: column;
align-items: stretch;
flex-shrink: 0;
border: 0 solid black;
(ns ruby-to-clojure.seq-utils)
(defn map-with-index
"Like clojure/map, but f should accept 2 arguments: the element and its index
in the collection."
[f coll]
(map f coll (iterate inc 0)))
(defn some-index
"Returns the index of the first element of coll for which (f elem) returns
pyg = 'ay'
original = raw_input('Enter a word:')
word=original.lower()
first = word[0]
new_word=word+first+pyg
new_word=new_word[1:len(new_word)]
if len(original) > 0 and original.isalpha():
print new_word
@mamonu
mamonu / functional.cpp
Last active August 29, 2015 14:25
Functional Programming in C++ . You need g++ 4.9 and newer to compile this code with: g++ -std=c++11 functional.cpp
#include <iostream>
#include <vector>
#include <algorithm>
/**
Example showing the function programming ideas in
C++ 11. Features used here are part of standard language.
**/
template <typename Collection,typename unop>