This time I have made a small Midi Piano...and excuse my total lack of Piano skills -:(
For this I used Python, AdaFruit_BBIO, PyGame and Timidity++.
Greetings,
Blag.
Development Culture.
My Rants related to SAP, Scripting Languages, Technologies and everything else I wanted to talk about...
Hashtags.js |
---|
var system = require('system'); var webpage = require('webpage').create(); webpage.viewportSize = { width: 1280, height: 800 }; webpage.scrollPosition = { top: 0, left: 0 }; var userid = system.args[1]; var profileUrl = "http://www.twitter.com/" + userid; webpage.open(profileUrl, function(status) { if (status === 'fail') { console.error('webpage did not open successfully'); phantom.exit(1); } var i = 0, top, queryFn = function() { return document.body.scrollHeight; }; setInterval(function() { top = webpage.evaluate(queryFn); i++; webpage.scrollPosition = { top: top + 1, left: 0 }; if (i >= 5) { var twitter = webpage.evaluate(function () { var twitter = []; forEach = Array.prototype.forEach; var tweets = document.querySelectorAll('[data-query-source="hashtag_click"]'); forEach.call(tweets, function(el) { twitter.push(el.innerText); }); return twitter; }); twitter.forEach(function(t) { console.log(t); }); phantom.exit(); } }, 3000); }); |
TwitterHashtags.go |
---|
package main import ( "os/exec" "strings" "fmt" ) func main() { cmd := exec.Command("phantomjs","--ssl-protocol=any","Hashtags.js", "Blag") out, err := cmd.Output() if err != nil { println(err.Error()) return } Tweets := strings.Split(string(out), "\n") charmap := make(map[string]int) for _, value := range Tweets { if value != "" { charmap[value] += 1 } } for key, value := range charmap { if value >= 5 { fmt.Print("(", key, ", ") fmt.Println(value, ")") } } } |
LED.go |
---|
package main import ( "fmt" "strconv" "strings" ) func main() { fmt.Print("Enter a number: ") var num int var list []string var line1, line2, line3 string fmt.Scanf("%d", &num) numList := strings.Split(strconv.Itoa(num), "") romans := map[string]string { "0" : " _ ,| | ,|_| ", "1" : " ,| ,| ", "2" : " _ , _| ,|_ ", "3" : "_ ,_| ,_| ", "4" : " ,|_| , | ", "5" : " _ ,|_ , _| ", "6" : " _ ,|_ ,|_| ", "7" : "_ , | , | ", "8" : " _ ,|_| ,|_| ", "9" : " _ ,|_| , _| ", } for _, value := range numList { list = strings.Split(romans[value],",") line1 += list[0] line2 += list[1] line3 += list[2] } fmt.Println(line1) fmt.Println(line2) fmt.Println(line3) } |
Fibonacci.go |
---|
package main import ( "fmt" "strconv" ) func main() { fmt.Print("Enter a number: ") var num int fmt.Scanf("%d", &num) fmt.Print(fib(num, 0, 1)) } func fib(num int, a int, b int) string{ var result string if a > 0 && num > 1 { result += strconv.Itoa(a+b) + " " + fib(num-1, a+b, a) } else if a == 0 { result = strconv.Itoa(a) + " " + strconv.Itoa(b) + " " + strconv.Itoa(a+b) + " " + fib(num-1, a+b, b) } return result } |
LED.rkt |
---|
#lang racket (define (showLED num) (display(get_led(toList num num 0 1) 1 num))) (define (toList num num_o start end) (cond [(number? num) (toList(number->string num) (number->string num_o) start end)] [(and (string? num) (> (string-length num_o) 1)) (append (cons(substring num start end) '()) (toList num (substring num_o 1 (string-length num_o)) (add1 start)(add1 end)))] [(and (string? num) (= (string-length num_o) 1)) (append (cons(substring num_o 0 1) '()))])) (define (get_led x n num) (cond [(> (length x) 0) (append (cons(make_led_digit (string->number(first x)) n) '()) (get_led(rest x) n num))] [(and (= (length x) 0) (< n 3)) (append '("\n") (get_led(toList num num 0 1) (add1 n) num) )] [(and (= (length x) 0) (>= n 3)) append '()])) (define (make_led_digit a b) (cond [(and (= a 0)(= b 1)) " _ "] [(and (= a 0)(= b 2)) "| | "] [(and (= a 0)(= b 3)) "|_| "] [(and (= a 1)(= b 1)) " "] [(and (= a 1)(= b 2)) "| "] [(and (= a 1)(= b 3)) "| "] [(and (= a 2)(= b 1)) " _ "] [(and (= a 2)(= b 2)) " _| "] [(and (= a 2)(= b 3)) "|_ "] [(and (= a 3)(= b 1)) "_ "] [(and (= a 3)(= b 2)) "_| "] [(and (= a 3)(= b 3)) "_| "] [(and (= a 4)(= b 1)) " "] [(and (= a 4)(= b 2)) "|_| "] [(and (= a 4)(= b 3)) " | "] [(and (= a 5)(= b 1)) " _ "] [(and (= a 5)(= b 2)) "|_ "] [(and (= a 5)(= b 3)) " _| "] [(and (= a 6)(= b 1)) " _ "] [(and (= a 6)(= b 2)) "|_ "] [(and (= a 6)(= b 3)) "|_| "] [(and (= a 7)(= b 1)) "_ "] [(and (= a 7)(= b 2)) " | "] [(and (= a 7)(= b 3)) " | "] [(and (= a 8)(= b 1)) " _ "] [(and (= a 8)(= b 2)) "|_| "] [(and (= a 8)(= b 3)) "|_| "] [(and (= a 9)(= b 1)) " _ "] [(and (= a 9)(= b 2)) "|_| "] [(and (= a 9)(= b 3)) " _| "])) |
Fibonacci.rkt |
---|
#lang racket (define (showFib num) (fib num 0 1)) (define (fib num a b) ( cond [(and (> a 0) (> num 1)) (append (cons (+ a b) '()) (fib (sub1 num) (+ a b) a))] [(= a 0) (append (append (cons a (cons b '())) (cons (+ a b) '())) (fib(sub1 num)(+ a b) b))] [(= 1 num) (append '())])) |
Hashtags.js |
---|
var system = require('system'); var webpage = require('webpage').create(); webpage.viewportSize = { width: 1280, height: 800 }; webpage.scrollPosition = { top: 0, left: 0 }; var userid = system.args[1]; var profileUrl = "http://www.twitter.com/" + userid; webpage.open(profileUrl, function(status) { if (status === 'fail') { console.error('webpage did not open successfully'); phantom.exit(1); } var i = 0, top, queryFn = function() { return document.body.scrollHeight; }; setInterval(function() { top = webpage.evaluate(queryFn); i++; webpage.scrollPosition = { top: top + 1, left: 0 }; if (i >= 5) { var twitter = webpage.evaluate(function () { var twitter = []; forEach = Array.prototype.forEach; var tweets = document.querySelectorAll('[data-query-source="hashtag_click"]'); forEach.call(tweets, function(el) { twitter.push(el.innerText); }); return twitter; }); twitter.forEach(function(t) { console.log(t); }); phantom.exit(); } }, 3000); }); |
hashtags.hs |
---|
import System.Process import Data.List hashTags :: String -> IO() hashTags(user) = do let x = readProcess "phantomjs" ["--ssl-protocol=any","Hashtags.js",user] [] y <- x mapM_ print $ sortBy sortGT $ count y count :: String -> [(String,Int)] count xs = filter ((>=5).snd) $ map(\ws -> (head ws, length ws)) $ group $ sort $ words xs sortGT :: (Ord a, Ord a1) => (a1, a) -> (a1, a) -> Ordering sortGT (a1, b1) (a2, b2) | b1 < b2 = GT | b1 > b2 = LT | b1 == b2 = compare a1 a2 |
Roman_Numerals.hs |
---|
showRomans :: Int -> IO() showRomans(num) = do putStr $ concat $ get_roman num 0 get_roman :: Int -> Int -> [[Char]] get_roman num ctr | num >= roman = make_roman(roman) ++ get_roman(num - roman) ctr | num < roman && num > 0 = get_roman(num) (ctr+1) | num <= 0 = ["\n"] where roman = roman_keys [] !! ctr make_roman :: Int -> [[Char]] make_roman(1) = ["I"]; make_roman(4) = ["IV"]; make_roman(5) = ["V"]; make_roman(9) = ["IX"]; make_roman(10) = ["X"]; make_roman(40) = ["XL"]; make_roman(50) = ["L"]; make_roman(90) = ["XC"]; make_roman(100) = ["C"]; make_roman(400) = ["CD"]; make_roman(500) = ["D"]; make_roman(900) = ["CM"]; make_roman(1000) = ["M"] roman_keys :: [Int] -> [Int] roman_keys keys = [1000,900,500,400,100,90,50,40,10,9,5,4,1] |
ZLED |
---|
REPORT zled. TYPES: BEGIN OF ty_lines, line(1) TYPE c, index(1) TYPE c, map TYPE string, END OF ty_lines. DATA: s_number TYPE string, counter TYPE i, num_counter TYPE i, line1 TYPE string, line2 TYPE string, line3 TYPE string. DATA: t_lines TYPE STANDARD TABLE OF ty_lines. FIELD-SYMBOLS: <fs_lines> LIKE LINE OF t_lines. SELECTION-SCREEN BEGIN OF BLOCK params. PARAMETERS: p_number TYPE i. SELECTION-SCREEN END OF BLOCK params. START-OF-SELECTION. PERFORM load_data. num_counter = 0. s_number = p_number. counter = strlen( s_number ) - 1. DO counter TIMES. READ TABLE t_lines ASSIGNING <fs_lines> WITH KEY line = 1 index = s_number+num_counter(1). CONCATENATE line1 <fs_lines>-map INTO line1 SEPARATED BY space. READ TABLE t_lines ASSIGNING <fs_lines> WITH KEY line = 2 index = s_number+num_counter(1). CONCATENATE line2 <fs_lines>-map INTO line2 SEPARATED BY space. READ TABLE t_lines ASSIGNING <fs_lines> WITH KEY line = 3 index = s_number+num_counter(1). CONCATENATE line3 <fs_lines>-map INTO line3 SEPARATED BY space. num_counter = num_counter + 1. ENDDO. REPLACE ALL OCCURRENCES OF '%' IN line1 WITH ` ` IN CHARACTER MODE. REPLACE ALL OCCURRENCES OF '%' IN line2 WITH ` ` IN CHARACTER MODE. REPLACE ALL OCCURRENCES OF '%' IN line3 WITH ` ` IN CHARACTER MODE. WRITE:/ line1. WRITE:/ line2. WRITE:/ line3. *&---------------------------------------------------------------------* *& Form LOAD_DATA *&---------------------------------------------------------------------* FORM load_data. PERFORM add_lines USING '1' '0' '%_%%'. PERFORM add_lines USING '2' '0' '| |%'. PERFORM add_lines USING '3' '0' '|_|%'. PERFORM add_lines USING '1' '1' '%%'. PERFORM add_lines USING '2' '1' '|%'. PERFORM add_lines USING '3' '1' '|%'. PERFORM add_lines USING '1' '2' '%_%%'. PERFORM add_lines USING '2' '2' ' _|%'. PERFORM add_lines USING '3' '2' '|_%%'. PERFORM add_lines USING '1' '3' '_%%'. PERFORM add_lines USING '2' '3' '_|%'. PERFORM add_lines USING '3' '3' '_|%'. PERFORM add_lines USING '1' '4' '%%%%'. PERFORM add_lines USING '2' '4' '|_|%'. PERFORM add_lines USING '3' '4' ' |%'. PERFORM add_lines USING '1' '5' '%_%%'. PERFORM add_lines USING '2' '5' '|_ %'. PERFORM add_lines USING '3' '5' ' _|%'. PERFORM add_lines USING '1' '6' '%_%%'. PERFORM add_lines USING '2' '6' '|_%%'. PERFORM add_lines USING '3' '6' '|_|%'. PERFORM add_lines USING '1' '7' '_%%'. PERFORM add_lines USING '2' '7' '%|%'. PERFORM add_lines USING '3' '7' '%|%'. PERFORM add_lines USING '1' '8' '%_%%'. PERFORM add_lines USING '2' '8' '|_|%'. PERFORM add_lines USING '3' '8' '|_|%'. PERFORM add_lines USING '1' '9' '%_%%'. PERFORM add_lines USING '2' '9' '|_|%'. PERFORM add_lines USING '3' '9' ' _|%'. ENDFORM. " LOAD_DATA *&---------------------------------------------------------------------* *& Form add_lines *&---------------------------------------------------------------------* FORM add_lines USING p_line p_index p_map. APPEND INITIAL LINE TO t_lines ASSIGNING <fs_lines>. <fs_lines>-line = p_line. <fs_lines>-index = p_index. <fs_lines>-map = p_map. ENDFORM. "add_lines |
LED.R |
---|
line<-c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3) index<-c(0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9) map<-c(" _ ","| | ","|_| "," ","| ","| "," _ "," _| ","|_ ", " _","_| ","_| "," ","|_| "," | "," _ ","|_ "," _| ", " _ ","|_ ","|_| "," _ "," | "," | "," _ ","|_| ","|_| ", " _ ","|_| "," _| ") Lines<-cbind(line,index,map) DF_Lines<-data.frame(Lines,stringsAsFactors=F) line1<-"" line2<-"" line3<-"" p_number<-readline("Enter a number?: ") l_number<-strsplit(p_number,"") for(i in 1:nchar(p_number)){ num_map<-DF_Lines[DF_Lines$index == as.numeric(l_number[[1]][i]),] line1<-paste(line1,num_map$map[1]) line2<-paste(line2,num_map$map[2]) line3<-paste(line3,num_map$map[3]) } lines = paste(line1,"\n",line2,"\n",line3,"\n") cat(lines) |
LED.hs |
---|
showLED :: Int -> IO() showLED(num) = do putStr(concat(addN(get_led(digits num) 1 num) (length(show num)) (length(show num)))) get_led :: [Int] -> Int -> Int -> [[Char]] get_led (x:xs) n num = make_led_digit(x,n) ++ get_led(xs) n num get_led [] n num = get_led2(digits num) (n+1) num get_led2 :: [Int] -> Int -> Int -> [[Char]] get_led2 (x:xs) n num = make_led_digit(x,n) ++ get_led2(xs) n num get_led2 [] n num = get_led3(digits num) (n+1) num get_led3 :: [Int] -> Int -> Int -> [[Char]] get_led3 (x:xs) n num = make_led_digit(x,n) ++ get_led3(xs) n num get_led3 [] n num = [] digits :: Int -> [Int] digits = map (read . (:[])) . show addN :: [String] -> Int -> Int -> [String] addN (x:xs) n ni | n > 0 = [x] ++ addN xs (n-1) ni | n == 0 = ["\n"] ++ [x] ++ addN xs (ni-1) ni addN [] _ _ = [] ++ ["\n"] make_led_digit :: (Int, Int) -> [[Char]] make_led_digit(0,1) = [" _ "]; make_led_digit(0,2) = ["| | "]; make_led_digit(0,3) = ["|_| "]; make_led_digit(1,1) = [" "]; make_led_digit(1,2) = ["| "]; make_led_digit(1,3) = ["| "]; make_led_digit(2,1) = [" _ "]; make_led_digit(2,2) = [" _| "]; make_led_digit(2,3) = ["|_ "]; make_led_digit(3,1) = ["_ "]; make_led_digit(3,2) = ["_| "]; make_led_digit(3,3) = ["_| "]; make_led_digit(4,1) = [" "]; make_led_digit(4,2) = ["|_| "]; make_led_digit(4,3) = [" | "]; make_led_digit(5,1) = [" _ "]; make_led_digit(5,2) = ["|_ "]; make_led_digit(5,3) = [" _| "]; make_led_digit(6,1) = [" _ "]; make_led_digit(6,2) = ["|_ "]; make_led_digit(6,3) = ["|_| "]; make_led_digit(7,1) = ["_ "]; make_led_digit(7,2) = [" | "]; make_led_digit(7,3) = [" | "]; make_led_digit(8,1) = [" _ "]; make_led_digit(8,2) = ["|_| "]; make_led_digit(8,3) = ["|_| "]; make_led_digit(9,1) = [" _ "]; make_led_digit(9,2) = ["|_| "]; make_led_digit(9,3) = [" _| "] |
LED_Fixed.hs |
---|
showLED :: Int -> IO() showLED(num) = do putStr(concat(addN(get_led(digits num) 1 num) (length(show num)) (length(show num)))) get_led :: [Int] -> Int -> Int -> [[Char]] get_led (x:xs) n num = make_led_digit(x,n) ++ get_led(xs) n num get_led [] n num | n < 3 = get_led(digits num) (n+1) num | n == 3 = [] digits :: Int -> [Int] digits = map (read . (:[])) . show addN :: [String] -> Int -> Int -> [String] addN (x:xs) n ni | n > 0 = [x] ++ addN xs (n-1) ni | n == 0 = ["\n"] ++ [x] ++ addN xs (ni-1) ni addN [] _ _ = [] ++ ["\n"] make_led_digit :: (Int, Int) -> [[Char]] make_led_digit(0,1) = [" _ "]; make_led_digit(0,2) = ["| | "]; make_led_digit(0,3) = ["|_| "]; make_led_digit(1,1) = [" "]; make_led_digit(1,2) = ["| "]; make_led_digit(1,3) = ["| "]; make_led_digit(2,1) = [" _ "]; make_led_digit(2,2) = [" _| "]; make_led_digit(2,3) = ["|_ "]; make_led_digit(3,1) = ["_ "]; make_led_digit(3,2) = ["_| "]; make_led_digit(3,3) = ["_| "]; make_led_digit(4,1) = [" "]; make_led_digit(4,2) = ["|_| "]; make_led_digit(4,3) = [" | "]; make_led_digit(5,1) = [" _ "]; make_led_digit(5,2) = ["|_ "]; make_led_digit(5,3) = [" _| "]; make_led_digit(6,1) = [" _ "]; make_led_digit(6,2) = ["|_ "]; make_led_digit(6,3) = ["|_| "]; make_led_digit(7,1) = ["_ "]; make_led_digit(7,2) = [" | "]; make_led_digit(7,3) = [" | "]; make_led_digit(8,1) = [" _ "]; make_led_digit(8,2) = ["|_| "]; make_led_digit(8,3) = ["|_| "]; make_led_digit(9,1) = [" _ "]; make_led_digit(9,2) = ["|_| "]; make_led_digit(9,3) = [" _| "] |