This file contains hidden or 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
(require '[clojure.string :as string]) | |
(defn is-vowel? [character] | |
(contains? #{\a \e \i \o \u} character)) | |
(defn remove-last-vowel [word] | |
(defn go [xs flag] | |
(cond | |
(or (empty? xs) flag) | |
xs |
This file contains hidden or 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
module Arrows where | |
import Control.Arrow | |
import System.Directory (doesDirectoryExist) | |
-- `arr` lifts a function to an arrow | |
-- arr :: (b -> c) -> a b c | |
-- e.g. pure function (+ 2) :: Integer -> Integer | |
-- b :: Integer |
This file contains hidden or 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
<?php | |
class WithFileContents { | |
private $resource = null; | |
private function open($f) { | |
$this->resource = fopen($f, "r"); | |
} | |
public function run($resource, $fun) { |
This file contains hidden or 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
total = sum( | |
sapply( | |
sapply(my_df$ratios, as.character), | |
as.numeric) | |
) |
This file contains hidden or 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
library(RMySQL) | |
library(GetoptLong) | |
# had to work with a secure connection to a MySQL | |
# make a option file, e.g. opts.cnf | |
" | |
[client] | |
user=kenny | |
host=mysqldb | |
ssl-ca=ca.crt |
This file contains hidden or 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
# hit a snag time when working with session ids (represented as bigint in a database) | |
df <- read.csv("myData.csv", header=TRUE) # sid is the column | |
" | |
> tail(df, n=1)$sid | |
[1] 2e+18 | |
" | |
# WTF moment |
This file contains hidden or 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
CREATE OR REPLACE FUNCTION fa.double_book_keeping_check() RETURNS trigger | |
AS $$ | |
BEGIN | |
IF TG_TABLE_NAME='reports' THEN | |
IF NEW.total_assets = (NEW.total_equity + NEW.total_liabilities) THEN | |
RETURN NEW; | |
ELSE | |
RAISE EXCEPTION 'BOOK KEEPING ERROR: TOTAL ASSETS DOES NOT MATCH SUM(TOTAL LIABILITIES, TOTAL EQUITY)!'; | |
END IF; | |
END IF; |
This file contains hidden or 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
# calculating annual maxima from a time series (df) | |
df$year <- floor_date(df$date, "year") | |
df_maxima <- ddply(df, "year", summarise, orders=max(orders)) | |
head(arrange(df_maxima, desc(orders), 3) # top 3 |
This file contains hidden or 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
lhs = reshape([2, -1, 0, -1, 2, -3, 0, -1, 4], 3, 3) | |
rhs = reshape([0, -1, 4], 3, 1) | |
soln = lhs\rhs | |
print((lhs * soln) == rhs) # prove it so |
This file contains hidden or 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
# So R can solve linear algebra too! | |
lhs <- matrix(c(2, -1, 0, -1, 2, -3, 0, -1, 4), nrow=3) | |
" | |
[,1] [,2] [,3] | |
[1,] 2 -1 0 | |
[2,] -1 2 -1 | |
[3,] 0 -3 4 | |
" |
NewerOlder