Skip to content

Instantly share code, notes, and snippets.

@swuecho
swuecho / xsl2csv.clj
Created June 8, 2012 03:50
convert all the xsl files to csv files in one directory
;;;convert all the xsl files to csv files in one directory
;get all the file names in one directory
(def directory (clojure.java.io/file "C:/Users/echo/Dropbox/7000/data-sets"))
(def files (file-seq directory))
(def filestr (map str files))
;find all the xls files in the directory
(def xlsfiles (filter #(re-find #".xls" %) filestr))
;clojure.string/replace
(defn xsl2csv [x] (save (read-xls x) (clojure.string/replace x #"xls" "csv")))
;convert all the xls file to csv files
@swuecho
swuecho / scope.pl
Created July 9, 2012 18:14
variables in perl
use Modern::Perl;
# my (a, b, c) = 1, 2, 3
my $a=2;
my $b=3;
my $c=4;
say ($a, $b, $c);
sub test {
# my $c=0;
say $a; #2
@swuecho
swuecho / scope.py
Created July 9, 2012 18:20
variables in python
a, b, c = (1, 2, 3)
print(a, b, c)
def test():
print(a)
print(b)
print(c) # (A)
c=1 # (B)
test()
@swuecho
swuecho / interact.pl
Created July 13, 2012 00:51
simulate the interact function in Haskell
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use autodie;
use Path::Class;
#use Simple::IO;
my $dir = dir("C:\\Users\\echo\\Dropbox\\bioinfo"); # /tmp
my $file = $dir->file("scope.pl");
@swuecho
swuecho / daily_80.clj
Created July 24, 2012 20:45
80_easy_anagrams
(ns playground.core)
;;http://www.reddit.com/r/dailyprogrammer/comments/x0v3e/7232012_challenge_80_easy_anagrams/
(defn anagrams? [x y]
(and (= (sort x) (sort y))
(not= x y)))
(defn anagrams [x]
(filter #(anagrams? (.toLowerCase x) %) dict))
(def dict (clojure.string/split-lines
@swuecho
swuecho / all_sum.pl
Created August 2, 2012 01:10
plain sum of several serials
# 1+2+3+..+n
sub sum_natural($n) {
my ($total,$k)=0,1;
while $k<=$n {
$total=$total+$k;
$k=$k+1;
}
return $total;
}
@swuecho
swuecho / pattern.pl
Created August 2, 2012 01:20
pattern
sub <sum_name>($n) {
my ($total,$k)=0,1;
while $k<=$n {
$total=$total+<term>;
$k=<suc>;
}
return $total;
}
@swuecho
swuecho / patern_code.pl
Created August 2, 2012 01:21
patterm code
sub sum($n,&term,&suc) {
my ($total,$k)=0,1;
while $k<=$n {
$total=$total+term($k);
$k=suc($k);
}
return $total;
}
@swuecho
swuecho / result.pl
Created August 2, 2012 01:22
functional perl result
sub successor($k){
$k+1;
}
sub cube($k) {
$k**3;
}
@swuecho
swuecho / result.pl
Created August 2, 2012 01:31
functional perl result
sub successor($k){
$k+1;
}
sub natural($k) {
$k;
}
sub pi($k) {
8/($k*($k+2));