├── golang
├── app
│ ├── gosub
│ │ ├── .root
│ │ ├── go.mod
│ │ ├── lib
│ │ │ └── bar.go
│ │ ├── gosub
│ │ │ └── foo.go
│ │ └── hello_test1.go
│ ├── usepkg
│ │ ├── .root
│ │ ├── go.sum
│ │ ├── go.mod
│ │ └── use_package.go
│ ├── foreign
│ │ ├── .root
│ │ ├── my_test.go
│ │ ├── go.mod
│ │ └── foreign_test1.go
│ └── readfile
│ │ ├── README.md
│ │ ├── go.mod
│ │ ├── go.sum
│ │ └── read_file.go
├── legacy
│ ├── write_log2.go
│ ├── write_log.go
│ ├── test2.go
│ ├── test_array.go
│ ├── test1.go
│ ├── hello.go
│ ├── test_map.go
│ ├── func_in_func.go
│ ├── http_test.go
│ ├── http_test1.go
│ ├── variable_decl.go
│ ├── read_file.go
│ ├── producer.go
│ ├── slice_test3.go
│ ├── interface_test1.go
│ ├── bbuffer.go
│ ├── test_rune.go
│ ├── slice_test2.go
│ ├── gob_encode.go
│ ├── variable_slice.go
│ └── slice_test1.go
├── basic
│ ├── slice_test9.go
│ ├── array_test6.go
│ ├── slice_test7.go
│ ├── num_test1.go
│ ├── array_test3.go
│ ├── pointer_test1.go
│ ├── interface_test2.go
│ ├── map_test7.go
│ ├── map_test4.go
│ ├── slice_test6.go
│ ├── type_test1.go
│ ├── slice_test8.go
│ ├── array_test4.go
│ ├── array_test1.go
│ ├── type_test4.go
│ ├── array_test2.go
│ ├── generic_test1.go
│ ├── map_test2.go
│ ├── type_test3.go
│ ├── any_test1.go
│ ├── slice_test3.go
│ ├── map_test1.go
│ ├── struct_test4.go
│ ├── type_test5.go
│ ├── struct_test1.go
│ ├── interface_test9.go
│ ├── interface_test1.go
│ ├── struct_test3.go
│ ├── slice_test4.go
│ ├── interface_test7.go
│ ├── embed_test1.go
│ ├── func_test1.go
│ ├── slice_test5.go
│ ├── array_test5.go
│ ├── embed_test2.go
│ ├── slice_test2.go
│ ├── struct_test2.go
│ ├── map_test3.go
│ ├── interface_test4.go
│ ├── type_test2.go
│ ├── interface_test8.go
│ ├── interface_test3.go
│ ├── func_test2.go
│ ├── interface_test5.go
│ ├── interface_test6.go
│ ├── generic_test2.go
│ ├── slice_test1.go
│ ├── map_test5.go
│ └── type_check.go
├── binary_tree_walk.go
├── goroutine
│ ├── channel_test5.go
│ ├── goroutine_test4.go
│ ├── goroutine_test5.go
│ ├── goroutine_test7.go
│ ├── channel_test4.go
│ ├── goroutine_test6.go
│ ├── goroutine_test2.go
│ ├── goroutine_test3.go
│ ├── goroutine_test1.go
│ ├── channel_test2.go
│ ├── channel_test1.go
│ └── channel_test3.go
├── writer_test1.go
├── encoding_test1.go
├── rune_test1.go
├── fib_test2.go
├── lib
│ ├── sort_test1.go
│ ├── buffer_test1.go
│ ├── udp_timeout.go
│ └── udp_test1.go
├── log_test1.go
├── reader_test1.go
├── clock_bench.go
├── fib_test1.go
├── image_test1.go
├── json_test1.go
└── rot13_test1.go
├── ruby
├── hello.rb
├── files.rb
├── rubycsv.txt
├── slice.rb
├── require_lib.rb
├── test3.rb
├── capture.rb
├── guess.rb
├── blank.rb
├── execute.rb
├── grep.rb
├── units.rb
├── to_file.rb
├── require_main.rb
├── roman.rb
├── repeat.rb
├── acts_as_csv_class.rb
├── class1.rb
├── namespace.rb
├── visitor.rb
├── acts_as_csv.rb
├── acts_as_csv_module.rb
└── treenode.rb
├── README.md
├── haskell
├── hello.hs
├── apply_twice.hs
├── test_do.hs
├── double.hs
├── triplet.hs
├── double_with_type.hs
├── map.hs
├── mtable.hs
├── cylinder.hs
├── genlist.hs
├── factorial.hs
├── lesson
│ ├── dtype1.hs
│ └── baby.hs
├── lists.hs
├── fib.hs
├── initials.hs
├── all_even.hs
├── fact_with_guard.hs
├── my_range.hs
├── curry.hs
├── evenlist.hs
├── qsort.hs
├── lazy_list.hs
├── lazy_fib.hs
├── fib2.hs
├── fib3.hs
├── curry2.hs
├── qsort2.hs
├── reverse.hs
├── cards.hs
├── colormap.hs
├── cards-with-show.hs
└── bmi.hs
├── iolang
├── hello.io
├── phonebook.txt
├── average.io
├── fib.io
├── actor1.io
├── listmeta.io
├── vecsum.io
├── divzero.io
├── builder.io
├── guess.io
├── coroutine.io
├── phonebook.io
├── animals.io
├── matrix.io
├── xml1.io
└── matrix2.io
├── prolog
├── concat_step_1.pro
├── concat_step_2.pro
├── marry.pro
├── concat.pro
├── chmy.pro
├── nagitive.pro
├── friends.pro
├── family.pro
├── fib.pro
├── books.pro
├── concat_step_3.pro
├── fact2.pro
├── hanoi.pro
├── minimum.pro
├── first_math.pro
├── different.pro
├── factorial.pro
├── reverse.pro
├── lover.pro
├── person.pro
├── food.pro
├── queen3.pro
├── family2.pro
├── map.pro
├── qsort.pro
├── plib.pro
├── queen2.pro
└── queen1.pro
├── python
├── parser
│ └── grammar
│ │ ├── d4_40.txt
│ │ ├── d4_49.txt
│ │ ├── test_first.txt
│ │ ├── example_1.txt
│ │ ├── test_first2.txt
│ │ ├── test_action.txt
│ │ ├── expr_bnf.txt
│ │ ├── test_lex1.txt
│ │ ├── expr_action.txt
│ │ ├── conflict_1.txt
│ │ ├── test_epsilon.txt
│ │ ├── conflict_2.txt
│ │ └── test_bnf.txt
├── scope.py
├── panda3d
│ ├── tut1.py
│ ├── tut2.py
│ └── tut3.py
├── property1.py
├── queen4.py
├── cotest1.py
├── cotest2.py
├── coecho1.py
├── example_echo.py
└── cotest3.py
├── lua
├── hello.lua
├── test_mod2.lua
├── test_mod1.lua
└── index.lua
├── scheme
├── hanoi.scm
├── fib.scm
├── factorial.scm
├── hello.scm
├── lesson3.scm
├── clojure.scm
├── diamon.scm
├── lesson4.scm
├── queen2.scm
├── predefined.scm
└── lesson2.scm
├── pascal
└── PL0
│ ├── PL0.pas
│ └── demo.pl0
├── javascript
├── es6
│ ├── module_test.js
│ ├── module_import.mjs
│ ├── module_export.mjs
│ ├── class_member.js
│ └── async_test1.mjs
├── component
│ └── module.js
├── basic
│ ├── function_args.js
│ ├── function_static.js
│ ├── function_order.js
│ ├── function_args2.js
│ ├── variable_scope2.js
│ ├── compile_scope.js
│ ├── function_args3.js
│ ├── function_this.js
│ ├── function_check.js
│ ├── closure_failed.js
│ ├── function_this2.js
│ ├── function_self.js
│ ├── closure_test1.js
│ ├── function_internal.js
│ ├── function_bind.js
│ ├── variable_scope.js
│ ├── object_class.js
│ ├── object_getter.js
│ ├── object_proto2.js
│ ├── closure_counter.js
│ ├── function_length.js
│ ├── object_extend.js
│ ├── object_property.js
│ ├── object_boxing.js
│ ├── async_promise.js
│ ├── object_proto4.js
│ ├── object_proto1.js
│ ├── object_proto3.js
│ ├── function_flexsum.js
│ ├── closure_set.js
│ ├── object_inherit.js
│ ├── class_range2.js
│ ├── class_range3.js
│ ├── class_range4.js
│ ├── class_type.js
│ ├── class_define.js
│ └── class_range.js
├── dom
│ ├── dom-update.html
│ ├── dom-insert-exist.html
│ ├── dom-iterate.html
│ ├── dom-remove.html
│ ├── dom-insert-new.html
│ ├── dom-insert-pos.html
│ ├── dom-types.html
│ ├── dom-insert-style.html
│ ├── dom-query.html
│ └── dom-sort.html
├── tools
│ ├── monitor.html
│ ├── monitor2.html
│ └── monitor3.html
└── react
│ ├── start-page.html
│ ├── react-start.html
│ ├── tutor-css1.html
│ ├── tutor-form1.html
│ └── tutor-event1.html
├── elisp
├── simplemacro.el
├── loop.el
├── functions.el
├── dynscope.el
├── system1.el
├── minibuf1.el
├── output.el
├── symbol.el
├── sequence.el
├── dayname.el
├── hash.el
├── dowhile.el
├── hello.el
└── start_compile.el
├── scala
├── ring.scala
├── while1.scala
├── test1.scala
├── list_loop.scala
├── ruby_for_loop.scala
├── factorial.scala
├── for_loop.scala
├── chores.scala
├── nice.scala
├── constructor.scala
├── trait.scala
├── movies.scala
├── employee.scala
├── kids.scala
└── compass.scala
├── erlang
├── argument.erl
├── matching_function.erl
├── basic.erl
├── hello.erl
├── counter.erl
├── double.erl
├── price.erl
├── roulette.erl
├── message.erl
├── qsort.erl
├── yet_again.erl
├── coroner.erl
├── doctor.erl
├── temperature.erl
├── listdemo.erl
├── pingpong.erl
├── translate.erl
├── echo.erl
├── log_server.erl
└── translate_service.erl
├── prompt
└── test_rename_1.gpt
├── csharp
├── fileread.cs
├── object.cs
├── array1.cs
├── variables.cs
└── hello.cs
├── html
├── page_scale.html
└── basic
│ ├── layout_1.html
│ ├── css_selector2.html
│ ├── component1.html
│ ├── component2.html
│ ├── layout_position1.html
│ ├── css_selector1.html
│ ├── layout_position2.html
│ ├── layout_position3.html
│ ├── layout_position4.html
│ ├── layout_table1.html
│ ├── layout_table3.html
│ ├── component3.html
│ ├── layout_table2.html
│ ├── layout_table4.html
│ ├── layout_flex5.html
│ └── component4.html
├── data
└── win.ini
├── .gitignore
└── LICENSE
/golang/app/gosub/.root:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/golang/app/usepkg/.root:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/golang/app/foreign/.root:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/golang/app/usepkg/go.sum:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/golang/app/readfile/README.md:
--------------------------------------------------------------------------------
1 | hello
2 |
--------------------------------------------------------------------------------
/ruby/hello.rb:
--------------------------------------------------------------------------------
1 | puts "Hello, Ruby World !!"
2 |
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # language
2 |
3 | Language Collection
4 |
5 |
6 |
--------------------------------------------------------------------------------
/haskell/hello.hs:
--------------------------------------------------------------------------------
1 |
2 | main = putStrLn "Hello, World !!\n"
3 |
4 |
--------------------------------------------------------------------------------
/iolang/hello.io:
--------------------------------------------------------------------------------
1 | "Hello, IoLanguage World !!" println
2 |
3 |
4 |
--------------------------------------------------------------------------------
/prolog/concat_step_1.pro:
--------------------------------------------------------------------------------
1 | concatenate([], List, List).
2 |
3 |
4 |
--------------------------------------------------------------------------------
/golang/app/gosub/go.mod:
--------------------------------------------------------------------------------
1 | module skywind.com/golang/gosub
2 |
3 | go 1.22.1
4 |
--------------------------------------------------------------------------------
/python/parser/grammar/d4_40.txt:
--------------------------------------------------------------------------------
1 | S : C C ;
2 | C : 'c' C | 'd' ;
3 |
4 |
--------------------------------------------------------------------------------
/lua/hello.lua:
--------------------------------------------------------------------------------
1 | print("Hello, Lua World !!")
2 |
3 | print(package.path)
4 |
5 |
--------------------------------------------------------------------------------
/scheme/hanoi.scm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skywind3000/language/HEAD/scheme/hanoi.scm
--------------------------------------------------------------------------------
/pascal/PL0/PL0.pas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/skywind3000/language/HEAD/pascal/PL0/PL0.pas
--------------------------------------------------------------------------------
/javascript/es6/module_test.js:
--------------------------------------------------------------------------------
1 |
2 | import * as mod from './module_export.mjs'
3 |
4 |
5 |
--------------------------------------------------------------------------------
/golang/app/gosub/lib/bar.go:
--------------------------------------------------------------------------------
1 | package lib
2 |
3 | func Bar() {
4 | println("Bar from gosub")
5 | }
6 |
--------------------------------------------------------------------------------
/haskell/apply_twice.hs:
--------------------------------------------------------------------------------
1 | applyTwice :: (a -> a) -> a -> a
2 | applyTwice f x = f (f x)
3 |
4 |
5 |
--------------------------------------------------------------------------------
/golang/app/gosub/gosub/foo.go:
--------------------------------------------------------------------------------
1 | package gosub
2 |
3 | func Foo() {
4 | println("Foo from gosub")
5 | }
6 |
--------------------------------------------------------------------------------
/lua/test_mod2.lua:
--------------------------------------------------------------------------------
1 | local test_mod1 = require 'test_mod1'
2 |
3 | test_mod1.foo()
4 | test_mod1.bar()
5 |
--------------------------------------------------------------------------------
/iolang/phonebook.txt:
--------------------------------------------------------------------------------
1 | {
2 | "Bob Smith": "5195551212",
3 | "Mary Walsh": "4162223434"
4 | }
5 |
6 |
7 |
--------------------------------------------------------------------------------
/javascript/component/module.js:
--------------------------------------------------------------------------------
1 | export function demo() {
2 | console.log("demo");
3 | }
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/python/parser/grammar/d4_49.txt:
--------------------------------------------------------------------------------
1 | S : L '=' R | R ;
2 | L : '*' R | id ;
3 | R : L ;
4 | %token id
5 |
6 |
--------------------------------------------------------------------------------
/prolog/concat_step_2.pro:
--------------------------------------------------------------------------------
1 | concatenate([], List, List).
2 | concatenate([Head|[]], List, [Head|List]).
3 |
4 |
5 |
--------------------------------------------------------------------------------
/javascript/basic/function_args.js:
--------------------------------------------------------------------------------
1 |
2 | function foo(x, y) {
3 | console.log(x, y);
4 | }
5 |
6 | foo(10);
7 |
8 |
--------------------------------------------------------------------------------
/elisp/simplemacro.el:
--------------------------------------------------------------------------------
1 | (defmacro my-cadr (x)
2 | (list 'car (list 'cdr x)))
3 |
4 | (message "%s" (my-cadr '(1 2 3 4)))
5 |
--------------------------------------------------------------------------------
/haskell/test_do.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 |
3 | fuck x = 5 + x
4 |
5 | main = do
6 | fuck 3
7 |
8 |
--------------------------------------------------------------------------------
/golang/legacy/write_log2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "log"
4 |
5 | func foo() {
6 | log.Printf("foo()")
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/haskell/double.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 |
3 | double x = x + x
4 | main = putStrLn "Hello, World !!\n"
5 |
6 |
7 |
--------------------------------------------------------------------------------
/iolang/average.io:
--------------------------------------------------------------------------------
1 |
2 | List MyAverage := method((self sum) / (self size))
3 |
4 | (list(10, 20, 30) MyAverage) println
5 |
6 |
--------------------------------------------------------------------------------
/ruby/files.rb:
--------------------------------------------------------------------------------
1 | fp = File.new('../data/win.ini', 'r')
2 | while line = fp.gets
3 | puts line
4 | end
5 |
6 | fp.close
7 |
8 |
--------------------------------------------------------------------------------
/scala/ring.scala:
--------------------------------------------------------------------------------
1 | object TrueRing {
2 | def rule = println("To rule them all")
3 | }
4 |
5 | TrueRing.rule
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/scheme/fib.scm:
--------------------------------------------------------------------------------
1 | (define (fib x y)
2 | (display x)
3 | (newline)
4 | (or (> y 20) (fib y (+ x y))))
5 |
6 | (fib 1 1)
7 |
8 |
--------------------------------------------------------------------------------
/erlang/argument.erl:
--------------------------------------------------------------------------------
1 | -module(argument).
2 | -export([main/1]).
3 |
4 |
5 | main(X) ->
6 | io:format("~p~n", [X]),
7 | ok.
8 |
9 |
--------------------------------------------------------------------------------
/prolog/marry.pro:
--------------------------------------------------------------------------------
1 | bachelor(P) :- male(P), not(married(P)).
2 |
3 | male(henry).
4 | male(tom).
5 |
6 | married(tom).
7 |
8 |
9 |
--------------------------------------------------------------------------------
/golang/app/foreign/my_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "testing"
4 |
5 | func TestSuit1(t *testing.T) {
6 | t.Log("Hello, World!")
7 | }
8 |
--------------------------------------------------------------------------------
/golang/app/readfile/go.mod:
--------------------------------------------------------------------------------
1 | module readfile
2 |
3 | go 1.22.1
4 |
5 | require github.com/goinaction/code v0.0.0-20171020164608-49fc99e6affb
6 |
--------------------------------------------------------------------------------
/python/parser/grammar/test_first.txt:
--------------------------------------------------------------------------------
1 | S : T B ;
2 | B : A B | ε ;
3 | A : + S | T B | * ;
4 | T : '(' S ')' | a ;
5 |
6 | %token a
7 |
8 |
--------------------------------------------------------------------------------
/prolog/concat.pro:
--------------------------------------------------------------------------------
1 | concatenate([], List, List).
2 | concatenate([Head|Tail1], List, [Head|Tail2]) :-
3 | concatenate(Tail1, List, Tail2).
4 |
5 |
--------------------------------------------------------------------------------
/ruby/rubycsv.txt:
--------------------------------------------------------------------------------
1 | name, date, type, size
2 | blank.rb, 2016/12/11, rb, 1024
3 | class1.rb, 2016/12/9, rb, 512
4 | hello.rb, 2016/12/8, rb, 256
5 |
--------------------------------------------------------------------------------
/haskell/triplet.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | data Triplet a = Trio a a a deriving (Show)
3 |
4 | main = do
5 | print "Hello"
6 |
7 |
8 |
--------------------------------------------------------------------------------
/prolog/chmy.pro:
--------------------------------------------------------------------------------
1 | cat(lion).
2 | cat(tiger).
3 |
4 | dorothy(X, Y, Z) :- X = lion, Y = tiger, Z = bear.
5 | twin_cats(X, Y) :- cat(X), cat(Y).
6 |
7 |
--------------------------------------------------------------------------------
/python/parser/grammar/example_1.txt:
--------------------------------------------------------------------------------
1 | S : L '=' R ;
2 | S : R ;
3 | L : '*' R ;
4 | L : id ;
5 | R : L ;
6 |
7 | %token id
8 |
9 |
10 |
--------------------------------------------------------------------------------
/golang/legacy/write_log.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "log"
4 |
5 | func main() {
6 | log.Printf("Hello")
7 | log.Printf("World")
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/javascript/es6/module_import.mjs:
--------------------------------------------------------------------------------
1 |
2 | import * as mod from './module_export.mjs'
3 |
4 | console.log(mod.foo(10, 20));
5 | console.log(mod.bar(10, 20));
6 |
7 |
--------------------------------------------------------------------------------
/elisp/loop.el:
--------------------------------------------------------------------------------
1 | (setq x 10 total 0)
2 |
3 | (while (>= x 0)
4 | (message (format "%d %d" total x))
5 | (setq total (+ total x))
6 | (setq x (- x 1)))
7 |
8 |
--------------------------------------------------------------------------------
/ruby/slice.rb:
--------------------------------------------------------------------------------
1 |
2 | a = (0...16).to_a
3 |
4 | 0.step(15, 4).each {|i| puts a[i,4].to_s }
5 |
6 |
7 | a.each_slice(4) { |i| puts i.to_s }
8 |
9 |
10 |
--------------------------------------------------------------------------------
/haskell/double_with_type.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 |
3 | double :: Integer -> Integer
4 | double x = x + x
5 |
6 | main = putStrLn "main entry"
7 |
8 |
9 |
--------------------------------------------------------------------------------
/prolog/nagitive.pro:
--------------------------------------------------------------------------------
1 | p(X) :- q(X), not(r(X)).
2 | r(X) :- w(X), not(s(X)).
3 | q(a).
4 | q(b).
5 | q(c).
6 | s(a).
7 | s(c).
8 | w(a).
9 | w(b).
10 |
11 |
--------------------------------------------------------------------------------
/python/parser/grammar/test_first2.txt:
--------------------------------------------------------------------------------
1 | E : T E';
2 | E' : + T E' | %empty;
3 | T : F T' ;
4 | T' : * F T' | %empty;
5 | F : '(' E ')' | id;
6 |
7 | %token id
8 |
9 |
--------------------------------------------------------------------------------
/prolog/friends.pro:
--------------------------------------------------------------------------------
1 | likes(wallace, cheese).
2 | likes(grommit, cheese).
3 | likes(wendolene, sheep).
4 |
5 | friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
6 |
7 |
8 |
--------------------------------------------------------------------------------
/golang/app/foreign/go.mod:
--------------------------------------------------------------------------------
1 | module skywind.com/golang/foreign
2 |
3 | go 1.22.1
4 |
5 | replace skywind.com/golang/gosub => ../gosub
6 |
7 | require skywind.com/golang/gosub v0.0.1
8 |
--------------------------------------------------------------------------------
/haskell/map.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | squareAll list = map square list
3 | where square x = x * x
4 |
5 | main = do
6 | print (squareAll [1,2,3,4])
7 |
8 |
--------------------------------------------------------------------------------
/javascript/basic/function_static.js:
--------------------------------------------------------------------------------
1 |
2 | uniqueInteger.counter1 = 0;
3 |
4 | function uniqueInteger() {
5 | return uniqueInteger.counter1++;
6 | }
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/python/parser/grammar/test_action.txt:
--------------------------------------------------------------------------------
1 |
2 | E: E {act1a} '+' {action1b} {action1c} T {act1d} {act1e}
3 | | E '-' T {act2e}
4 | ;
5 |
6 | T: {actT} number {actEND} ;
7 |
8 |
9 |
--------------------------------------------------------------------------------
/elisp/functions.el:
--------------------------------------------------------------------------------
1 | (defun square (x) (* x x))
2 |
3 | (message "%s" (square 100))
4 |
5 | (let ((x 1)
6 | (y 2)
7 | (z 3))
8 | (message "%d" (+ x y z)))
9 |
10 |
--------------------------------------------------------------------------------
/erlang/matching_function.erl:
--------------------------------------------------------------------------------
1 |
2 | -module(matching_function).
3 | -export([number/1]).
4 |
5 | number(one) -> 1;
6 | number(two) -> 2;
7 | number(three) -> 3.
8 |
9 |
10 |
--------------------------------------------------------------------------------
/haskell/mtable.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | number = [1..9]
3 | mtable = [(x, y, x * y) | x <- number, y <-number, x < y]
4 |
5 | main = do
6 | print mtable
7 |
8 |
--------------------------------------------------------------------------------
/javascript/basic/function_order.js:
--------------------------------------------------------------------------------
1 |
2 | function foo() {
3 | bar();
4 | }
5 |
6 | var bar = function () {
7 | console.log("bar");
8 | }
9 |
10 | foo();
11 |
12 |
13 |
--------------------------------------------------------------------------------
/scala/while1.scala:
--------------------------------------------------------------------------------
1 | def whileLoop
2 | {
3 | var i = 1;
4 | while (i <= 3)
5 | {
6 | println(i);
7 | i+=1
8 | }
9 | }
10 |
11 | whileLoop
12 |
13 |
14 |
--------------------------------------------------------------------------------
/elisp/dynscope.el:
--------------------------------------------------------------------------------
1 | (defun foo ()
2 | (let ((x 6))
3 | (bar)
4 | x))
5 |
6 | (defun bar ()
7 | (let ((x 7))
8 | (setq x 7)))
9 |
10 | (message "x is %d" (foo))
11 |
12 |
--------------------------------------------------------------------------------
/prolog/family.pro:
--------------------------------------------------------------------------------
1 | father(zeb, john_boy_sr).
2 | father(john_boy_sr, john_boy_jr).
3 |
4 | ancestor(X, Y) :- father(X, Y).
5 | ancestor(X, Y) :- father(X, Z), ancestor(Z, Y).
6 |
7 |
8 |
--------------------------------------------------------------------------------
/prolog/fib.pro:
--------------------------------------------------------------------------------
1 |
2 | fib(0, 1).
3 | fib(1, 1).
4 | fib(2, 2).
5 |
6 | fib(N, V) :-
7 | N > 2, N1 is N - 1, N2 is N - 2,
8 | fib(N1, V1), fib(N2, V2), V is V1 + V2.
9 |
10 |
--------------------------------------------------------------------------------
/scala/test1.scala:
--------------------------------------------------------------------------------
1 |
2 | val a = 1
3 | val b = 2
4 |
5 | if (a > b)
6 | {
7 | println("true")
8 | }
9 | else
10 | {
11 | println("false")
12 | }
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/golang/basic/slice_test9.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | s1 := []int{1, 2, 3, 4, 5}
7 | s2 := []int{0, 0, 0}
8 | copy(s2, s1)
9 | fmt.Println(s2)
10 | }
11 |
--------------------------------------------------------------------------------
/haskell/cylinder.hs:
--------------------------------------------------------------------------------
1 | cylinder :: (RealFloat a) => a -> a -> a
2 | cylinder r h =
3 | let sideArea = 2 * pi * r * h
4 | topArea = pi * r ^ 2
5 | in sideArea + 2 * topArea
6 |
7 |
--------------------------------------------------------------------------------
/haskell/genlist.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | generate n = [(x, y) | x <- n, y <- n, x < y]
3 |
4 | main = do
5 | print (generate ["black", "yellow", "blue", "white", "red"])
6 |
7 |
--------------------------------------------------------------------------------
/python/parser/grammar/expr_bnf.txt:
--------------------------------------------------------------------------------
1 | E: E '+' T | E '-' T | T ;
2 | T: T '*' F | T '/' F | F ;
3 | F: number | "(" E ")" ;
4 |
5 | %token number
6 |
7 | @match number \d+
8 |
9 |
10 |
--------------------------------------------------------------------------------
/python/scope.py:
--------------------------------------------------------------------------------
1 |
2 | scope = 'global'
3 |
4 | def foo():
5 | print('scope', scope)
6 | # nonlocal scope = 'local'
7 | # print('scope', scope)
8 |
9 | foo()
10 |
11 |
--------------------------------------------------------------------------------
/erlang/basic.erl:
--------------------------------------------------------------------------------
1 |
2 |
3 | -module(basic).
4 | -export([mirror/1]).
5 |
6 | mirror(Anything) -> Anything.
7 |
8 | main(_) ->
9 | io:format("Fuck\n"),
10 | halt(0).
11 |
12 |
13 |
--------------------------------------------------------------------------------
/haskell/factorial.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | factorial :: Integer -> Integer
3 | factorial 0 = 1
4 | factorial x = x * factorial (x - 1)
5 |
6 | main = putStrLn "haha"
7 |
8 |
9 |
--------------------------------------------------------------------------------
/haskell/lesson/dtype1.hs:
--------------------------------------------------------------------------------
1 | removeNonUppercase :: [Char] -> [Char]
2 | removeNonUppercase st = [c|c<-st, c `elem` ['A'..'Z']]
3 |
4 | main =
5 | print(removeNonUppercase "Hello, World !!")
6 |
7 |
--------------------------------------------------------------------------------
/haskell/lists.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | size [] = 0
3 | size (h:t) = 1 + size t
4 |
5 | prod [] = 1
6 | prod (h:t) = h * prod t
7 |
8 | main = print "Hsdfsdf"
9 |
10 |
--------------------------------------------------------------------------------
/scheme/factorial.scm:
--------------------------------------------------------------------------------
1 | (define factorial
2 | (lambda (n)
3 | (if (= n 0) 1
4 | (* n (factorial (- n 1)))
5 | )
6 | )
7 | )
8 |
9 | (display (factorial 4))
10 | (newline)
11 |
12 |
--------------------------------------------------------------------------------
/scheme/hello.scm:
--------------------------------------------------------------------------------
1 | (begin (display "Hello World") (newline))
2 | (display "!!")
3 | (newline)
4 |
5 | (display "dsfsdf")
6 | (newline)
7 | (display (+ 10 20)) (newline)
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/haskell/fib.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | fib :: Integer -> Integer
3 | fib 0 = 1
4 | fib 1 = 1
5 | fib x = fib(x - 1) + fib(x - 2)
6 |
7 |
8 | main = print(fib(8))
9 |
10 |
--------------------------------------------------------------------------------
/erlang/hello.erl:
--------------------------------------------------------------------------------
1 | -import(basic).
2 |
3 | main(_) ->
4 | io:format("Hello, Erlang World !!\n"),
5 | X = basic:mirror(smiling_mug),
6 | io:format(X),
7 | io:format("\n"),
8 | halt(1).
9 |
10 |
--------------------------------------------------------------------------------
/golang/legacy/test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | )
7 |
8 | func main() {
9 | dir, _ := os.UserConfigDir();
10 | fmt.Println("hello, world", dir);
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/haskell/initials.hs:
--------------------------------------------------------------------------------
1 | initials :: String -> String -> String
2 | initials firstname lastname = [f] ++ ". " ++ [l] ++ "."
3 | where (f:_) = firstname
4 | (l:_) = lastname
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/javascript/es6/module_export.mjs:
--------------------------------------------------------------------------------
1 |
2 | function foo(x, y) {
3 | return x + y;
4 | }
5 |
6 | function bar(x, y) {
7 | return x * y;
8 | }
9 |
10 |
11 |
12 | export { foo, bar };
13 |
14 |
--------------------------------------------------------------------------------
/golang/basic/array_test6.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | a1 := [3]int{0, 0, 0}
9 | a2 := a1
10 | a2[0] = 1
11 | fmt.Println(a1)
12 | fmt.Println(a2)
13 | }
14 |
--------------------------------------------------------------------------------
/golang/binary_tree_walk.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 |
6 | "golang.org/x/tour/tree"
7 | )
8 |
9 | func main() {
10 | fmt.Println("Hello, World!")
11 | fmt.Println(tree.New(1))
12 | }
13 |
--------------------------------------------------------------------------------
/javascript/es6/class_member.js:
--------------------------------------------------------------------------------
1 |
2 | class Buffer {
3 | constructor() {
4 | this.size = 0;
5 | this.capacity = 4096;
6 | this.buffer = new Uint8Array(this.capacity);
7 | }
8 | }
9 |
10 |
11 |
--------------------------------------------------------------------------------
/scala/list_loop.scala:
--------------------------------------------------------------------------------
1 |
2 |
3 | val x = List(0,1,2,3,4,5)
4 |
5 | for (i <- 0 until 10) {
6 | println(i)
7 | }
8 |
9 | for (i <- 0 until x.length) {
10 | println(x(i))
11 | }
12 |
13 |
14 |
--------------------------------------------------------------------------------
/elisp/system1.el:
--------------------------------------------------------------------------------
1 | (message "system-type: %s" system-type)
2 | (message "system-name: %s" (system-name))
3 | (message "buffer-file-name: %s" buffer-file-name)
4 | (message "tty-erase-char: %s" tty-erase-char)
5 |
6 |
7 |
--------------------------------------------------------------------------------
/golang/basic/slice_test7.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | slice := [][]int{{10}, {100, 200}}
9 | slice[0] = append(slice[0], 20)
10 | fmt.Printf("%v", slice)
11 | }
12 |
--------------------------------------------------------------------------------
/golang/goroutine/channel_test5.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | ch1 := make(chan int, 100)
7 | ch1 <- 10
8 | fmt.Printf("len(ch1)=%d, cap(ch1)=%d\n", len(ch1), cap(ch1))
9 | }
10 |
--------------------------------------------------------------------------------
/prompt/test_rename_1.gpt:
--------------------------------------------------------------------------------
1 | #! python3 ~/.vim/vim/lib/gptcoder.py -p
2 |
3 | you are a coder
4 | convert the following code for me
5 |
6 | <<<
7 | hello
8 | >>>
9 | world
10 | <<<
11 | how are you
12 |
13 |
--------------------------------------------------------------------------------
/javascript/basic/function_args2.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | function foo(x, y) {
4 | console.log(arguments.length);
5 | }
6 |
7 | foo(1);
8 | foo(1, 2);
9 | foo(1, 2, 3);
10 | foo(1, 2, 3, 4);
11 |
12 |
13 |
--------------------------------------------------------------------------------
/scala/ruby_for_loop.scala:
--------------------------------------------------------------------------------
1 |
2 | def rubyStyleForLoop {
3 | println("for loop using ruby-style iteration")
4 | args.foreach { arg =>
5 | println(arg)
6 | }
7 | }
8 |
9 | rubyStyleForLoop
10 |
11 |
12 |
--------------------------------------------------------------------------------
/csharp/fileread.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | class Hello {
5 | static void Main(string[] args) {
6 | string text = File.ReadAllText("fileread.cs");
7 | Console.Write(text);
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/elisp/minibuf1.el:
--------------------------------------------------------------------------------
1 | (play-sound-file "d:/acm/github/vim/tools/samples/sample-7.wav")
2 | (setq x (read-passwd "input your naked passwd: "))
3 | (message "your input is %s" x)
4 | (message "buffers: %s" (buffer-list))
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/iolang/fib.io:
--------------------------------------------------------------------------------
1 |
2 | fib := method(x,
3 | if (x == 0, 1,
4 | if (x == 1, 1,
5 | (fib(x - 2)) + (fib(x - 1))
6 | )
7 | )
8 | )
9 |
10 |
11 | for (i, 0, 20, writeln("[", i, "] ", fib(i)))
12 |
13 |
--------------------------------------------------------------------------------
/javascript/basic/variable_scope2.js:
--------------------------------------------------------------------------------
1 |
2 | let scope = 'global';
3 |
4 | function foo() {
5 | console.log('scope', scope);
6 | let scope = 'local';
7 | console.log('scope', scope);
8 | }
9 |
10 | foo();
11 |
12 |
13 |
--------------------------------------------------------------------------------
/lua/test_mod1.lua:
--------------------------------------------------------------------------------
1 | local print = print
2 |
3 | module('test_mod1')
4 |
5 | function foo()
6 | print('This is foo()')
7 | end
8 |
9 | function bar()
10 | print('This is bar()')
11 | end
12 |
13 | print('fuck')
14 |
--------------------------------------------------------------------------------
/prolog/books.pro:
--------------------------------------------------------------------------------
1 | likes(book1, author1).
2 | likes(book3, author1).
3 | likes(book5, author2).
4 | likes(book7, author3).
5 | likes(book9, author1).
6 | likes(book11, author2).
7 | likes(book13, author3).
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/ruby/require_lib.rb:
--------------------------------------------------------------------------------
1 | module RequireLib
2 | def self.test2
3 | puts "this is test2 from require_lib.rb"
4 | end
5 | end
6 |
7 |
8 | def RequireLib.test
9 | puts "this is test from require_lib.rb"
10 | end
11 |
12 |
--------------------------------------------------------------------------------
/golang/legacy/test_array.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | b := [10]byte {0, 0, 0, 0}
5 | d := b[:2]
6 | b[0] = 10
7 | d[0] = 20
8 | println("b[0] is", b[0])
9 | println("d[0] is", d[0])
10 | }
11 |
12 |
13 |
--------------------------------------------------------------------------------
/haskell/all_even.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | allEven :: [Integer] -> [Integer]
3 | allEven [] = []
4 | allEven (h:t) = if even h then h:allEven(t) else allEven(t)
5 |
6 | main = print(allEven [1,2,3,4,5,6,7])
7 |
8 |
9 |
--------------------------------------------------------------------------------
/haskell/fact_with_guard.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | factorial :: Integer -> Integer
3 | factorial x
4 | | x > 1 = factorial(x - 1) * x
5 | | otherwise = 1
6 |
7 | main = putStrLn "Fuck you"
8 |
9 |
10 |
--------------------------------------------------------------------------------
/javascript/basic/compile_scope.js:
--------------------------------------------------------------------------------
1 |
2 | var scope = 'global';
3 |
4 | function constructFunction() {
5 | var scope = 'local';
6 | return new Function('return scope;');
7 | }
8 |
9 | constructFunction()();
10 |
11 |
12 |
--------------------------------------------------------------------------------
/python/panda3d/tut1.py:
--------------------------------------------------------------------------------
1 | from direct.showbase.ShowBase import ShowBase
2 |
3 | class MyApp (ShowBase):
4 |
5 | def __init__ (self):
6 | ShowBase.__init__(self)
7 |
8 | app = MyApp()
9 | app.run()
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ruby/test3.rb:
--------------------------------------------------------------------------------
1 |
2 | def foo(x)
3 | return proc {
4 | puts x
5 | x += 1
6 | }
7 | end
8 |
9 |
10 | f1 = foo(100)
11 | f2 = foo(200)
12 |
13 | f1.call()
14 | f1.call()
15 | f1.call()
16 | f2.call()
17 |
18 |
--------------------------------------------------------------------------------
/golang/basic/num_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | var x byte = 253
7 | var y byte
8 | var z byte
9 | var n byte = 10
10 | y = x + n
11 | z = y - n
12 | fmt.Println(y)
13 | fmt.Println(z)
14 | }
15 |
--------------------------------------------------------------------------------
/golang/writer_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | "os"
7 | )
8 |
9 | func main() {
10 | var b bytes.Buffer
11 | b.Write([]byte("Hello "))
12 | fmt.Fprintf(&b, "world!")
13 | b.WriteTo(os.Stdout)
14 | }
15 |
--------------------------------------------------------------------------------
/scala/factorial.scala:
--------------------------------------------------------------------------------
1 |
2 | def factorial(n: Int): Int = n match {
3 | case 0 => 1
4 | case x if x > 0 => factorial(n - 1) * n
5 | }
6 |
7 |
8 | println(factorial(3))
9 | println(factorial(0))
10 | println(factorial(5))
11 |
12 |
--------------------------------------------------------------------------------
/scheme/lesson3.scm:
--------------------------------------------------------------------------------
1 | (define a 10)
2 | (define b 20)
3 | (if (< a b)
4 | (begin
5 | (display "a is ")
6 | (display a)
7 | (display " b is ")
8 | (display b)
9 | (display " a < b")
10 | (newline)
11 | )
12 | )
13 |
14 |
--------------------------------------------------------------------------------
/elisp/output.el:
--------------------------------------------------------------------------------
1 | (defun my-append-string-to-file (s filename)
2 | (with-temp-buffer
3 | (erase-buffer)
4 | (insert s)
5 | (write-region (point-min) (point-max) filename nil)))
6 |
7 | (my-append-string-to-file "fuck you\n" "output.txt")
8 |
--------------------------------------------------------------------------------
/golang/basic/array_test3.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | var array1 [4][2]int
9 | array2 := [4][2]int{{10, 11}, {20, 21}, {30, 31}, {40, 41}}
10 | array1 = array2
11 | fmt.Println(array1)
12 | }
13 |
--------------------------------------------------------------------------------
/javascript/basic/function_args3.js:
--------------------------------------------------------------------------------
1 |
2 | function foo(x, y) {
3 | console.log(x, y);
4 | arguments[1] = 99;
5 | console.log(x, y);
6 | }
7 |
8 | var x = 10, y = 20;
9 |
10 | foo(x, y);
11 |
12 | console.log(x, y);
13 |
14 |
15 |
--------------------------------------------------------------------------------
/prolog/concat_step_3.pro:
--------------------------------------------------------------------------------
1 | concatenate([], List, List).
2 | concatenate([Head|[]], List, [Head|List]).
3 | concatenate([Head1|[Head2|[]]], List, [Head1, Head2|List]).
4 | concatenate([Head1|[Head2|[Head3|[]]]], List, [Head1, Head2, Head3|List]).
5 |
6 |
--------------------------------------------------------------------------------
/ruby/capture.rb:
--------------------------------------------------------------------------------
1 | require "Open3"
2 |
3 | if Gem.win_platform?
4 | text, code = Open3.capture2e 'dir', "\\"
5 | else
6 | text, code = Open3.capture2e 'ls', '-la', '/'
7 | end
8 |
9 |
10 | puts text
11 | puts code
12 |
13 |
14 |
--------------------------------------------------------------------------------
/golang/app/readfile/go.sum:
--------------------------------------------------------------------------------
1 | github.com/goinaction/code v0.0.0-20171020164608-49fc99e6affb h1:xpDeYJF7P9jgczf4KjRQOoqPrrKs56vqMBiWOXnSoQM=
2 | github.com/goinaction/code v0.0.0-20171020164608-49fc99e6affb/go.mod h1:3NRM3Fi26eZwRU/33Y0fH7YaVlo6EDQUAE2CBQ/snQ0=
3 |
--------------------------------------------------------------------------------
/haskell/my_range.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | myRange start step = start:(myRange (start + step) step)
3 |
4 | main = do
5 | print (take 10 (myRange 10 1))
6 | print (take 5 (myRange 0 5))
7 | -- print (myRange 0 5)
8 |
9 |
--------------------------------------------------------------------------------
/golang/legacy/test1.go:
--------------------------------------------------------------------------------
1 | package main
2 | import "fmt"
3 |
4 | func main() {
5 | var a int = 1
6 | fmt.Println("Fuck you !!", a)
7 | println("hahaha")
8 | for x := 0
9 | x < 10
10 | x++ {
11 | println("x=", x)
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/prolog/fact2.pro:
--------------------------------------------------------------------------------
1 | :- use_module(library(clpfd)).
2 |
3 | factorial(0,1).
4 | factorial(N,F) :-
5 | N in 1..2147483647, % between 1 and max int
6 | N1 #= N - 1,
7 | factorial(N1,F1),
8 | N #>= 1,
9 | F #= N * F1.
10 |
11 |
12 |
--------------------------------------------------------------------------------
/golang/basic/pointer_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | i, j := 42, 2701
7 |
8 | p := &i
9 | fmt.Println(*p) // 42
10 | *p = 21
11 | fmt.Println(i) // 21
12 | p = &j
13 | *p = *p / 37
14 | fmt.Println(j)
15 | }
16 |
--------------------------------------------------------------------------------
/golang/legacy/hello.go:
--------------------------------------------------------------------------------
1 | package main
2 | import "fmt"
3 |
4 | func main() {
5 | var a int = 1
6 | fmt.Println("How are you !!", a)
7 | println("hahaha2")
8 | for x := 0
9 | x < 10
10 | x++ {
11 | println("x=", x)
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/golang/legacy/test_map.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 |
4 | func main() {
5 | m := map[string]string {}
6 | t := m["test"]
7 | println("size", len(t))
8 | if t == "" {
9 | println("empty")
10 | } else {
11 | println("not empty")
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/iolang/actor1.io:
--------------------------------------------------------------------------------
1 | slower := Object clone
2 | faster := Object clone
3 |
4 | slower start := method(wait(2); writeln("slowly"))
5 | faster start := method(wait(1); writeln("quickly"))
6 |
7 | slower @@start; faster @@start
8 | wait(3)
9 |
10 |
11 |
--------------------------------------------------------------------------------
/javascript/basic/function_this.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | function test_this() {
4 | console.log('this', this);
5 | }
6 |
7 | test_this();
8 |
9 | var o = {x:1, y:2};
10 |
11 | o.m = test_this;
12 | o.x = 100;
13 |
14 | o.m();
15 |
16 |
17 |
--------------------------------------------------------------------------------
/ruby/guess.rb:
--------------------------------------------------------------------------------
1 | x = rand(10)
2 |
3 | while true
4 | puts "enter your guess"
5 | y = gets
6 | if y.to_i == x
7 | puts "yes you are right, secret number is #{x}"
8 | break
9 | else
10 | puts "you are wrong"
11 | end
12 | end
13 |
14 |
15 |
--------------------------------------------------------------------------------
/golang/app/foreign/foreign_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 |
6 | "skywind.com/golang/gosub/gosub"
7 | "skywind.com/golang/gosub/lib"
8 | )
9 |
10 | func main() {
11 | fmt.Println("Hello, World!")
12 | gosub.Foo()
13 | lib.Bar()
14 | }
15 |
--------------------------------------------------------------------------------
/golang/app/gosub/hello_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 |
6 | "skywind.com/golang/gosub/gosub"
7 | "skywind.com/golang/gosub/lib"
8 | )
9 |
10 | func main() {
11 | fmt.Println("Hello, Golang !!")
12 | gosub.Foo()
13 | lib.Bar()
14 | }
15 |
--------------------------------------------------------------------------------
/golang/basic/interface_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type duration int
8 |
9 | func (d duration) pretty() string {
10 | return fmt.Sprintf("Duration: %d", d)
11 | }
12 |
13 | func main() {
14 | duration(42).pretty()
15 | }
16 |
--------------------------------------------------------------------------------
/golang/basic/map_test7.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | table := make(map[string]string)
7 | table["1"] = "A"
8 | table["2"] = "B"
9 | delete(table, "3")
10 | fmt.Printf("%t\n", table)
11 | fmt.Printf("%v\n", table)
12 | }
13 |
--------------------------------------------------------------------------------
/javascript/es6/async_test1.mjs:
--------------------------------------------------------------------------------
1 |
2 | async function foo(x) {
3 | return 100 * x;
4 | }
5 |
6 | let y = await foo(99);
7 |
8 | console.log(y);
9 |
10 | let m = await import('./module_export.mjs');
11 |
12 | console.log(m.bar(33, 2));
13 |
14 |
15 |
--------------------------------------------------------------------------------
/scala/for_loop.scala:
--------------------------------------------------------------------------------
1 |
2 | def forLoop {
3 | println("For loop using java-style iteration")
4 | println("argument size = " + args.length.toString)
5 | for (i <- 0 until args.length) {
6 | println(args(8))
7 | }
8 | }
9 |
10 | forLoop
11 |
12 |
--------------------------------------------------------------------------------
/erlang/counter.erl:
--------------------------------------------------------------------------------
1 | -module(counter).
2 |
3 | -export([main/1]).
4 |
5 |
6 | count(N, N) ->
7 | true;
8 | count(I, N) ->
9 | io:format("~w~n", [I]),
10 | count(I + 1, N).
11 |
12 |
13 | main(_) ->
14 | count(0, 10),
15 | halt(0).
16 |
17 |
18 |
--------------------------------------------------------------------------------
/erlang/double.erl:
--------------------------------------------------------------------------------
1 | % just another test
2 | -module(just_another).
3 | -export([main/1]).
4 |
5 |
6 | double_all([]) -> [];
7 | double_all([H|L]) -> [H + H|double_all(L)].
8 |
9 | main(_) ->
10 | io:format("~p~n", [double_all([1,2,3])]),
11 | ok.
12 |
13 |
--------------------------------------------------------------------------------
/golang/app/usepkg/go.mod:
--------------------------------------------------------------------------------
1 | module usepkg
2 |
3 | go 1.22.1
4 |
5 | // require github.com/skywind3000/gosub v0.0.0-20240328151048-0d5975ecb0e6
6 | replace github.com/skywind3000/gosub => /mnt/e/Lab/gosub
7 |
8 | require github.com/skywind3000/gosub v0.0.0-00010101000000-000000000000
9 |
--------------------------------------------------------------------------------
/golang/basic/map_test4.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func foo(m map[string]string) {
8 | m["foo"] = "bar"
9 | }
10 |
11 | func main() {
12 | m := make(map[string]string)
13 | m["hello"] = "world"
14 | foo(m)
15 | fmt.Println(m)
16 | }
17 |
--------------------------------------------------------------------------------
/golang/basic/slice_test6.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | slice := []int{10, 20, 30, 40, 50}
7 | for index, value := range slice {
8 | fmt.Printf("Value: %d, Value-Addr: %X, ElemAddr: %X\n", value, &value, &slice[index])
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/iolang/listmeta.io:
--------------------------------------------------------------------------------
1 |
2 |
3 | curlyBrackets := method(
4 | r := List clone
5 | call message arguments foreach(arg,
6 | x := r doMessage(arg)
7 | r append(x)
8 | )
9 | r
10 | )
11 |
12 |
13 | x := { 1, 2, 3, 4 }
14 | x println
15 |
16 |
--------------------------------------------------------------------------------
/javascript/basic/function_check.js:
--------------------------------------------------------------------------------
1 |
2 | function isFunction(x) {
3 | return Object.prototype.toString.call(x) === '[object Function]';
4 | }
5 |
6 | function f() {}
7 |
8 | console.log(isFunction(f));
9 | console.log(Object.prototype.toString.call(f));
10 |
11 |
--------------------------------------------------------------------------------
/haskell/curry.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | fuck :: (Integer, String) -> String
3 | fuck (x, y) = (show x) ++ y
4 |
5 | main = do
6 | let suck x = fuck (10, x)
7 | putStrLn (fuck (1, "hahahah"))
8 | putStrLn (suck "sdfsdf")
9 |
10 |
11 |
--------------------------------------------------------------------------------
/javascript/basic/closure_failed.js:
--------------------------------------------------------------------------------
1 |
2 | function constfuncs() {
3 | var funcs = [];
4 | for (var i = 0; i < 10; i++) {
5 | funcs[i] = function() {return i;}
6 | }
7 | return funcs;
8 | }
9 |
10 | var funcs = constfuncs();
11 | console.log(funcs[5]());
12 |
13 |
--------------------------------------------------------------------------------
/javascript/basic/function_this2.js:
--------------------------------------------------------------------------------
1 |
2 | var calculator = {
3 | operand1: 1,
4 | operand2: 2,
5 |
6 | add: function() {
7 | this.result = this.operand1 + this.operand2;
8 | }
9 | };
10 |
11 | calculator.add();
12 |
13 | console.log(calculator.result);
14 |
15 |
--------------------------------------------------------------------------------
/ruby/blank.rb:
--------------------------------------------------------------------------------
1 | class NilClass
2 | def blank?
3 | true
4 | end
5 | end
6 |
7 | class String
8 | def blank?
9 | self.size == 0
10 | end
11 | end
12 |
13 | ["", "person", nil].each do |element|
14 | puts element unless element.blank?
15 | end
16 |
17 |
18 |
--------------------------------------------------------------------------------
/scala/chores.scala:
--------------------------------------------------------------------------------
1 | def doChore(chore: String):String = chore match {
2 | case "clean dishes" => "scrub, dry"
3 | case "cook dinner" => "chop, sizzle"
4 | case _ => "whine, complain"
5 | }
6 |
7 | println(doChore("clean dishes"))
8 | println(doChore("mow lawn"))
9 |
10 |
--------------------------------------------------------------------------------
/golang/encoding_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/binary"
5 | "fmt"
6 | )
7 |
8 | func main() {
9 | b := make([]byte, 4)
10 | binary.LittleEndian.PutUint16(b[0:], 0x03e8)
11 | binary.LittleEndian.PutUint16(b[2:], 0x07d0)
12 | fmt.Printf("%x\n", b)
13 | }
14 |
--------------------------------------------------------------------------------
/haskell/evenlist.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | even1 [] = []
3 | even1 (h:t) = if (even h) then (h:even1(t)) else even1(t)
4 |
5 | even2 x = [n | n <- x, even n]
6 |
7 | main = do
8 | print (even1 [1,2,3,4,5])
9 | print (even2 [1,2,3,4,5])
10 |
11 |
--------------------------------------------------------------------------------
/prolog/hanoi.pro:
--------------------------------------------------------------------------------
1 | move(1,X,Y,_) :-
2 | write('Move top disk from '),
3 | write(X),
4 | write(' to '),
5 | write(Y),
6 | nl.
7 |
8 | move(N,X,Y,Z) :-
9 | N > 1,
10 | M is N - 1,
11 | move(M, X, Z, Y),
12 | move(1, X, Y, _),
13 | move(M, Z, Y, X).
14 |
15 |
16 |
--------------------------------------------------------------------------------
/haskell/lesson/baby.hs:
--------------------------------------------------------------------------------
1 | doubleMe x = x + x
2 | doubleUs x y = x * 2 + y * 2
3 |
4 | doubleSmallNumber x =
5 | if x > 100
6 | then x
7 | else x * 2
8 |
9 | doubleSmallNumber' x = (if x > 100 then x else x * 2) + 1
10 |
11 | main =
12 | print([1,2,3])
13 |
14 |
--------------------------------------------------------------------------------
/python/parser/grammar/test_lex1.txt:
--------------------------------------------------------------------------------
1 | E: E '+' T | E '-' T | T ;
2 | T: T '*' F | T '/' F | F ;
3 | F: number | "(" E ")" ;
4 |
5 | %token number
6 |
7 | # 'abc': F;
8 |
9 | @ignore [\r\n\t ]*
10 | @import NUMBER as number
11 | @match { action1 } \w+
12 |
13 | %token hahs
14 |
--------------------------------------------------------------------------------
/golang/basic/type_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type Duration int64
8 |
9 | func main() {
10 | var dur Duration
11 | dur = 1000
12 | fmt.Println(dur)
13 | dur = 2000
14 | fmt.Println(dur)
15 | dur = Duration(int64(1234))
16 | fmt.Println(dur)
17 | }
18 |
--------------------------------------------------------------------------------
/golang/legacy/func_in_func.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | func main() {
4 | var x = 1
5 | foo := func () {
6 | println("foo is", x)
7 | x++
8 | }
9 | bar := func () {
10 | println("bar is", x)
11 | x++
12 | }
13 | foo()
14 | bar()
15 | foo()
16 | bar()
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/javascript/basic/function_self.js:
--------------------------------------------------------------------------------
1 |
2 | var o = {
3 | m: function () {
4 | var self = this;
5 | console.log(this === o);
6 | f();
7 | function f() {
8 | console.log(this === o);
9 | console.log(self === o);
10 | }
11 | }
12 | };
13 |
14 | o.m();
15 |
16 |
17 |
--------------------------------------------------------------------------------
/erlang/price.erl:
--------------------------------------------------------------------------------
1 | -module(price).
2 | -export([main/1]).
3 |
4 |
5 | main(_) ->
6 | Cart = [{pencil, 4, 0.2}, {pen, 1, 1.20}, {paper, 2, 0.2}],
7 | io:format("~p~n", [Cart]),
8 | Price = [{Name, N * P} || {Name, N, P} <- Cart],
9 | io:format("~p~n", [Price]),
10 | ok.
11 |
12 |
13 |
--------------------------------------------------------------------------------
/javascript/basic/closure_test1.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | var uniqueInteger = (function () {
4 | var counter = 0;
5 | return function () {
6 | return counter++;
7 | }
8 | })();
9 |
10 | console.log(uniqueInteger());
11 | console.log(uniqueInteger());
12 | console.log(uniqueInteger());
13 |
14 |
--------------------------------------------------------------------------------
/erlang/roulette.erl:
--------------------------------------------------------------------------------
1 | -module(roulette).
2 | -export([loop/0]).
3 |
4 | % send a number, 1- 6
5 | loop() ->
6 | receive
7 | 3 ->
8 | io:format("bang.~n"),
9 | exit({roulette, die, at, erlang:time()});
10 | _ ->
11 | io:format("click~n"),
12 | loop()
13 | end.
14 |
15 |
16 |
--------------------------------------------------------------------------------
/prolog/minimum.pro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | minimum([], 0).
5 | minimum([A], A).
6 |
7 | min(A, B, C) :- A < B, C is A.
8 | min(A, B, C) :- A = B, C is A.
9 | min(A, B, C) :- A > B, C is B.
10 |
11 | minimum([HA|LA], B) :-
12 | \+(LA=[]),
13 | minimum(LA, B1),
14 | min(HA, B1, B).
15 |
16 |
17 |
--------------------------------------------------------------------------------
/golang/rune_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | s := []rune("你好,世界!")
9 | c := s[1]
10 | fmt.Println(len(s))
11 | fmt.Printf("%T\n", c)
12 | fmt.Println(string(s))
13 | n := []int{1, 2, 3, 4}
14 | n = n[2:]
15 | n = n[4:]
16 | fmt.Println(n)
17 | }
18 |
--------------------------------------------------------------------------------
/javascript/basic/function_internal.js:
--------------------------------------------------------------------------------
1 | function foo(index) {
2 | for (var i = 0; i < 10; i++) {
3 | try {
4 | function bar() {
5 | console.log('foo', index, 'bar', i);
6 | }
7 | bar();
8 | }
9 | catch {
10 | }
11 | }
12 | }
13 |
14 | foo(10)
15 | foo(20)
16 |
17 |
18 |
--------------------------------------------------------------------------------
/haskell/qsort.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | qsort [] = []
3 | qsort (s:t) =
4 | qsort([x | x <- t, x < s]) ++
5 | [s] ++
6 | [x | x <- t, x == s] ++
7 | qsort([x | x <- t, x > s])
8 |
9 | main = do
10 | print (qsort [3, 1, 4, 1, 5, 9, 2, 6])
11 |
12 |
13 |
--------------------------------------------------------------------------------
/iolang/vecsum.io:
--------------------------------------------------------------------------------
1 |
2 | Number sum := method(self)
3 | List + := method(y, (self sum) + (y sum))
4 |
5 | x := list(list(1,2,3), list(4,5,6), list(7,8,9))
6 |
7 | sum := method(x,
8 | m := 0
9 | for (i, 0, (x size) - 1, m = m + ((x at(i)) sum))
10 | m)
11 |
12 | sum(x) println
13 |
14 |
15 |
--------------------------------------------------------------------------------
/javascript/basic/function_bind.js:
--------------------------------------------------------------------------------
1 |
2 | var sum = function(x, y) { return x + y; };
3 |
4 | var succ = sum.bind(null, 1);
5 |
6 | console.log(succ(2));
7 |
8 | function f(y, z) { return this.x + y + z; };
9 |
10 | var g = f.bind({x:1}, 2);
11 |
12 | console.log(g(3));
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/javascript/basic/variable_scope.js:
--------------------------------------------------------------------------------
1 | function foo() {
2 | {
3 | var x = 10;
4 | }
5 | try { console.log(x); } catch { console.log('failed to access x'); }
6 | {
7 | let y = 20;
8 | }
9 | try { console.log(y); } catch { console.log('failed to access y'); }
10 | }
11 |
12 | foo();
13 |
14 |
15 |
--------------------------------------------------------------------------------
/elisp/symbol.el:
--------------------------------------------------------------------------------
1 | (message "%s" (symbol-name 'buffer-file-name))
2 | (message "%s" (symbol-value 'buffer-file-name))
3 | (message "------------------------")
4 | (message "%s" buffer-file-name)
5 | (message "%s" (buffer-file-name))
6 |
7 | (message "%s" (symbol-function 'symbol-value))
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/golang/fib_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func fib(n int) int {
8 | if n < 0 {
9 | return 0
10 | } else if n < 2 {
11 | return 1
12 | }
13 | return fib(n-1) + fib(n-2)
14 | }
15 |
16 | func main() {
17 | for i := 0; i < 10; i++ {
18 | fmt.Println(fib(i))
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/iolang/divzero.io:
--------------------------------------------------------------------------------
1 | (1 / 1) println
2 | (1 / 0) println
3 |
4 | origDiv := Number getSlot("/")
5 |
6 | Number / := method(x, if (x == 0, 0, self origDiv(x)))
7 |
8 | "---------------" println
9 |
10 | (5 / 1) println
11 | (30 / 2) println
12 | (100 / 0) println
13 |
14 | for(i, 0, 4, i println)
15 |
16 |
--------------------------------------------------------------------------------
/prolog/first_math.pro:
--------------------------------------------------------------------------------
1 | count(0, []).
2 | count(Count, [Head|Tail]) :- count(TailCount, Tail), Count is TailCount + 1.
3 |
4 | sum(0, []).
5 | sum(Total, [Head|Tail]) :- sum(Sum, Tail), Total is Head + Sum.
6 |
7 | average(Average, List) :- sum(Sum, List), count(Count, List), Average is Sum / Count.
8 |
9 |
10 |
--------------------------------------------------------------------------------
/javascript/dom/dom-update.html:
--------------------------------------------------------------------------------
1 |
2 |
javascript
3 |
Java
4 |
5 |
6 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/prolog/different.pro:
--------------------------------------------------------------------------------
1 |
2 | exclude([], _).
3 | exclude([A], B) :- \+(A=B).
4 | exclude([HA|LA], B) :- \+(LA=[]), \+(HA=B), exclude(LA, B).
5 |
6 | different([]).
7 | different([_]).
8 | different([HA|LA]) :- \+(LA=[]), exclude(LA, HA), different(LA).
9 |
10 | my_all_different(X) :- different(X).
11 |
12 |
13 |
--------------------------------------------------------------------------------
/prolog/factorial.pro:
--------------------------------------------------------------------------------
1 |
2 |
3 | factorial(0, 1).
4 | factorial(1, 1).
5 | factorial(2, 2).
6 | factorial(3, 6).
7 |
8 | factorial(N, V) :-
9 | N > 3, N1 is N - 1,
10 | factorial(N1, V1), V is V1 * N.
11 |
12 | factorial(N, V) :-
13 | V > 6,
14 | factorial(N1, V1), V is V1 * N, N1 is N - 1.
15 |
16 |
17 |
--------------------------------------------------------------------------------
/prolog/reverse.pro:
--------------------------------------------------------------------------------
1 |
2 | reverse([], []).
3 | reverse([A], [A]).
4 |
5 | reverse([HA|LA], B) :-
6 | \+(LA=[]),
7 | reverse(LA, B1),
8 | \+(B1=[]),
9 | append(B1, [HA], B).
10 |
11 | reverse(A, [HB|LB]) :-
12 | \+(LB=[]),
13 | reverse(A1, LB),
14 | \+(A1=[]),
15 | append(A1, [HB], A).
16 |
17 |
18 |
--------------------------------------------------------------------------------
/scala/nice.scala:
--------------------------------------------------------------------------------
1 | class Person(val name:String)
2 |
3 | trait Nice {
4 | def greet() = println("Howdily doodily.")
5 | }
6 |
7 | class Character(override val name:String) extends Person(name) with Nice
8 |
9 | val flanders = new Character("Ned")
10 | flanders.greet
11 | println(flanders.name)
12 |
13 |
14 |
--------------------------------------------------------------------------------
/golang/lib/sort_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "sort"
6 | )
7 |
8 | func main() {
9 | array := []int{10, 5, 3, 7, 2, 8, 9, 4, 6, 1}
10 | fmt.Println(array)
11 | sort.Ints(array)
12 | fmt.Println(array)
13 | a2 := array[5:7]
14 | a3 := a2[:5]
15 | fmt.Println(a3)
16 | fmt.Println(cap(a2))
17 | }
18 |
--------------------------------------------------------------------------------
/ruby/execute.rb:
--------------------------------------------------------------------------------
1 | require 'Open3'
2 |
3 | def backtick
4 | return `dir`
5 | end
6 |
7 | def capture
8 | text, code = Open3.capture2e 'dir'
9 | return text
10 | end
11 |
12 | x = backtick
13 | puts '-' * 72
14 | puts x
15 |
16 | puts '-' * 72
17 | x = capture
18 | puts '-' * 72
19 | puts x
20 |
21 |
22 |
--------------------------------------------------------------------------------
/elisp/sequence.el:
--------------------------------------------------------------------------------
1 | (setq x [1 2 3 4 5])
2 |
3 | (message "%d %s %s" (length x) x (elt x 2))
4 |
5 | (setq y [10 20 30])
6 |
7 | (setq z (vconcat x y))
8 | (message "x is %s" x)
9 | (message "y is %s" y)
10 | (message "z is %s" z)
11 |
12 |
13 | (setq h (make-hash-table))
14 | (message "%s" h)
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/golang/basic/slice_test8.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | slice1 := []int{10, 20, 30, 40, 50}
9 | slice2 := []int{100, 200, 300, 400, 500}
10 | fmt.Printf("\v\n", slice1)
11 | slice3 := append(slice1, slice2...)
12 | fmt.Printf("\v\n", slice1)
13 | fmt.Printf("\v\n", slice3)
14 | }
15 |
--------------------------------------------------------------------------------
/golang/log_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | )
6 |
7 | func init() {
8 | log.SetPrefix("TRACE: ")
9 | log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
10 | }
11 |
12 | func main() {
13 | log.Println("message", 1)
14 | log.Fatalln("fatal message", 2)
15 | log.Panicln("panic message", 3)
16 | }
17 |
--------------------------------------------------------------------------------
/scheme/clojure.scm:
--------------------------------------------------------------------------------
1 | (define cc
2 | (lambda (x)
3 | (lambda ()
4 | (begin
5 | (set! x (+ x 1))
6 | (display x)
7 | (newline)
8 | x
9 | )
10 | )
11 | )
12 | )
13 |
14 | (define c1 (cc 10))
15 | (define c2 (cc 20))
16 | (c1)
17 | (c1)
18 | (c2)
19 | (c2)
20 | (c1)
21 | (c1)
22 |
23 |
--------------------------------------------------------------------------------
/erlang/message.erl:
--------------------------------------------------------------------------------
1 | -module(message).
2 | -export([main/1]).
3 |
4 |
5 | detect(success) ->
6 | io:format("success~n"),
7 | success;
8 | detect({error, Message}) ->
9 | io:format("error: ~ts~n", [Message]).
10 |
11 |
12 | main(_) ->
13 | detect(success),
14 | detect({error, "don't touch me here"}).
15 |
16 |
17 |
--------------------------------------------------------------------------------
/prolog/lover.pro:
--------------------------------------------------------------------------------
1 | love(zhangxueyou,wanfei).
2 | love(zhangxueyou,zouhuimin).
3 | love(wanfei,xietinfen).
4 | love(zouhuimin,zhangxueyou).
5 | love(xietinfen,wanfei).
6 | love(xietinfen,zouhuimin).
7 | love(liudehua,zouhuimin).
8 | lovers(X,Y):-love(X,Y),love(Y,X).
9 | rival_in_love(X,Y):-love(X,Z),\+(love(Z,X)),love(Z,Y).
10 |
11 |
--------------------------------------------------------------------------------
/python/parser/grammar/expr_action.txt:
--------------------------------------------------------------------------------
1 | E: E '+' T {add}
2 | | E '-' T {sub}
3 | | T {get1}
4 | ;
5 | T: T '*' F {mul}
6 | | T '/' F {div}
7 | | F {get1}
8 | ;
9 | F: number {getint}
10 | | "(" E ")" {get2}
11 | ;
12 |
13 | %token number
14 |
15 | @ignore [ \t\r\n]*
16 | @match number \d+
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/ruby/grep.rb:
--------------------------------------------------------------------------------
1 |
2 | def grep(word, filename)
3 | File.open(filename, 'r') do |fp|
4 | number = 0
5 | fp.each do |line|
6 | number += 1
7 | text = "#{filename}:#{number}: #{line}"
8 | puts text if line.match(word) != nil
9 | end
10 | end
11 | end
12 |
13 |
14 | grep('Video', '../data/win.ini')
15 |
16 |
17 |
--------------------------------------------------------------------------------
/prolog/person.pro:
--------------------------------------------------------------------------------
1 | % This is the syntax for comments. % MORTAL - The first illustrative Prolog
2 | % program mortal(X) :- person(X).
3 | person(socrates).
4 | person(plato).
5 | person(aristotle).
6 | mortal(X) :- person(X).
7 |
8 | mortal_report:-
9 | write('Known mortals are:'),nl, mortal(X), write(X),nl,
10 | fail.
11 |
12 |
13 |
--------------------------------------------------------------------------------
/javascript/basic/object_class.js:
--------------------------------------------------------------------------------
1 | function classof(o) {
2 | if (o === null) return "Null";
3 | if (o === undefined) return 'Undefined';
4 | return Object.prototype.toString.call(o).slice(8, -1);
5 | }
6 |
7 | console.log(classof(classof));
8 | console.log(classof);
9 | console.log(Object.prototype.toString.call(classof));
10 |
11 |
12 |
--------------------------------------------------------------------------------
/golang/legacy/http_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "io"
5 | "net/http"
6 | "os"
7 | )
8 |
9 | func main() {
10 | var url string = "https://www.baidu.com"
11 | r, err := http.Get(url)
12 | if err != nil {
13 | panic(err)
14 | }
15 | io.Copy(os.Stdout, r.Body)
16 | if err := r.Body.Close(); err != nil {
17 | panic(err)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/golang/legacy/http_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "io"
5 | "net/http"
6 | "os"
7 | )
8 |
9 | func main() {
10 | var url string = "https://www.baidu.com"
11 | r, err := http.Get(url)
12 | if err != nil {
13 | panic(err)
14 | }
15 | io.Copy(os.Stdout, r.Body)
16 | if err := r.Body.Close(); err != nil {
17 | panic(err)
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/scala/constructor.scala:
--------------------------------------------------------------------------------
1 | class Person(first_name:String) {
2 | println("Outer constructor")
3 | def this(first_name: String, last_name: String) {
4 | this(first_name)
5 | println("Inner constructor")
6 | }
7 | def talk() = println("Hi")
8 | }
9 |
10 | val bob = new Person("Bob")
11 | val bobTate = new Person("Bob", "Tate")
12 |
13 |
14 |
--------------------------------------------------------------------------------
/golang/basic/array_test4.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func foo(a [5]int) {
8 | a[0] = 100
9 | fmt.Println(a)
10 | }
11 |
12 | func bar(a *[5]int) {
13 | a[0] = 200
14 | fmt.Println(a)
15 | }
16 |
17 | func main() {
18 | b := [...]int{1, 2, 3, 4, 5}
19 | foo(b)
20 | fmt.Println(b)
21 | bar(&b)
22 | fmt.Println(b)
23 | }
24 |
--------------------------------------------------------------------------------
/python/parser/grammar/conflict_1.txt:
--------------------------------------------------------------------------------
1 | %token NUMBER
2 |
3 | %left '+' '-'
4 | %left '*' '/' '%'
5 | %right UMINUS
6 |
7 | expr: expr '+' expr
8 | | expr '-' expr
9 | | expr '*' expr
10 | | expr '/' expr
11 | | '(' expr ')'
12 | | '-' expr %prec UMINUS
13 | | NUMBER
14 | ;
15 |
16 | @ignore [ \r\n\t]*
17 | @match NUMBER \d+
18 |
19 |
--------------------------------------------------------------------------------
/golang/app/usepkg/use_package.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/skywind3000/gosub"
7 | dummy2 "github.com/skywind3000/gosub/dummy"
8 | )
9 |
10 | func main() {
11 | fmt.Println("Hello, World!")
12 | x := gosub.DummySub(1, 2)
13 | fmt.Println("1 + 2 =", x)
14 | y := dummy2.DummyAdd2(9, 10)
15 | fmt.Println("add2=", y)
16 | }
17 |
--------------------------------------------------------------------------------
/golang/basic/array_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | a := [...]int{1, 2, 3}
7 | b := a[1:2]
8 | c := append(b, 9)
9 | b[0] = 100
10 | var d [5]int = [5]int{1: 100, 3: 200}
11 | fmt.Println(a)
12 | fmt.Println(cap(a))
13 | fmt.Println(len(b))
14 | fmt.Println(b)
15 | fmt.Println(c)
16 | fmt.Println(d)
17 | }
18 |
--------------------------------------------------------------------------------
/haskell/lazy_list.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | every2 x = x : every2 (x + 2)
3 | every4 x = x : every4 (x + 4)
4 |
5 | combo (x, y) = [(a + b + c) | (a, b, c) <- (zip3 (every2 x) (every4 y) [0..])]
6 |
7 | main = do
8 | print (take 5 (every2 0))
9 | print (take 5 (every4 0))
10 | print (take 10 (combo(3, 1)))
11 |
12 |
13 |
--------------------------------------------------------------------------------
/pascal/PL0/demo.pl0:
--------------------------------------------------------------------------------
1 | var n,ret,data;
2 |
3 | procedure myproc;
4 | var save;
5 | begin
6 | if n=1 then ret:=1;
7 | if n>1 then begin
8 | save:=n;
9 | n:=n-1;
10 | call myproc;
11 | n:=save;
12 | ret:=ret*n;
13 | end;
14 | end;
15 |
16 | begin
17 | read(n);
18 | call myproc;
19 | write(ret);
20 | end.
--------------------------------------------------------------------------------
/csharp/object.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | class Hello {
4 | static void Main(string[] args) {
5 | Console.WriteLine("Hello, World");
6 | int x = 10;
7 | Object y = x;
8 | int z = (int)y;
9 | Console.WriteLine(y);
10 | Console.WriteLine(z);
11 | System.String abc = "Hello";
12 | Object zz = abc;
13 | Console.WriteLine(zz);
14 | }
15 | }
16 |
17 |
18 |
--------------------------------------------------------------------------------
/golang/basic/type_test4.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type Number int
8 |
9 | func (self *Number) add(x Number) {
10 | *self += x
11 | }
12 |
13 | func (self Number) mul(x Number) Number {
14 | return self * x
15 | }
16 |
17 | func main() {
18 | var x Number = 10
19 | x.add(5)
20 | fmt.Println("x = ", x)
21 | fmt.Println(Number(10).mul(5))
22 | }
23 |
--------------------------------------------------------------------------------
/golang/legacy/variable_decl.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "reflect"
6 | )
7 |
8 |
9 | func main() {
10 | var x, y int = 1, 2
11 | fmt.Printf("%s\n", reflect.TypeOf(x))
12 | fmt.Printf("%s\n", reflect.TypeOf(y))
13 | z := [4]int{1,2,3};
14 | fmt.Printf("%s\n", z)
15 | var w *int = &x;
16 | fmt.Printf("%s\n", reflect.TypeOf(w))
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/golang/legacy/read_file.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "io/ioutil"
6 | )
7 |
8 | func main() {
9 | file, err := ioutil.ReadFile("read_file.go")
10 | if err != nil {
11 | fmt.Println("Error reading file")
12 | return
13 | }
14 | fmt.Println(string(file))
15 | // count := words.CountWords(text)
16 | // fmt.Printf("There are %d words in the text.\n", count)
17 | }
18 |
--------------------------------------------------------------------------------
/javascript/basic/object_getter.js:
--------------------------------------------------------------------------------
1 | var o = {
2 | data: 10,
3 | get access_prop() { return this.data; },
4 | set access_prop(value) { this.data = value; },
5 | }
6 |
7 | console.log(o.access_prop);
8 | o.access_prop = 33;
9 | console.log(o.access_prop);
10 |
11 | console.log(o.propertyIsEnumerable('access_prop'));
12 | console.log(o.propertyIsEnumerable('data'));
13 |
14 |
15 |
--------------------------------------------------------------------------------
/erlang/qsort.erl:
--------------------------------------------------------------------------------
1 | -module(qsort).
2 | -export([main/1, qsort/1]).
3 |
4 |
5 | qsort([]) ->
6 | [];
7 | qsort([H|L]) ->
8 | A = [X || X <- L, X < H],
9 | B = [X || X <- L, X > H],
10 | C = [X || X <- L, X == H],
11 | lists:append([qsort(A), [H], C, qsort(B)]).
12 |
13 |
14 | main(_) ->
15 | io:format("~p~n", [qsort([3,1,4,1,5,9,2,6,5,3,5])]),
16 | ok.
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/golang/reader_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "io"
6 | "strings"
7 | )
8 |
9 | func main() {
10 | r := strings.NewReader("Hello, Reader!")
11 |
12 | b := make([]byte, 8)
13 | for {
14 | n, err := r.Read(b)
15 | fmt.Printf("n = %v err = %v b = %v\n", n, err, b)
16 | fmt.Printf("b[:n] = %q\n", b[:n])
17 | if err == io.EOF {
18 | break
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/prolog/food.pro:
--------------------------------------------------------------------------------
1 | food_type(velveeta, cheese).
2 | food_type(ritz, cracker).
3 | food_type(spam, meat).
4 | food_type(sausage, meat).
5 | food_type(jolt, soda).
6 | food_type(twinkie, dessert).
7 |
8 | flavor(sweet, dessert).
9 | flavor(savory, meat).
10 | flavor(savory, cheese).
11 | flavor(sweet, soda).
12 |
13 |
14 | food_flavor(X, Y) :- food_type(X, Z), flavor(Y, Z).
15 |
16 |
--------------------------------------------------------------------------------
/prolog/queen3.pro:
--------------------------------------------------------------------------------
1 | :-use_module(library(clpfd)).
2 | :-include('plib.pro').
3 |
4 | solve(P) :-
5 | perm([1,2,3,4,5,6,7,8],P),
6 | combine([1,2,3,4,5,6,7,8],P,S,D),
7 | different(S),
8 | different(D).
9 |
10 | combine([X1|X], [Y1|Y], [S1|S], [D1|D]) :-
11 | S1 is X1 + Y1,
12 | D1 is X1 - Y1,
13 | combine(X, Y, S, D).
14 |
15 | combine([], [], [], []).
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/python/property1.py:
--------------------------------------------------------------------------------
1 |
2 | class Foo:
3 |
4 | def __init__ (self):
5 | self.__x = 100
6 |
7 | @property
8 | def value (self):
9 | return self.__x
10 |
11 | @value.setter
12 | def value (self, x):
13 | self.__x = x * 100
14 |
15 | f = Foo()
16 |
17 | print(f.value)
18 |
19 | f.value = 99
20 |
21 | print(f.value)
22 |
23 |
24 |
--------------------------------------------------------------------------------
/golang/basic/array_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | var array1 [3]*string
9 | array2 := [3]*string{new(string), new(string), new(string)}
10 | *array2[0] = "Red"
11 | *array2[1] = "Blue"
12 | *array2[2] = "Green"
13 | array1 = array2
14 | fmt.Println(array1)
15 | for i := 0; i < len(array1); i++ {
16 | fmt.Println(*array1[i])
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/haskell/lazy_fib.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | lazyFib x y = x:(lazyFib y (x + y))
3 | fib = lazyFib 1 1
4 |
5 | fibNth x = head (drop (x - 1) (take (x) fib))
6 |
7 | main = do
8 | print (take 5 (lazyFib 0 1))
9 | print (take 5 (fib))
10 | print (take 5 (drop 20 (lazyFib 0 1)))
11 | print (fibNth 3)
12 | print (fibNth 6)
13 |
14 |
--------------------------------------------------------------------------------
/golang/basic/generic_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func Index[T comparable](s []T, t T) int {
6 | for i, v := range s {
7 | if v == t {
8 | return i
9 | }
10 | }
11 | return -1
12 | }
13 |
14 | func main() {
15 | si := []int{10, 20, 15, -10}
16 | fmt.Println(Index(si, 15)) // 2
17 | ss := []string{"foo", "bar", "baz"}
18 | fmt.Println(Index(ss, "hello")) // -1
19 | }
20 |
--------------------------------------------------------------------------------
/javascript/dom/dom-insert-exist.html:
--------------------------------------------------------------------------------
1 | JavaScript
2 |
3 |
Java
4 |
Python
5 |
Scheme
6 |
7 |
8 |
16 |
17 |
--------------------------------------------------------------------------------
/lua/index.lua:
--------------------------------------------------------------------------------
1 | local z = require('z')
2 |
3 | local m = {[0] = 1, 2, 3, 4, [-2] = 3, linwei = 4, ['weilin'] = 5}
4 |
5 | z.printT(m)
6 |
7 | local m = {[0] = 100, 101, 102, 103}
8 | print('size', #m)
9 | z.printT(m)
10 |
11 | for i, j in ipairs(m) do
12 | print(i, '->', j)
13 | end
14 |
15 | print('----')
16 |
17 | for i, j in pairs(m) do
18 | print(i, '->', j)
19 | end
20 |
21 |
--------------------------------------------------------------------------------
/elisp/dayname.el:
--------------------------------------------------------------------------------
1 | (defun day-name (day)
2 | (catch 'return
3 | (case day
4 | (0
5 | (throw 'return "Sunday"))
6 | (6
7 | (throw 'return "Saturday"))
8 | (t
9 | (throw 'return "weekday")))))
10 |
11 | (message "%s %s" (day-name 0) (day-name 5))
12 |
13 | (message "size %d %d %d"
14 | (length (list 1 2))
15 | (length (vector 1 2 3 4))
16 | (length "Hello"))
17 |
18 |
--------------------------------------------------------------------------------
/python/parser/grammar/test_epsilon.txt:
--------------------------------------------------------------------------------
1 | %token digit NUMBER
2 | %left '+' '-'
3 | %left '*' "/"
4 | %nonassoc UMINUS
5 |
6 | %%
7 | expr: expr + term | expr - term | term;
8 |
9 | term:
10 | term * factor
11 | | term / factor
12 | | factor
13 | ;
14 |
15 | factor: {haha} digit
16 | | {action0} '(' expr ')' {action2} %prec UMINUS;
17 |
18 | %%
19 |
20 | %start term
21 |
22 |
23 |
--------------------------------------------------------------------------------
/python/queen4.py:
--------------------------------------------------------------------------------
1 | f = lambda A, x, y: y < 0 or (not (A[y] in (A[x], A[x] + (x - y), A[x] - (x - y))))
2 | g = lambda A, x, y: (not x) or (f(A, x, y) and ((y < 0) or g(A, x, y - 1)))
3 | h = lambda A, x: sum([ g(A, x, x - 1) and 1 or 0 for A[x] in range(len(A)) ])
4 | q = lambda A, x: h(A, x) if (x == 7) else sum([ q(A, x + 1) for A[x] in range(8) if g(A, x, x - 1) ])
5 |
6 | print(q([ 0 for i in range(8) ], 0))
7 |
--------------------------------------------------------------------------------
/erlang/yet_again.erl:
--------------------------------------------------------------------------------
1 |
2 |
3 | -module(yet_again).
4 | -export([another_factorial/1]).
5 | -export([another_fib/1]).
6 |
7 | another_factorial(0) -> 1;
8 | another_factorial(N) -> N * another_factorial(N - 1).
9 |
10 | another_fib(one) -> 1;
11 | another_fib(zero) -> 1;
12 | another_fib(0) -> 1;
13 | another_fib(1) -> 1;
14 | another_fib(N) -> another_fib(N - 1) + another_fib(N - 2).
15 |
16 |
17 |
--------------------------------------------------------------------------------
/golang/basic/map_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | colors := map[string]string{
9 | "AliceBlue": "#f0f8ff",
10 | "Coral": "#ff7f50",
11 | "DarkGray": "#a9a9a9",
12 | "ForestGreen": "#228b22",
13 | }
14 |
15 | delete(colors, "Coral")
16 |
17 | for key, value := range colors {
18 | fmt.Printf("Key: %s Value: %s\n", key, value)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/golang/lib/buffer_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "fmt"
6 | )
7 |
8 | func main() {
9 | var buf bytes.Buffer
10 | buf.Write([]byte("Hello, World!"))
11 | buf.Write([]byte(" 1234\n"))
12 | // buf.WriteTo(os.Stdout)
13 |
14 | s := make([]byte, 5)
15 | n, e := buf.Read(s)
16 | fmt.Printf("%v %v %v\n", s, n, e)
17 | n, e = buf.Read(s)
18 | fmt.Printf("%v %v %v\n", s, n, e)
19 | }
20 |
--------------------------------------------------------------------------------
/html/page_scale.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
17 | Scale me up!
18 | Hello World!
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/prolog/family2.pro:
--------------------------------------------------------------------------------
1 | male(di).
2 | male(jianbo).
3 | female(xin).
4 | female(yuan).
5 | female(yuqing).
6 | father(jianbo, di).
7 | father(di, yuqing).
8 | mother(xin, di).
9 | mother(yuan, yuqing).
10 |
11 | grandfather(X, Y) :- father(X, Z), father(Z, Y).
12 | grandmother(X, Y) :- mother(X, Z), mother(Z, Y).
13 | daughter(X, Y) :- father(X, Y),female(Y).
14 | son(X, Y) :- father(X, Y),male(Y).
15 |
16 |
--------------------------------------------------------------------------------
/iolang/builder.io:
--------------------------------------------------------------------------------
1 | Builder := Object clone
2 |
3 | Builder forward := method(
4 | writeln("<", call message name, ">")
5 | call message arguments foreach(
6 | arg,
7 | content := self doMessage(arg);
8 | if (content type == "Sequence", writeln(content)))
9 | writeln("", call message name, ">"))
10 |
11 | Builder ul(
12 | li("Io"),
13 | li("Lua"),
14 | li("JavaScript"))
15 |
16 |
17 |
--------------------------------------------------------------------------------
/python/cotest1.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import time
3 |
4 | async def task1(n):
5 | print(''%n)
6 | await asyncio.sleep(1)
7 | print(''%n)
8 | return n * 10
9 |
10 | async def main():
11 | for i in range(10):
12 | p = asyncio.create_task(task1(i))
13 | while 1:
14 | await asyncio.sleep(1)
15 | return 0
16 |
17 | asyncio.run(main())
18 |
19 |
--------------------------------------------------------------------------------
/ruby/units.rb:
--------------------------------------------------------------------------------
1 | class Numeric
2 | def inches
3 | self
4 | end
5 |
6 | def feet
7 | self * 12.inches
8 | end
9 |
10 | def yards
11 | self * 3.feet
12 | end
13 |
14 | def miles
15 | self * 5280.feet
16 | end
17 |
18 | def back
19 | self * -1
20 | end
21 |
22 | def forward
23 | self
24 | end
25 | end
26 |
27 | puts 10.miles.back
28 | puts 2.feet.forward
29 |
30 |
31 |
--------------------------------------------------------------------------------
/haskell/fib2.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | fibTuple :: (Integer, Integer, Integer) -> (Integer, Integer, Integer)
3 | fibTuple (x, y, 0) = (x, y, 0)
4 | fibTuple (x, y, index) = fibTuple(y, x + y, index - 1)
5 |
6 | fibResult :: (Integer, Integer, Integer) -> Integer
7 | fibResult(x, y, z) = y
8 |
9 | fib x = fibResult(fibTuple(0, 1, x))
10 |
11 |
12 | main = print(fib(8))
13 |
14 |
--------------------------------------------------------------------------------
/golang/basic/type_test3.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "net"
6 | )
7 |
8 | // net.IP definition: "type IP []byte"
9 | func main() {
10 | ip1 := net.IP{192, 168, 1, 1}
11 | ip2 := ip1
12 | fmt.Println(ip1)
13 | fmt.Println(ip2)
14 | ip2[3] = 5
15 | fmt.Println(ip1)
16 | fmt.Println(ip2)
17 | }
18 |
19 | /*
20 | output:
21 |
22 | 192.168.1.1
23 | 192.168.1.1
24 | 192.168.1.5
25 | 192.168.1.5
26 | */
27 |
--------------------------------------------------------------------------------
/python/parser/grammar/conflict_2.txt:
--------------------------------------------------------------------------------
1 | %token NUMBER
2 |
3 | %left '+' '-'
4 | %left '*' '/' '%'
5 | %right UMINUS
6 |
7 | expr: expr '+' expr {add}
8 | | expr '-' expr {sub}
9 | | expr '*' expr {mul}
10 | | expr '/' expr {div}
11 | | '(' expr ')' {get2}
12 | | '-' expr %prec UMINUS {negative}
13 | | NUMBER {getint}
14 | ;
15 |
16 | @ignore [ \r\n\t]*
17 | @match NUMBER \d+
18 |
19 |
20 |
--------------------------------------------------------------------------------
/golang/legacy/producer.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | var cc = make(chan int)
4 | var finish = make(chan int)
5 |
6 | func worker() {
7 | for {
8 | x := <- cc
9 | if x <= 0 {
10 | println("exit")
11 | break
12 | } else {
13 | println("got", x)
14 | }
15 | }
16 | finish <- 10
17 | }
18 |
19 | func main() {
20 | go worker()
21 | cc <- 20
22 | cc <- 30
23 | cc <- 0
24 | <- finish
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/html/basic/layout_1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
vertical a
13 |
vertical b
14 |
vertical c
15 |
16 |
17 |
18 |
horizontal a
19 |
horizontal b
20 |
horizontal c
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/haskell/fib3.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | fibNextPair :: (Integer, Integer) -> (Integer, Integer)
3 | fibNextPair (x, y) = (y, x + y)
4 |
5 | fibNthPair :: Integer -> (Integer, Integer)
6 | fibNthPair 0 = (0, 1)
7 | fibNthPair 1 = (1, 1)
8 | fibNthPair n = fibNextPair(fibNthPair(n - 1))
9 |
10 | fib :: Integer -> Integer
11 | fib = fst . fibNthPair
12 |
13 | main = print(fib 6)
14 |
15 |
16 |
--------------------------------------------------------------------------------
/ruby/to_file.rb:
--------------------------------------------------------------------------------
1 |
2 | module ToFile
3 | def filename
4 | "object_#{self.object_id}.txt"
5 | end
6 | def to_f
7 | File.open(filename, 'w') { |f| f.write(to_s) }
8 | end
9 | end
10 |
11 | class Person
12 | include ToFile
13 | attr_accessor :name
14 |
15 | def initialize(name)
16 | @name = name
17 | end
18 |
19 | def to_s
20 | name
21 | end
22 | end
23 |
24 | Person.new('matz').to_f
25 |
26 |
27 |
--------------------------------------------------------------------------------
/scala/trait.scala:
--------------------------------------------------------------------------------
1 |
2 | class Employee(val name:String) {
3 | def work() = println("I am working")
4 | }
5 |
6 | trait Dev {
7 | def code() = println("I am coding")
8 | }
9 |
10 | class Principal(override val name:String) extends Employee(name) with Dev {
11 | override def work() = println("Pincipal " + name + " is working")
12 | }
13 |
14 | val fred = new Principal("Fred")
15 | fred.work
16 | fred.code
17 |
18 |
19 |
--------------------------------------------------------------------------------
/javascript/dom/dom-iterate.html:
--------------------------------------------------------------------------------
1 |
2 |
Java
3 |
Haskell
4 |
Python
5 |
Scheme
6 |
7 |
16 |
17 |
--------------------------------------------------------------------------------
/scala/movies.scala:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | val movies =
5 | The Incredibles
6 | WALL E
7 | Jack Jack Attack
8 | Geri's Game
9 |
10 |
11 | (movies \ "_").foreach {movie =>
12 | movie match {
13 | case {movieName} => println(movieName)
14 | case {shortName} => println(shortName + " (short)")
15 | }
16 | }
17 |
18 |
19 |
--------------------------------------------------------------------------------
/elisp/hash.el:
--------------------------------------------------------------------------------
1 | (setq table (make-hash-table :test 'equal))
2 |
3 | (setf (gethash "one" table) 100)
4 | (message "%s" (gethash "one" table))
5 | (message "%s" (gethash "two" table))
6 |
7 | (puthash "three" 3 table)
8 |
9 | (defun print-hash (key value)
10 | (message "key=%s value=%s" key value))
11 |
12 | (print-hash 10 20)
13 | (maphash 'print-hash table)
14 | (message "hash code %d" (sxhash "HELLO"))
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/javascript/basic/object_proto2.js:
--------------------------------------------------------------------------------
1 | function inherit(p) {
2 | if (p == null)
3 | throw TypeError();
4 | if (Object.create)
5 | return Object.create(p);
6 | var t = typeof(p);
7 | if (t != 'function' && t != 'object')
8 | throw TypeError();
9 | function f() {};
10 | f.prototype = p;
11 | return new f();
12 | }
13 |
14 | var o = {x: 'dont change this value'};
15 | var x = inherit(o);
16 |
17 | console.log(x);
18 |
19 |
20 |
--------------------------------------------------------------------------------
/python/cotest2.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 |
3 | async def foo():
4 | return 10
5 |
6 | async def main():
7 | coro = foo()
8 | task = asyncio.create_task(coro)
9 | done, pending = await asyncio.wait({task})
10 | if task in done:
11 | print('done')
12 | elif task in pending:
13 | print('pending')
14 | else:
15 | print('else')
16 | return 0
17 |
18 | asyncio.run(main())
19 |
20 |
21 |
--------------------------------------------------------------------------------
/haskell/curry2.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 |
3 | -- divide :: Number num => (num, num) -> num
4 | divide (x, y) = x / y
5 |
6 | concatstr :: ([Char], [Char]) -> [Char]
7 | concatstr (x, y) = x ++ y
8 |
9 | half x = divide(x, 2)
10 | newline x = concatstr(x, "\n")
11 |
12 | main = do
13 | print (half 10)
14 | print (newline "sucker")
15 | print (newline "sucker 2")
16 |
17 |
18 |
--------------------------------------------------------------------------------
/csharp/array1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | class TestArrayClass {
4 | static void Main() {
5 | Console.WriteLine("arrays");
6 | int[] array1 = new int[5];
7 | int[] array2 = new int[] { 1, 3, 5, 7, 9 };
8 | int[] array3 = { 1, 2, 3, 4, 5, 6 };
9 | int[,] matrix1 = new int[2, 3];
10 | int[,] matrix2 = { {1, 2, 3}, {4, 5, 6} };
11 | int[][] jagged = new int[6][];
12 | jagged[0] = new int[4] {1, 2, 3, 4};
13 | }
14 | }
15 |
16 |
17 |
--------------------------------------------------------------------------------
/csharp/variables.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | class Variables {
4 | static void Main(string[] args) {
5 | Console.WriteLine(sizeof(byte));
6 | Console.WriteLine(sizeof(sbyte));
7 | Console.WriteLine(sizeof(char));
8 | Console.WriteLine(sizeof(short));
9 | Console.WriteLine(sizeof(uint));
10 | Console.WriteLine(sizeof(int));
11 | Console.WriteLine(sizeof(UInt32));
12 | Console.WriteLine(sizeof(Int16));
13 | }
14 | }
15 |
16 |
17 |
--------------------------------------------------------------------------------
/erlang/coroner.erl:
--------------------------------------------------------------------------------
1 | -module(coroner).
2 | -export([loop/0]).
3 |
4 | loop() ->
5 | process_flag(trap_exit, true),
6 | receive
7 | {monitor, Process} ->
8 | link(Process),
9 | io:format("Monitoring process ~p~n", [Process]),
10 | loop();
11 |
12 | {'EXIT', From, Reason} ->
13 | io:format("The shooter ~p died with reason ~p. ", [From, Reason]),
14 | io:format("Start another one.~n"),
15 | loop()
16 | end.
17 |
18 |
19 |
--------------------------------------------------------------------------------
/golang/legacy/slice_test3.go:
--------------------------------------------------------------------------------
1 | // vim: set ts=4 sw=4 tw=0 noet ft=go :
2 | package main
3 |
4 | import (
5 | "fmt"
6 | )
7 |
8 | func main() {
9 | var a [100]int
10 | b := make([]int, 256)
11 | a[0] = 1
12 | for i := 0; i < len(b); i++ {
13 | b[i] = i;
14 | }
15 | copy(a[5:], b[:10])
16 | for i := 0; i < 20; i++ {
17 | fmt.Println(a[i])
18 | }
19 | var z [3]int = [...]int{1, 2, 3}
20 | fmt.Println(z)
21 | }
22 |
23 |
24 |
--------------------------------------------------------------------------------
/javascript/basic/closure_counter.js:
--------------------------------------------------------------------------------
1 |
2 | function counter() {
3 | var n = 0;
4 | return {
5 | count: function() { return n++; },
6 | reset: function() { n = 0; },
7 | };
8 | }
9 |
10 | var c = counter();
11 | var d = counter();
12 |
13 | console.log(c.count());
14 | console.log(d.count());
15 | console.log(c.count());
16 | console.log(d.count());
17 | c.reset();
18 |
19 | console.log(c.count());
20 | console.log(d.count());
21 |
22 |
--------------------------------------------------------------------------------
/javascript/dom/dom-remove.html:
--------------------------------------------------------------------------------
1 |
2 | - JavaScript
3 | - Swift
4 | - HTML
5 | - ANSI C
6 | - CSS
7 | - DirectX
8 |
9 |
10 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/scheme/diamon.scm:
--------------------------------------------------------------------------------
1 | (define (iter f i n)
2 | (if (< i n) (begin (f i) (iter f (+ i 1) n) )) )
3 |
4 | (define (row n m)
5 | (define x (- (/ m 2) n 1))
6 | (iter (lambda (i) (display " ")) 0 x)
7 | (iter (lambda (i) (display "#")) 0 (+ n n 1))
8 | (newline)
9 | )
10 |
11 | (define max 40)
12 | (define num 10)
13 |
14 | (iter (lambda (i) (row i max)) 0 num)
15 | (iter (lambda (i) (row (- num i) max)) 0 (+ num 1))
16 | (newline)
17 |
18 |
19 |
--------------------------------------------------------------------------------
/golang/basic/any_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type Packet struct {
4 | cmd int
5 | data int
6 | }
7 |
8 | func NewPacket(cmd int, data int) *Packet {
9 | return &Packet{cmd, data}
10 | }
11 |
12 | func main() {
13 | pending := make([]any, 0)
14 | for i := 0; i < 10; i++ {
15 | p := NewPacket(1, i)
16 | pending = append(pending, p)
17 | }
18 | for i := 0; i < len(pending); i++ {
19 | p := pending[i].(*Packet)
20 | println(p.cmd, p.data)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/iolang/guess.io:
--------------------------------------------------------------------------------
1 |
2 | key := (Random value * 1000) ceil
3 |
4 | while(true,
5 | "Enter your guess: " print
6 | x := File standardInput readLine asNumber
7 | ((x asString) .. " has been entered") println
8 | if (x == key,
9 | ("Yes you are right, secret key is: " .. (key asString)) println
10 | break)
11 | if (x < key, "your input is less than secret key" println,
12 | "your input is great than secret key" println)
13 | )
14 |
15 |
16 |
--------------------------------------------------------------------------------
/golang/basic/slice_test3.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func printSlice(x []int) {
8 | fmt.Printf("slice[%d/%d]: ", len(x), cap(x))
9 | for i := 0; i < len(x); i++ {
10 | fmt.Printf("%d ", x[i])
11 | }
12 | fmt.Println("")
13 | }
14 |
15 | func main() {
16 | fmt.Println("Hello, World!")
17 | a := []int{1, 2, 3, 4, 5}
18 | b := a[2:4]
19 | printSlice(a)
20 | printSlice(b)
21 | b = append(b, 9)
22 | printSlice(a)
23 | printSlice(b)
24 | }
25 |
--------------------------------------------------------------------------------
/iolang/coroutine.io:
--------------------------------------------------------------------------------
1 | vizzini := Object clone
2 | vizzini talk := method(
3 | "Fezzik, are there rocks ahead?" println
4 | yield
5 | "No more rhymes now, I mean it." println
6 | yield)
7 |
8 | fezzik := Object clone
9 | fezzik rhyme := method(
10 | yield
11 | "If there are, we'll all be dead." println
12 | yield
13 | "Anybody want a peanut?" println)
14 |
15 | vizzini @@talk
16 | fezzik @@rhyme
17 |
18 | Coroutine currentCoroutine pause
19 |
20 |
--------------------------------------------------------------------------------
/ruby/require_main.rb:
--------------------------------------------------------------------------------
1 | require "net/http"
2 |
3 | class Foo
4 | def self.bar
5 | puts "from Foo.bar"
6 | end
7 | end
8 |
9 | class Fuck
10 | class << Fuck
11 | def fuck
12 | puts "fucked here"
13 | end
14 | end
15 | end
16 |
17 |
18 | Foo::bar
19 |
20 | puts $LOAD_PATH
21 | $LOAD_PATH.unshift('./')
22 | require "require_lib"
23 |
24 | RequireLib.test
25 | RequireLib.test2
26 | Fuck.fuck
27 |
28 | puts File.dirname(__FILE__)
29 |
30 |
--------------------------------------------------------------------------------
/golang/app/readfile/read_file.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "io/ioutil"
6 |
7 | "github.com/goinaction/code/chapter3/words"
8 | )
9 |
10 | func main() {
11 | file, err := ioutil.ReadFile("read_file.go")
12 | if err != nil {
13 | fmt.Println("Error reading file")
14 | return
15 | }
16 | fmt.Println(string(file))
17 | text := string(file)
18 | count := words.CountWords(text)
19 | fmt.Printf("There are %d words in the text.\n", count)
20 | }
21 |
22 |
23 |
--------------------------------------------------------------------------------
/golang/basic/map_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | // var m map[string]int = map[string]int{}
7 | var m map[string]int = make(map[string]int)
8 | // m = make(map[string]int)
9 | if m == nil {
10 | println("m is nil")
11 | }
12 | m["one"] = 1
13 | fmt.Println(m)
14 | fmt.Println(m["one"])
15 | fmt.Println(len(m))
16 | value, exists := m["two"]
17 | println(value, exists)
18 | value, exists = m["one"]
19 | println(value, exists)
20 | }
21 |
--------------------------------------------------------------------------------
/javascript/dom/dom-insert-new.html:
--------------------------------------------------------------------------------
1 | JavaScript
2 |
3 |
Java
4 |
Python
5 |
Scheme
6 |
7 |
8 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/javascript/basic/function_length.js:
--------------------------------------------------------------------------------
1 |
2 | function check(args) {
3 | var actual = args.length;
4 | var expected = args.callee.length;
5 | if (actual != expected) {
6 | throw Error("Expected " + expected + " args, got " + actual);
7 | }
8 | }
9 |
10 | function f(x, y, z) {
11 | check(arguments);
12 | return x + y + z;
13 | }
14 |
15 | console.log("expecting to pass");
16 |
17 | f(1, 2, 3);
18 |
19 | console.log("expecting to crash");
20 |
21 | f(1);
22 |
23 |
--------------------------------------------------------------------------------
/python/panda3d/tut2.py:
--------------------------------------------------------------------------------
1 | from direct.showbase.ShowBase import ShowBase
2 |
3 | class MyApp (ShowBase):
4 |
5 | def __init__ (self):
6 | ShowBase.__init__(self)
7 | self.scene = self.loader.loadModel('models/environment')
8 | self.scene.reparentTo(self.render)
9 | self.scene.setScale(0.25, 0.25, 0.25)
10 | self.scene.setPos(-8, 42, 0)
11 | self.scene.setPos(-8, 42, -5)
12 |
13 | app = MyApp()
14 | app.run()
15 |
16 |
17 |
--------------------------------------------------------------------------------
/erlang/doctor.erl:
--------------------------------------------------------------------------------
1 | -module(doctor).
2 | -export([loop/0]).
3 |
4 | loop() ->
5 | process_flag(trap_exit, true),
6 | receive
7 | new ->
8 | io:format("Create and monitoring process ~n"),
9 | register(revolver, spawn_link(fun roulette:loop/0)),
10 | loop();
11 |
12 | {'EXIT', From, Reason} ->
13 | io:format("The shooter ~p died with reason ~p.", [From, Reason]),
14 | io:format(" Restarting. ~n"),
15 | self() ! new,
16 | loop()
17 | end.
18 |
19 |
20 |
--------------------------------------------------------------------------------
/javascript/basic/object_extend.js:
--------------------------------------------------------------------------------
1 |
2 | Object.defineProperty(Object.prototype, "extend", {
3 | writable: true,
4 | enumerable: false,
5 | configurable: true,
6 | value: function (o) {
7 | var names = Object.getOwnPropertyNames(o);
8 | for (var i = 0; i < names.length; i++) {
9 | if (names[i] in this) continue;
10 | var desc = Object.getOwnPropertyDescriptor(o, names[i]);
11 | Object.defineProperty(this, names[i], desc);
12 | }
13 | },
14 | });
15 |
16 |
17 |
--------------------------------------------------------------------------------
/javascript/basic/object_property.js:
--------------------------------------------------------------------------------
1 | var o = {};
2 |
3 | Object.defineProperty(o, 'x', { value: 1,
4 | writable: true, enumerable: true, configurable: true});
5 |
6 | console.log(o.x);
7 |
8 | o.x = 10;
9 | console.log(o.x);
10 |
11 | console.log(Object.keys(o));
12 |
13 | Object.defineProperty(o, 'x', {enumerable: false});
14 | console.log(Object.keys(o));
15 |
16 | Object.defineProperty(o, 'x', {writable: false});
17 | o.x = 20;
18 | console.log(o.x);
19 |
20 |
21 |
--------------------------------------------------------------------------------
/golang/basic/struct_test4.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type user struct {
8 | name string
9 | email string
10 | }
11 |
12 | func (u user) notify() {
13 | fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
14 | }
15 |
16 | func (u *user) changeEmail(email string) {
17 | u.email = email
18 | }
19 |
20 | func main() {
21 | bill := user{"Bill", "bill@email.com"}
22 | bill.notify()
23 | bill.changeEmail("bill@newdomain.com")
24 | bill.notify()
25 | }
26 |
--------------------------------------------------------------------------------
/golang/basic/type_test5.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | type IPAddr [4]byte
6 |
7 | // TODO: Add a "String() string" method to IPAddr.
8 | func (self IPAddr) String() string {
9 | return fmt.Sprintf("%d.%d.%d.%d", self[0], self[1], self[2], self[3])
10 | }
11 |
12 | func main() {
13 | hosts := map[string]IPAddr{
14 | "loopback": {127, 0, 0, 1},
15 | "googleDNS": {8, 8, 8, 8},
16 | }
17 | for name, ip := range hosts {
18 | fmt.Printf("%v: %v\n", name, ip)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/golang/clock_bench.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "time"
6 | )
7 |
8 | func main() {
9 | fmt.Println("Hello, World!")
10 | N := 10000000
11 | var sum int64 = 0
12 | ts := time.Now().UnixNano()
13 | for i := 0; i < N; i++ {
14 | sum += time.Now().UnixNano()
15 | }
16 | dt := time.Now().UnixNano() - ts
17 | ns := float64(dt) / float64(N)
18 | fmt.Printf("time=%d N=%d once=%0.3fns\n", dt, N, ns)
19 | fmt.Printf("end sum=%d\n", int(sum&0xff))
20 | }
21 |
--------------------------------------------------------------------------------
/golang/legacy/interface_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type notifier interface {
8 | notify()
9 | }
10 |
11 | type user struct {
12 | name string
13 | email string
14 | }
15 |
16 | func (u *user) notify() {
17 | fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
18 | }
19 |
20 | func main() {
21 | u := user{"Bill", "bill@email.com"}
22 | sendNotification(&u)
23 |
24 | }
25 |
26 | func sendNotification(n notifier) {
27 | n.notify()
28 | }
29 |
--------------------------------------------------------------------------------
/golang/legacy/bbuffer.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/gob"
6 | )
7 |
8 | func main() {
9 | m := map[string]string {
10 | "name": "lilei",
11 | "age": "24",
12 | }
13 | var b bytes.Buffer
14 | e := gob.NewEncoder(&b)
15 | e.Encode(m)
16 | println(len(b.Bytes()))
17 |
18 | nb := bytes.NewBuffer(b.Bytes())
19 | d := gob.NewDecoder(nb)
20 | var x map[string]string
21 | d.Decode(&x)
22 | println(x["name"], x["age"])
23 | }
24 |
25 |
26 |
--------------------------------------------------------------------------------
/haskell/qsort2.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | qsort ([], cmp) = []
3 | qsort (s:t, cmp) =
4 | qsort([x | x <- t, cmp(x, s) < 0], cmp) ++
5 | [s] ++
6 | [x | x <- t, cmp(x, s) == 0] ++
7 | qsort([x | x <- t, cmp(x, s) > 0], cmp)
8 |
9 | mycmp (x, y)
10 | | x < y = -1
11 | | x == y = 0
12 | | x > y = 1
13 |
14 | main = do
15 | print (qsort ([3, 1, 4, 1, 5, 9, 2, 6], mycmp))
16 | print 12345
17 |
18 |
19 |
--------------------------------------------------------------------------------
/elisp/dowhile.el:
--------------------------------------------------------------------------------
1 | (require 'cl)
2 |
3 | (setq x 0)
4 |
5 | (loop do
6 | (message "%d" x)
7 | (setq x (1+ x))
8 | while
9 | (< x 10))
10 |
11 | (setq z (loop with result = '()
12 | for i downfrom 10
13 | for j from 0 by 2
14 | while (< j 10)
15 | do
16 | (push (+ i j) result)
17 | finally
18 | return (nreverse result)))
19 |
20 | (message "%s" z)
21 |
22 | (message "square: %s" (loop for i in '(1 2 3 4 5 6)
23 | collect (* i i)))
24 |
25 |
26 |
--------------------------------------------------------------------------------
/haskell/reverse.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | reverse2 (s, e)
3 | | (length(s) == 0) = e
4 | | otherwise = reverse2(tail s, (head s):e)
5 |
6 | reverse3 s = (reverse2 (s, []))
7 |
8 | reverse4 ([], e) = e
9 | reverse4 (s:t, e) = reverse4(t, s:e)
10 |
11 | reverse5 s = reverse4(s, [])
12 |
13 | main = do
14 | print (reverse2 ([1,2,3,4], []))
15 | print (reverse3 [1,2,3,4])
16 | print (reverse5 [1,2,3,4])
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/ruby/roman.rb:
--------------------------------------------------------------------------------
1 | class Roman
2 | def self.method_missing name, *args
3 | roman = name.to_s
4 | roman.gsub!('IV', 'IIII')
5 | roman.gsub!('IX', 'VIIII')
6 | roman.gsub!('XL', 'XXXX')
7 | roman.gsub!('XC', 'LXXXX')
8 |
9 | (roman.count("I") +
10 | roman.count("V") * 5 +
11 | roman.count("X") * 10 +
12 | roman.count("L") * 50 +
13 | roman.count("C") * 100)
14 | end
15 | end
16 |
17 | puts Roman.X
18 | puts Roman.XC
19 | puts Roman.XII
20 | puts Roman.X
21 |
22 |
23 |
--------------------------------------------------------------------------------
/golang/basic/struct_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type user struct {
4 | name string
5 | email string
6 | ext int
7 | privileged bool
8 | }
9 |
10 | func (self *user) notify() {
11 | println("Sending user email to", self.name, self.email)
12 | }
13 |
14 | func main() {
15 | var bill user
16 | bill.ext = 10
17 | bill.name = "bill"
18 | bill.email = "bill@163.com"
19 | bill.notify()
20 | var b2 *user = new(user)
21 | b2.name = "zhj"
22 | b2.email = "zhj@163.com"
23 | b2.notify()
24 | }
25 |
--------------------------------------------------------------------------------
/haskell/cards.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | data Suit = Spades | Hearts deriving (Show)
3 | data Rank = Ten | Jack | Queen | King | Ace deriving (Show)
4 | type Card = (Rank, Suit)
5 | type Hand = [Card]
6 | value :: Rank -> Integer
7 | value Ten = 1
8 | value Jack = 2
9 | value Queen = 3
10 | value King = 4
11 | value Ace = 5
12 | cardValue :: Card -> Integer
13 | cardValue (rank, suit) = value rank
14 |
15 | main = do
16 | print "My types"
17 |
18 |
--------------------------------------------------------------------------------
/javascript/basic/object_boxing.js:
--------------------------------------------------------------------------------
1 |
2 | var s = 'test', n = 1, b = true;
3 |
4 | var S = new String(s);
5 | var N = new Number(n);
6 | var B = new Boolean(b);
7 |
8 | s.hello = 123;
9 | console.log(s.hello);
10 |
11 | S.hello = 123;
12 | console.log(S.hello);
13 |
14 | console.log(s == S, s === S, s === S.valueOf());
15 |
16 | console.log(typeof s);
17 | console.log(typeof S);
18 | console.log(Object.prototype.toString.apply(s));
19 | console.log(Object.prototype.toString.apply(S));
20 |
21 |
22 |
--------------------------------------------------------------------------------
/javascript/dom/dom-insert-pos.html:
--------------------------------------------------------------------------------
1 |
2 |
Java
3 |
Python
4 |
Scheme
5 |
6 |
7 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/golang/basic/interface_test9.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func do(i interface{}) {
6 | if i == nil {
7 | fmt.Printf("decode: obj is nil\n")
8 | } else {
9 | switch v := i.(type) {
10 | case int:
11 | fmt.Printf("Twice %v is %v\n", v, v*2)
12 | case string:
13 | fmt.Printf("%q is %v bytes long\n", v, len(v))
14 | default:
15 | fmt.Printf("I don't know about type %T!\n", v)
16 | }
17 | }
18 | }
19 |
20 | func main() {
21 | do(21)
22 | do("hello")
23 | do(true)
24 | do(nil)
25 | }
26 |
--------------------------------------------------------------------------------
/haskell/colormap.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 |
3 | colors = [0, 1, 2]
4 | possible = [(a, m, g, t, f) |
5 | a<-colors,
6 | m<-colors,
7 | g<-colors,
8 | t<-colors,
9 | f<-colors,
10 | m /= t,
11 | m /= a,
12 | a /= t,
13 | a /= m,
14 | a /= g,
15 | a /= f,
16 | g /= f,
17 | g /= t
18 | ]
19 |
20 | main = do
21 | putStrLn "maps"
22 | print possible
23 |
24 |
25 |
--------------------------------------------------------------------------------
/javascript/dom/dom-types.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 | hello
9 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/golang/basic/interface_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type notifier interface {
8 | notify()
9 | }
10 |
11 | type user struct {
12 | name string
13 | email string
14 | }
15 |
16 | func (u *user) notify() {
17 | fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
18 | }
19 |
20 | func main() {
21 | u := user{"Bill", "bill@email.com"}
22 |
23 | // must be converted pointer
24 | sendNotification(&u)
25 | }
26 |
27 | func sendNotification(n notifier) {
28 | n.notify()
29 | }
30 |
--------------------------------------------------------------------------------
/golang/basic/struct_test3.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type user struct {
8 | name string
9 | email string
10 | ext int
11 | privileged bool
12 | }
13 |
14 | type admin struct {
15 | person user
16 | level string
17 | }
18 |
19 | func main() {
20 | fred := admin{
21 | person: user{
22 | name: "Fred",
23 | email: "fred@email.com",
24 | ext: 123,
25 | privileged: true,
26 | },
27 | level: "super",
28 | }
29 | fmt.Println(fred)
30 | }
31 |
--------------------------------------------------------------------------------
/haskell/cards-with-show.hs:
--------------------------------------------------------------------------------
1 | module Main where
2 | data Suit = Spades | Hearts deriving (Show)
3 | data Rank = Ten | Jack | Queen | King | Ace deriving (Show)
4 | type Card = (Rank, Suit)
5 | type Hand = [Card]
6 | value :: Rank -> Integer
7 | value Ten = 1
8 | value Jack = 2
9 | value Queen = 3
10 | value King = 4
11 | value Ace = 5
12 | cardValue :: Card -> Integer
13 | cardValue (rank, suit) = value rank
14 |
15 | main = do
16 | print "My types"
17 |
18 |
--------------------------------------------------------------------------------
/golang/basic/slice_test4.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func printSlice(slice []int) {
8 | fmt.Printf("slice[%d/%d]: ", len(slice), cap(slice))
9 | for _, v := range slice {
10 | fmt.Printf("%d ", v)
11 | }
12 | fmt.Println()
13 | }
14 |
15 | func main() {
16 | slice := []int{10, 20, 30, 40, 50}
17 | newSlice := slice[1:3]
18 | printSlice(slice)
19 | printSlice(newSlice)
20 | newSlice2 := append(newSlice, 60)
21 | printSlice(slice)
22 | printSlice(newSlice)
23 | printSlice(newSlice2)
24 | }
25 |
--------------------------------------------------------------------------------
/golang/goroutine/goroutine_test4.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "runtime"
6 | "sync"
7 | )
8 |
9 | var (
10 | counter int
11 | wg sync.WaitGroup
12 | )
13 |
14 | func main() {
15 | wg.Add(2)
16 | go incCounter(1)
17 | go incCounter(2)
18 | wg.Wait()
19 | fmt.Println("Final Counter:", counter)
20 | }
21 |
22 | func incCounter(id int) {
23 | defer wg.Done()
24 | for count := 0; count < 2; count++ {
25 | value := counter
26 | runtime.Gosched()
27 | value++
28 | counter = value
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/golang/goroutine/goroutine_test5.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "runtime"
6 | "sync"
7 | "sync/atomic"
8 | )
9 |
10 | var (
11 | counter int64
12 | wg sync.WaitGroup
13 | )
14 |
15 | func main() {
16 | wg.Add(2)
17 | go incCounter(1)
18 | go incCounter(2)
19 | wg.Wait()
20 | fmt.Printf("Final Counter: %d\n", counter)
21 | }
22 |
23 | func incCounter(id int) {
24 | defer wg.Done()
25 | for count := 0; count < 2; count++ {
26 | atomic.AddInt64(&counter, 1)
27 | runtime.Gosched()
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/html/basic/css_selector2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
11 |
12 |
start
13 |
hahaha
14 |
15 | another b
16 |
17 |
18 |
19 | child.child
20 |
21 |
22 |
23 |
24 | hahaha
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/javascript/basic/async_promise.js:
--------------------------------------------------------------------------------
1 | function regularFunction() {
2 | const promise = asyncFunction();
3 | console.log(promise); // Promise {}
4 |
5 | // can't use await here, but can use .then
6 | promise.then(result => {
7 | console.log("Async result:", result);
8 | });
9 |
10 | console.log("This runs before async completes");
11 | }
12 |
13 | async function asyncFunction() {
14 | await new Promise(r => setTimeout(r, 1000));
15 | return "Done";
16 | }
17 |
18 | regularFunction();
19 |
20 |
21 |
--------------------------------------------------------------------------------
/javascript/basic/object_proto4.js:
--------------------------------------------------------------------------------
1 | function inherit(p) {
2 | if (p == null)
3 | throw TypeError();
4 | if (Object.create)
5 | return Object.create(p);
6 | var t = typeof(p);
7 | if (t != 'function' && t != 'object')
8 | throw TypeError();
9 | function f() {};
10 | f.prototype = p;
11 | return new f();
12 | }
13 |
14 | var unitcircle = { r:1 };
15 | var c = inherit(unitcircle);
16 |
17 | c.x = 1;
18 | c.y = 1;
19 | c.r = 2;
20 |
21 | console.log(c.r);
22 | console.log(unitcircle.r);
23 |
24 |
25 |
--------------------------------------------------------------------------------
/html/basic/component1.html:
--------------------------------------------------------------------------------
1 |
2 | haha
3 |
4 |
5 |
6 |
19 |
20 |
21 | think
22 |
23 |
24 | haha
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ruby/repeat.rb:
--------------------------------------------------------------------------------
1 |
2 | i = 0
3 | while i < 5
4 | puts "Hello #{i}"
5 | i += 1
6 | end
7 |
8 | for i in (0...5)
9 | puts "Hello #{i}"
10 | end
11 |
12 | for i in (0...5) do puts "FUCK #{i}"; end
13 |
14 | puts "SUCK #{i}" while (i += 1) < 10
15 |
16 | (0..9).each do
17 | |i|
18 | puts "each #{i}"
19 | end
20 |
21 | i = 3
22 | begin puts "haha #{i}" ; i += 1 end while (i < 7)
23 |
24 | while i < 10 do puts "fuck #{i}" ; i += 1 end
25 |
26 | (0...10).each {|i| puts i}
27 |
28 | 5.times { puts 'hahahaha' }
29 |
30 |
--------------------------------------------------------------------------------
/golang/fib_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | // fibonacci is a function that returns
6 | // a function that returns an int.
7 | func fibonacci() func() int {
8 | x := 0
9 | y := 0
10 | n := 0
11 | return func() int {
12 | z := 0
13 | if n == 0 {
14 | z = 0
15 | } else if n <= 2 {
16 | z = 1
17 | } else {
18 | z = x + y
19 | }
20 | x = y
21 | y = z
22 | n++
23 | return z
24 | }
25 | }
26 |
27 | func main() {
28 | f := fibonacci()
29 | for i := 0; i < 10; i++ {
30 | fmt.Println(f())
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/javascript/basic/object_proto1.js:
--------------------------------------------------------------------------------
1 | const Person = {
2 | isHuman: false,
3 | printIntroduction: function () {
4 | console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
5 | }
6 | }
7 |
8 | Person.printIntroduction();
9 |
10 | console.log(Person);
11 |
12 | const me = Object.create(Person);
13 |
14 | me.name = 'Matthew';
15 | me.isHuman = true;
16 |
17 | me.printIntroduction();
18 |
19 | console.log(me.__proto__);
20 |
21 | console.log(Object);
22 | console.log(Person.printIntroduction);
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/javascript/dom/dom-insert-style.html:
--------------------------------------------------------------------------------
1 | JavaScript
2 |
3 |
Java
4 |
Python
5 |
Scheme
6 |
7 |
8 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/golang/basic/interface_test7.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "math"
6 | )
7 |
8 | type I interface {
9 | M()
10 | }
11 |
12 | type T struct {
13 | S string
14 | }
15 |
16 | func (t *T) M() {
17 | fmt.Println(t.S)
18 | }
19 |
20 | type F float64
21 |
22 | func (f F) M() {
23 | fmt.Println(f)
24 | }
25 |
26 | func main() {
27 | var i I
28 |
29 | i = &T{"Hello"}
30 | describe(i)
31 | i.M()
32 |
33 | i = F(math.Pi)
34 | describe(i)
35 | i.M()
36 | }
37 |
38 | func describe(i I) {
39 | fmt.Printf("(%v, %T)\n", i, i)
40 | }
41 |
--------------------------------------------------------------------------------
/javascript/basic/object_proto3.js:
--------------------------------------------------------------------------------
1 | function inherit(p) {
2 | if (p == null)
3 | throw TypeError();
4 | if (Object.create)
5 | return Object.create(p);
6 | var t = typeof(p);
7 | if (t != 'function' && t != 'object')
8 | throw TypeError();
9 | function f() {};
10 | f.prototype = p;
11 | return new f();
12 | }
13 |
14 | var o = {};
15 | o.x = 1;
16 |
17 | var p = inherit(o);
18 | p.y = 2;
19 |
20 | var q = inherit(p);
21 | q.z = 3;
22 |
23 | var s = q.toString();
24 |
25 | console.log(q.x + q.y);
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/html/basic/component2.html:
--------------------------------------------------------------------------------
1 |
2 | haha
3 |
4 |
5 |
6 |
18 |
19 |
20 | think
21 |
22 |
23 | haha
24 |
25 |
26 |
--------------------------------------------------------------------------------
/scala/employee.scala:
--------------------------------------------------------------------------------
1 | class Person(val name:String) {
2 | def talk(message: String) = println(name + " says " + message)
3 | def id(): String = name
4 | }
5 |
6 | class Employee(override val name: String,
7 | val number: Int) extends Person(name) {
8 | override def talk(message: String) {
9 | println(name + " with number " + number + " says " + message)
10 | }
11 | override def id(): String = number.toString
12 | }
13 |
14 | val employee = new Employee("Yoda", 4)
15 | employee.talk("Extend or extend not. There is no try.")
16 |
17 |
18 |
--------------------------------------------------------------------------------
/javascript/tools/monitor.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/prolog/map.pro:
--------------------------------------------------------------------------------
1 | different(red, green).
2 | different(red, blue).
3 | different(green, red).
4 | different(green, blue).
5 | different(blue, red).
6 | different(blue, green).
7 |
8 | coloring(Alabama, Mississippi, Georgia, Tennessee, Florida) :-
9 | different(Mississippi, Tennessee),
10 | different(Mississippi, Alabama),
11 | different(Alabama, Tennessee),
12 | different(Alabama, Mississippi),
13 | different(Alabama, Georgia),
14 | different(Alabama, Florida),
15 | different(Georgia, Florida),
16 | different(Georgia, Tennessee).
17 |
18 |
19 |
--------------------------------------------------------------------------------
/html/basic/layout_position1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 |
13 | test1
14 |
15 | test2
16 |
test3
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/golang/basic/embed_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type user struct {
8 | name string
9 | email string
10 | }
11 |
12 | func (u *user) notify() {
13 | fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
14 | }
15 |
16 | type admin struct {
17 | user
18 | level string
19 | }
20 |
21 | func main() {
22 | ad := admin{
23 | user: user{
24 | name: "John Smith",
25 | email: "john@email.com",
26 | },
27 | level: "super",
28 | }
29 | fmt.Printf("The name is %s\n", ad.name)
30 | ad.user.notify()
31 | ad.notify()
32 | }
33 |
--------------------------------------------------------------------------------
/iolang/phonebook.io:
--------------------------------------------------------------------------------
1 | OperatorTable addAssignOperator(":", "atPutNumber")
2 |
3 | curlyBrackets := method(
4 | r := Map clone
5 | call message arguments foreach(arg,
6 | r doMessage(arg)
7 | )
8 | r
9 | )
10 |
11 | Map atPutNumber := method(
12 | self atPut(
13 | call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\""),
14 | call evalArgAt(1))
15 | )
16 |
17 | s := File with("phonebook.txt") openForReading contents
18 | phoneNumbers := doString(s)
19 | phoneNumbers keys println
20 | phoneNumbers values println
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/iolang/animals.io:
--------------------------------------------------------------------------------
1 | Object ancestors := method(
2 | prototype := self proto
3 | if (prototype != Object,
4 | writeln("Slots of ", prototype type, "\n-------------")
5 | prototype slotNames foreach(slotName, writeln(slotName))
6 | writeln
7 | prototype ancestors))
8 |
9 | Animal := Object clone
10 | Animal speak := method(
11 | "ambiguous animal noise" println)
12 |
13 | Duck := Animal clone
14 | Duck speak := method(
15 | "quack" println)
16 | Duck walk := method(
17 | "waddle" println)
18 |
19 | disco := Duck clone
20 | disco ancestors
21 |
22 |
--------------------------------------------------------------------------------
/golang/basic/func_test1.go:
--------------------------------------------------------------------------------
1 | // =====================================================================
2 | //
3 | // func_test1.go -
4 | //
5 | // Created by skywind on 2024/06/26
6 | // Last Modified: 2024/06/26 17:17:37
7 | //
8 | // =====================================================================
9 | package main
10 |
11 | var fn func(int, int) int = nil
12 |
13 | func add(a, b int) int {
14 | return a + b
15 | }
16 |
17 | func sub(a, b int) int {
18 | return a - b
19 | }
20 |
21 | func main() {
22 | fn = add
23 | println(fn(1, 2))
24 | fn = sub
25 | println(fn(1, 2))
26 | }
27 |
--------------------------------------------------------------------------------
/golang/basic/slice_test5.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func printSlice(slice []int) {
8 | fmt.Printf("slice[%d/%d]: ", len(slice), cap(slice))
9 | for _, v := range slice {
10 | fmt.Printf("%d ", v)
11 | }
12 | fmt.Println()
13 | }
14 |
15 | func main() {
16 | slice := []int{10, 20, 30, 40, 50}
17 | printSlice(slice)
18 | newSlice := slice[1:2:3]
19 | s1 := append(newSlice, 60)
20 | s2 := append(s1, 70)
21 | println()
22 | printSlice(slice)
23 | printSlice(newSlice)
24 | printSlice(s1)
25 | printSlice(s2)
26 | fmt.Printf("slice: %v\n", slice)
27 | }
28 |
--------------------------------------------------------------------------------
/golang/legacy/test_rune.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "reflect"
6 | )
7 |
8 | func main() {
9 | // Creating runes
10 | rune1 := 'B'
11 | rune2 := 'g'
12 | rune3 := '\a'
13 |
14 | // Displaying rune and its type
15 | fmt.Printf("Rune 1: %c; Unicode: %U; Type: %s\n", rune1, rune1, reflect.TypeOf(rune1))
16 | fmt.Printf("Rune 2: %c; Unicode: %U; Type: %s\n", rune2, rune2, reflect.TypeOf(rune2))
17 | fmt.Printf("Rune 3: Unicode: %U; Type: %s\n", rune3, reflect.TypeOf(rune3))
18 | fmt.Printf("Hello\n");
19 | }
20 |
21 |
22 |
--------------------------------------------------------------------------------
/golang/goroutine/goroutine_test7.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "runtime"
6 | "sync"
7 | )
8 |
9 | var (
10 | counter int
11 | wg sync.WaitGroup
12 | mutex sync.Mutex
13 | )
14 |
15 | func main() {
16 | wg.Add(2)
17 | go incCounter(1)
18 | go incCounter(2)
19 | wg.Wait()
20 | fmt.Println("Final Counter:", counter)
21 | }
22 |
23 | func incCounter(id int) {
24 | defer wg.Done()
25 | for count := 0; count < 2; count++ {
26 | mutex.Lock()
27 | value := counter
28 | runtime.Gosched()
29 | value++
30 | counter = value
31 | mutex.Unlock()
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ruby/acts_as_csv_class.rb:
--------------------------------------------------------------------------------
1 | class ActsAsCsv
2 | def read
3 | file = File.new(self.class.to_s.downcase + '.txt')
4 | @headers = file.gets.chomp.split(', ')
5 |
6 | file.each do |row|
7 | @result << row.chomp.split(', ')
8 | end
9 | end
10 |
11 | def headers
12 | @headers
13 | end
14 |
15 | def csv_contents
16 | @result
17 | end
18 |
19 | def initialize
20 | @result = []
21 | read
22 | end
23 | end
24 |
25 | class RubyCsv < ActsAsCsv
26 | end
27 |
28 | m = RubyCsv.new
29 | puts m.headers.inspect
30 | puts m.csv_contents.inspect
31 |
32 |
33 |
--------------------------------------------------------------------------------
/golang/image_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "image"
5 | "image/color"
6 |
7 | "golang.org/x/tour/pic"
8 | )
9 |
10 | type Image struct {
11 | w int
12 | h int
13 | }
14 |
15 | func (self *Image) ColorModel() color.Model {
16 | return color.RGBAModel
17 | }
18 |
19 | func (self *Image) Bounds() image.Rectangle {
20 | return image.Rect(0, 0, self.w, self.h)
21 | }
22 |
23 | func (self *Image) At(x int, y int) color.Color {
24 | c := x ^ y
25 | v := byte(c)
26 | return color.RGBA{v, v, 255, 255}
27 | }
28 |
29 | func main() {
30 | m := Image{256, 256}
31 | pic.ShowImage(&m)
32 | }
33 |
--------------------------------------------------------------------------------
/ruby/class1.rb:
--------------------------------------------------------------------------------
1 |
2 | class Car
3 | def initialize(number)
4 | @number = number
5 | end
6 |
7 | def inc
8 | @number += 1
9 | end
10 | end
11 |
12 | class Bike
13 | def initialize(number)
14 | self.num = number
15 | end
16 | def inc
17 | self.num += 1
18 | end
19 | end
20 |
21 | c1 = Car.new(10)
22 | c2 = Car.new(50)
23 |
24 | puts c1.inc
25 | puts c1.inc
26 | puts c2.inc
27 | puts c1.inc
28 | puts c1.inc
29 | puts c2.inc
30 |
31 | puts '-' * 72
32 | b1 = Bike.new(20)
33 | b2 = Bike.new(60)
34 | puts b1.inc
35 | puts b1.inc
36 | puts b2.inc
37 | puts b1.inc
38 |
--------------------------------------------------------------------------------
/golang/basic/array_test5.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "reflect"
6 | )
7 |
8 | func isSliceOrArray(x interface{}) string {
9 | t := reflect.TypeOf(x)
10 | switch t.Kind() {
11 | case reflect.Slice:
12 | return "Slice"
13 | case reflect.Array:
14 | return "Array"
15 | default:
16 | return "not a slice or an array"
17 | }
18 | }
19 |
20 | func main() {
21 | a := [...]int{1, 2, 3, 4, 5}
22 | fmt.Println(a)
23 | var b []int = a[:]
24 | fmt.Println(b)
25 | fmt.Println(isSliceOrArray(a))
26 | fmt.Println(isSliceOrArray(b))
27 | c := a[1:3]
28 | c[1] = 5
29 | fmt.Println(a)
30 | }
31 |
--------------------------------------------------------------------------------
/html/basic/css_selector1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
14 |
15 |
16 |
17 | h1
18 | h2 inline h3
19 | h3
20 | h4
21 |
22 | hahaha
23 |
24 | another b
25 |
26 |
27 | h1
28 | h2 inline h3
29 | h3
30 | h4
31 | hahaha
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/golang/basic/embed_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type user struct {
8 | name string
9 | email string
10 | }
11 |
12 | func (u *user) notify() {
13 | fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
14 | }
15 |
16 | type admin struct {
17 | user
18 | level string
19 | name string
20 | }
21 |
22 | func main() {
23 | ad := admin{
24 | user: user{
25 | name: "John Smith",
26 | email: "john@email.com",
27 | },
28 | level: "super",
29 | name: "Lisa",
30 | }
31 | fmt.Printf("The name is %s\n", ad.name)
32 | ad.user.notify()
33 | ad.notify()
34 | }
35 |
--------------------------------------------------------------------------------
/html/basic/layout_position2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 |
13 | test1
14 |
15 | test2
16 |
test3
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/golang/basic/slice_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func printSlice(x []int) {
8 | fmt.Printf("slice[%d/%d]: ", len(x), cap(x))
9 | for i := 0; i < len(x); i++ {
10 | fmt.Printf("%d ", x[i])
11 | }
12 | fmt.Println("")
13 | }
14 |
15 | func main() {
16 | fmt.Println("Hello, World!")
17 | a := []int{0}
18 | a = append(a, 1, 2, 3)
19 | printSlice(a)
20 | println(cap(a))
21 | println(len(a))
22 | a[2] = 200
23 | printSlice(a)
24 | b := a[1:3]
25 | printSlice(b)
26 | c := b[0:3]
27 | printSlice(c)
28 | d := a[0:1]
29 | e := d[3:4]
30 | printSlice(d)
31 | printSlice(e)
32 | }
33 |
--------------------------------------------------------------------------------
/golang/basic/struct_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | type user struct {
4 | name string
5 | email string
6 | ext int
7 | privileged bool
8 | }
9 |
10 | func (self *user) notify() {
11 | println("Sending user email to", self.name, self.email)
12 | }
13 |
14 | func newUser(name string) *user {
15 | var nu user
16 | nu.name = name
17 | return &nu
18 | }
19 |
20 | func main() {
21 | var n1 *user = newUser("user1")
22 | var n2 *user = newUser("user2")
23 | n1.notify()
24 | n2.notify()
25 | }
26 |
27 | /*
28 | output:
29 |
30 | Sending user email to user1
31 | Sending user email to user2
32 | */
33 |
--------------------------------------------------------------------------------
/html/basic/layout_position3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 |
13 | test1
14 |
15 | test2
16 |
test3
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/javascript/basic/function_flexsum.js:
--------------------------------------------------------------------------------
1 |
2 | function flexsum() {
3 | var total = 0;
4 | for (var i = 0; i < arguments.length; i++) {
5 | var element = arguments[i];
6 | var n = 0;
7 | if (element == null) continue;
8 | else if (Array.isArray(element)) {
9 | n = flexsum.apply(this, element);
10 | }
11 | else if (typeof element === 'function') {
12 | n = Number(element());
13 | }
14 | else if (isFinite(element)) {
15 | n = Number(element);
16 | }
17 | total += n;
18 | }
19 | return total;
20 | }
21 |
22 |
23 | console.log(flexsum([1, 2, 3], 4, 5, [6, 7]));
24 |
25 |
26 |
--------------------------------------------------------------------------------
/ruby/namespace.rb:
--------------------------------------------------------------------------------
1 | class M1
2 | def self.test
3 | puts "M1.test"
4 | end
5 | end
6 |
7 | class M2
8 | class << M2
9 | def test
10 | puts "M2.test"
11 | end
12 | end
13 | end
14 |
15 | module M3
16 | module MM
17 | def self.test
18 | puts "M3.MM.test"
19 | end
20 | end
21 | end
22 |
23 | module M4
24 | def self.test
25 | puts "M4.test"
26 | end
27 |
28 | def M4.test2
29 | puts "M4.test2"
30 | end
31 | end
32 |
33 |
34 | M1.test
35 | M2.test
36 |
37 | M3::MM::test
38 | M3::MM.test
39 |
40 | M4.test
41 | M4::test
42 | M4.test2
43 | M4::test2
44 |
45 |
46 |
--------------------------------------------------------------------------------
/html/basic/layout_position4.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 |
13 | test1
14 |
15 | test2
16 |
test3
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/html/basic/layout_table1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
11 |
12 |
13 |
14 | | test1 |
15 | test2 |
16 | test3 |
17 |
18 |
19 | | test1 |
20 | haha |
21 | test3 |
22 |
23 |
24 | | test1 |
25 | test2 |
26 | test3 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/golang/basic/map_test3.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | colors := map[string]string{
9 | "AliceBlue": "#f0f8ff",
10 | "Coral": "#ff7f50",
11 | "DarkGray": "#a9a9a9",
12 | "ForestGreen": "#228b22",
13 | }
14 |
15 | for key, value := range colors {
16 | fmt.Printf("Key: %s Value: %s\n", key, value)
17 | }
18 |
19 | removeColor(colors, "Coral")
20 | println()
21 |
22 | for key, value := range colors {
23 | fmt.Printf("Key: %s Value: %s\n", key, value)
24 | }
25 | }
26 |
27 | func removeColor(colors map[string]string, key string) {
28 | delete(colors, key)
29 | }
30 |
--------------------------------------------------------------------------------
/javascript/basic/closure_set.js:
--------------------------------------------------------------------------------
1 |
2 | function addPrivateProperty(o, name, predicate) {
3 | var value;
4 | o['get' + name] = function() { return value; };
5 | o['set' + name] = function(v) {
6 | if (predicate && !predicate(v))
7 | throw Error('set' + name + ':invalid value ' + v);
8 | else
9 | value = v;
10 | };
11 | }
12 |
13 | var o = {}
14 |
15 | addPrivateProperty(o, 'Name', function (x) {
16 | return typeof x == 'string'; });
17 |
18 | o.setName('Frank');
19 | console.log(o.getName());
20 |
21 | try {
22 | o.setName(0);
23 | }
24 | catch {
25 | console.log('error here');
26 | }
27 |
28 |
29 |
--------------------------------------------------------------------------------
/erlang/temperature.erl:
--------------------------------------------------------------------------------
1 | -module(temperature).
2 | -export([format_temps/1, main/1]).
3 |
4 |
5 | format_temps([]) ->
6 | ok;
7 | format_temps([City | Rest]) ->
8 | print_temp(convert_to_celsius(City)),
9 | format_temps(Rest).
10 |
11 |
12 | convert_to_celsius({Name, {c, Temp}}) ->
13 | {Name, {c, Temp}};
14 | convert_to_celsius({Name, {f, Temp}}) ->
15 | {Name, {c, (Temp - 32) * 5 / 9}}.
16 |
17 | print_temp({Name, {c, Temp}}) ->
18 | io:format("~-15w ~w c~n", [Name, Temp]).
19 |
20 |
21 | main(_) ->
22 | T = [{moscow, {c, -10}}, {cape_tow, {f,70}},{stockholm,{c,-4}}],
23 | format_temps(T),
24 | ok.
25 |
26 |
27 |
--------------------------------------------------------------------------------
/haskell/bmi.hs:
--------------------------------------------------------------------------------
1 | bmiTell :: (RealFloat a) => a -> a -> String
2 |
3 | bmiTell weight height
4 | | bmi <= skinny = "You're underweight, you emo, you!"
5 | | bmi <= normal = "You're supposedly normal. Pffft, I bet you're ugly!"
6 | | bmi <= fat = "You're fat! Lose some weight, fatty!"
7 | | otherwise = "You're a whale, congratulations!"
8 | where bmi = weight / height ^ 2
9 | skinny = 18.5
10 | normal = 25.0
11 | fat = 30.0
12 |
13 | calcBmis :: (RealFloat a) => [(a, a)] -> [a]
14 | calcBmis xs = [bmi w h | (w, h) <- xs]
15 | where bmi weight height = weight / height ^ 2
16 |
17 |
18 |
--------------------------------------------------------------------------------
/golang/basic/interface_test4.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type notifier interface {
8 | notify()
9 | }
10 |
11 | type user struct {
12 | name string
13 | email string
14 | }
15 |
16 | func (u *user) notify() {
17 | fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
18 | }
19 |
20 | type admin struct {
21 | user
22 | level string
23 | }
24 |
25 | func main() {
26 | ad := admin{
27 | user: user{
28 | name: "John Smith",
29 | email: "john@email.com",
30 | },
31 | level: "super",
32 | }
33 | sendNotification(&ad)
34 | }
35 |
36 | func sendNotification(n notifier) {
37 | n.notify()
38 | }
39 |
--------------------------------------------------------------------------------
/javascript/basic/object_inherit.js:
--------------------------------------------------------------------------------
1 | function inherit(p) {
2 | if (p == null)
3 | throw TypeError();
4 | if (Object.create)
5 | return Object.create(p);
6 | var t = typeof(p);
7 | if (t != 'function' && t != 'object')
8 | throw TypeError();
9 | function f() {};
10 | f.prototype = p;
11 | return new f();
12 | }
13 |
14 | var o = inherit({y:2});
15 |
16 | o.x = 1;
17 |
18 | console.log(Object.keys(o));
19 |
20 | console.log(o.propertyIsEnumerable('x'));
21 | console.log(o.propertyIsEnumerable('y'));
22 | console.log(o.propertyIsEnumerable('toString'));
23 |
24 | for (var v in o) {
25 | console.log(v);
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/golang/goroutine/channel_test4.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "time"
6 | )
7 |
8 | func scale(x int) int {
9 | return x * 2
10 | }
11 |
12 | var fn func(int) int = scale
13 |
14 | func main() {
15 | fmt.Println(time.Now().UnixNano())
16 | x := 10
17 |
18 | t1 := time.Now().UnixNano()
19 | y := fn(x)
20 | t1 = time.Now().UnixNano() - t1
21 |
22 | fmt.Println(y, t1)
23 | ch1 := make(chan int)
24 | ch2 := make(chan int)
25 | t2 := time.Now().UnixNano()
26 | go func() {
27 | s := <-ch1
28 | t := fn(s)
29 | ch2 <- t
30 | }()
31 | ch1 <- x
32 | z := <-ch2
33 | t2 = time.Now().UnixNano() - t2
34 | fmt.Println(z, t2)
35 | }
36 |
--------------------------------------------------------------------------------
/data/win.ini:
--------------------------------------------------------------------------------
1 | ; for 16-bit app support
2 | [fonts]
3 | [extensions]
4 | [mci extensions]
5 | [files]
6 | [Mail]
7 | MAPI=1
8 | CMCDLLNAME32=mapi32.dll
9 | CMC=1
10 | MAPIX=1
11 | MAPIXVER=1.0.0.1
12 | OLEMessaging=1
13 | [MCI Extensions.BAK]
14 | 3g2=MPEGVideo
15 | 3gp=MPEGVideo
16 | 3gp2=MPEGVideo
17 | 3gpp=MPEGVideo
18 | aac=MPEGVideo
19 | adt=MPEGVideo
20 | adts=MPEGVideo
21 | m2t=MPEGVideo
22 | m2ts=MPEGVideo
23 | m2v=MPEGVideo
24 | m4a=MPEGVideo
25 | m4v=MPEGVideo
26 | mod=MPEGVideo
27 | mov=MPEGVideo
28 | mp4=MPEGVideo
29 | mp4v=MPEGVideo
30 | mts=MPEGVideo
31 | ts=MPEGVideo
32 | tts=MPEGVideo
33 | [Aliim]
34 | ImageManClear=1
35 |
--------------------------------------------------------------------------------
/scheme/lesson4.scm:
--------------------------------------------------------------------------------
1 | (define x 100)
2 | (set! x 10)
3 | (display x)
4 | (newline)
5 | (begin
6 | (set! x 200)
7 | (display x)
8 | (newline)
9 | )
10 | (display x)
11 | (newline)
12 |
13 |
14 | (define add2
15 | (lambda (x y) (begin
16 | (set! x (+ x y))
17 | (display "FUCK")
18 | (newline)
19 | x
20 | )))
21 |
22 | (define x 100)
23 | (define y 200)
24 | (display (add2 x y))
25 | (newline)
26 | (display x)
27 | (newline)
28 |
29 |
30 | (define add2 (
31 | lambda (x)
32 | (set! x (+ x 2))
33 | x
34 | )
35 | )
36 |
37 | (display (add2 x))
38 | (newline)
39 | (display x)
40 | (newline)
41 |
42 |
43 |
--------------------------------------------------------------------------------
/javascript/basic/class_range2.js:
--------------------------------------------------------------------------------
1 |
2 | function Range(from, to) {
3 | this.from = from;
4 | this.to = to;
5 | }
6 |
7 | Range.prototype = {
8 | includes: function (x) {
9 | return this.from <= x && x <= this.to;
10 | },
11 | foreach: function (f) {
12 | for (var x = Math.ceil(this.from); x <= this.to; x++)
13 | f(x);
14 | },
15 | toString: function () {
16 | return"(" + this.from + "..." + this.to + ")";
17 | },
18 | };
19 |
20 | var r = new Range(1, 3);
21 |
22 | console.log(r.includes(2));
23 | r.foreach(console.log);
24 | console.log(r);
25 |
26 | console.log(typeof r);
27 |
28 | console.log(r instanceof Range);
29 |
30 |
--------------------------------------------------------------------------------
/ruby/visitor.rb:
--------------------------------------------------------------------------------
1 | class Tree
2 | attr_accessor :children, :node_name
3 |
4 | def initialize(name, children = [])
5 | @children = children
6 | @node_name = name
7 | end
8 |
9 | def visit_all(&block)
10 | visit &block
11 | children.each {|c| c.visit_all &block}
12 | end
13 |
14 | def visit(&block)
15 | block.call self
16 | end
17 | end
18 |
19 |
20 | ruby_tree = Tree.new("Ruby", [Tree.new("Reia"), Tree.new("MacRuby")])
21 |
22 | puts "Visiting a node"
23 | ruby_tree.visit {|node| puts node.node_name}
24 | puts
25 |
26 | puts "visiting entire tree"
27 | ruby_tree.visit_all {|node| puts node.node_name}
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/golang/basic/type_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type IP []byte
8 |
9 | func (ip IP) String() string {
10 | if len(ip) != 4 {
11 | return "Error IP"
12 | }
13 | return fmt.Sprintf("%v.%v.%v.%v", ip[0], ip[1], ip[2], ip[3])
14 | }
15 |
16 | func (ip IP) Add() {
17 | ip[3] += 1
18 | }
19 |
20 | func main() {
21 | var ip1 IP = []byte{192, 168, 1, 1}
22 | fmt.Println(ip1.String())
23 | ip1 = []byte{192, 168, 1, 3}
24 | fmt.Println(ip1.String())
25 | var ip2 IP = ip1
26 | ip2[3] = 4
27 | fmt.Println(ip1.String())
28 | fmt.Println(ip2.String())
29 | ip2.Add()
30 | fmt.Println(ip1.String())
31 | fmt.Println(ip2.String())
32 | }
33 |
--------------------------------------------------------------------------------
/scala/kids.scala:
--------------------------------------------------------------------------------
1 |
2 |
3 | import scala.actors._
4 | import scala.actors.Actor._
5 |
6 | case object Poke
7 | case object Feed
8 |
9 | class Kid() extends Actor {
10 | def act {
11 | loop {
12 | react {
13 | case Poke => {
14 | println("Ow...")
15 | println("Quit it ...")
16 | }
17 | case Feed => {
18 | println("Gurgle...")
19 | println("Burp...")
20 | }
21 | }
22 | }
23 | }
24 | }
25 |
26 |
27 | val bart = (new Kid()).start
28 | val lisa = (new Kid()).start
29 |
30 | println("Ready to poke and feed...")
31 |
32 | bart ! Poke
33 | lisa ! Poke
34 | bart ! Feed
35 | lisa ! Feed
36 |
37 |
38 |
--------------------------------------------------------------------------------
/html/basic/layout_table3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | | 左边列 |
22 | 右边列 |
23 |
24 |
25 |
26 |
27 | | 内容1 |
28 | 内容2 |
29 |
30 |
31 | | 内容3 |
32 | 内容4 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/erlang/listdemo.erl:
--------------------------------------------------------------------------------
1 | -module(listdemo).
2 | -export([main/1, getvalue/2, getvalue2/2]).
3 |
4 |
5 | getvalue([], _) -> [];
6 | getvalue([H|L], K) ->
7 | {Key, Value} = H,
8 | if
9 | Key == K ->
10 | [Value|getvalue(L, K)];
11 | true ->
12 | getvalue(L, K)
13 | end.
14 |
15 | getvalue2([], _) -> [];
16 | getvalue2([{K, Value}|L], K) ->
17 | [Value|getvalue2(L, K)];
18 | getvalue2([{_, _}|L], K) ->
19 | getvalue2(L, K).
20 |
21 |
22 | main(_) ->
23 | X = [{erlang, "a functional language"}, {ruby, "an OO language"}],
24 | Y = getvalue2(X, erlang),
25 | Z = getvalue2(X, ruby),
26 | io:format("~p~n", [Y]),
27 | io:format("~p~n", [Z]),
28 | ok.
29 |
30 |
31 |
--------------------------------------------------------------------------------
/golang/basic/interface_test8.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | type I interface {
6 | M()
7 | }
8 |
9 | type T struct {
10 | S string
11 | }
12 |
13 | func (t *T) M() {
14 | if t == nil {
15 | fmt.Println("")
16 | return
17 | }
18 | fmt.Println(t.S)
19 | }
20 |
21 | func main() {
22 | var i I
23 |
24 | var t *T
25 | i = t
26 | describe(i)
27 | i.M()
28 |
29 | i = &T{"hello"}
30 | describe(i)
31 | i.M()
32 |
33 | fmt.Println()
34 | i = nil
35 | describe(i)
36 |
37 | t = nil
38 | i = t
39 | describe(i)
40 | }
41 |
42 | func describe(i I) {
43 | t := "not nil"
44 | if i == nil {
45 | t = "is nil"
46 | }
47 | fmt.Printf("(%v, %T) %s\n", i, i, t)
48 | }
49 |
--------------------------------------------------------------------------------
/golang/legacy/slice_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 |
6 | func displaySlice(x []int) {
7 | fmt.Printf("slice cap=%d len=%d: %s\n", cap(x), len(x), x)
8 | }
9 |
10 | func main() {
11 | a := []int{1, 2, 3}
12 | b := append(a, 4)
13 | c := b[:3]
14 | d := append(c, 5)
15 | displaySlice(a)
16 | displaySlice(b)
17 | displaySlice(c)
18 | displaySlice(d)
19 | }
20 |
21 | // Output:
22 | // slice cap=3 len=3: [%!s(int=1) %!s(int=2) %!s(int=3)]
23 | // slice cap=6 len=4: [%!s(int=1) %!s(int=2) %!s(int=3) %!s(int=5)]
24 | // slice cap=6 len=3: [%!s(int=1) %!s(int=2) %!s(int=3)]
25 | // slice cap=6 len=4: [%!s(int=1) %!s(int=2) %!s(int=3) %!s(int=5)]
26 |
27 |
--------------------------------------------------------------------------------
/iolang/matrix.io:
--------------------------------------------------------------------------------
1 |
2 | Matrix := List clone
3 |
4 | Matrix dim := method(x, y,
5 | m := Matrix clone
6 | z := 0
7 | fuck := 3
8 | for (i, 0, y - 1,
9 | n := list()
10 | for (j, 0, x - 1, n append(0))
11 | m append(n))
12 | m row := y
13 | m col := x
14 | m)
15 |
16 |
17 | Matrix get := method(x, y, (self at(y)) at(x))
18 | Matrix set := method(x, y, z, (self at(y)) atPut(x, z))
19 |
20 | m := Matrix dim(4, 4)
21 | n := Matrix dim(2, 2)
22 |
23 |
24 | m set(0, 1, 1)
25 | m set(1, 0, 3)
26 | m set(0, 3, 8)
27 | m set(2, 2, 6)
28 | m set(3, 0, 9)
29 | n set(1, 0, 99)
30 | n set(0, 1, 3)
31 |
32 | m println
33 | n println
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/python/coecho1.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 |
3 | async def handle_echo(reader, writer):
4 | while 1:
5 | data = await reader.read(100)
6 | writer.write(data)
7 | await writer.drain()
8 | print('received %d bytes'%len(data))
9 | if data.strip() == b'exit':
10 | break
11 | writer.close()
12 | return 0
13 |
14 |
15 | async def main():
16 | server = await asyncio.start_server(
17 | handle_echo, '0.0.0.0', 8888)
18 |
19 | addr = server.sockets[0].getsockname()
20 | print(f"Serving on {addr}")
21 |
22 | # async with server:
23 | await server.serve_forever()
24 |
25 | return 0
26 |
27 | asyncio.run(main())
28 |
29 |
30 |
--------------------------------------------------------------------------------
/ruby/acts_as_csv.rb:
--------------------------------------------------------------------------------
1 | class ActsAsCsv
2 | def self.acts_as_csv
3 | define_method 'read' do
4 | file = File.new(self.class.to_s.downcase + '.txt')
5 | @headers = file.gets.chomp.split(', ')
6 | file.each do |row|
7 | @result << row.chomp.split(', ')
8 | end
9 | end
10 |
11 | define_method "headers" do
12 | @headers
13 | end
14 |
15 | define_method "csv_contents" do
16 | @result
17 | end
18 |
19 | define_method "initialize" do
20 | @result = []
21 | read
22 | end
23 | end
24 | end
25 |
26 | class RubyCsv < ActsAsCsv
27 | acts_as_csv
28 | end
29 |
30 | m = RubyCsv.new
31 | puts m.headers.inspect
32 | puts m.csv_contents.inspect
33 |
34 |
--------------------------------------------------------------------------------
/golang/goroutine/goroutine_test6.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "sync"
6 | "sync/atomic"
7 | "time"
8 | )
9 |
10 | var (
11 | shutdown int64
12 | wg sync.WaitGroup
13 | )
14 |
15 | func main() {
16 | wg.Add(2)
17 | go doWork("A")
18 | go doWork("B")
19 | time.Sleep(1 * time.Second)
20 | fmt.Println("Shutdown Now")
21 | atomic.StoreInt64(&shutdown, 1)
22 | wg.Wait()
23 | fmt.Println("Done")
24 | }
25 |
26 | func doWork(name string) {
27 | defer wg.Done()
28 | for {
29 | fmt.Printf("Doing %s Work\n", name)
30 | time.Sleep(250 * time.Millisecond)
31 | if atomic.LoadInt64(&shutdown) == 1 {
32 | fmt.Printf("Shutting %s Down\n", name)
33 | break
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/golang/lib/udp_timeout.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "net"
6 | "time"
7 | )
8 |
9 | func main() {
10 | conn, err := net.DialUDP("udp", nil, &net.UDPAddr{Port: 12345})
11 | if err != nil {
12 | fmt.Println(err)
13 | return
14 | }
15 | go func() {
16 | buf := make([]byte, 65536)
17 | fmt.Println("Reading from UDP")
18 | n, err := conn.Read(buf)
19 | if err != nil {
20 | fmt.Println(err)
21 | } else {
22 | fmt.Println("Received:", string(buf[:n]))
23 | }
24 | fmt.Println("Closing connection")
25 | }()
26 | time.Sleep(1 * time.Second)
27 | conn.SetReadDeadline(time.Now().Add(2 * time.Second))
28 | fmt.Println("Deadline set")
29 | time.Sleep(1000 * time.Second)
30 | }
31 |
--------------------------------------------------------------------------------
/iolang/xml1.io:
--------------------------------------------------------------------------------
1 | Builder := Object clone
2 |
3 | Builder indent := 0
4 |
5 | Builder forward := method(
6 | write(" " repeated(self indent))
7 | writeln("<", call message name, ">")
8 | self indent = (self indent) + 4
9 | call message arguments foreach(
10 | arg,
11 | content := self doMessage(arg);
12 | if (content type == "Sequence",
13 | for (i, 0, (self indent) - 1, write(" "))
14 | writeln(content)))
15 | self indent = (self indent) - 4
16 | write(" " repeated(self indent))
17 | writeln("", call message name, ">"))
18 |
19 | Builder ul(
20 | li("Io"),
21 | li("Lua"),
22 | lu(
23 | li("Test"),
24 | li("Haha")),
25 | li("JavaScript"))
26 |
27 |
28 |
--------------------------------------------------------------------------------
/erlang/pingpong.erl:
--------------------------------------------------------------------------------
1 | -module(pingpong).
2 | -export([main/1]).
3 |
4 |
5 | ping(Pong_Pid, 0) ->
6 | Pong_Pid ! finished,
7 | io:format("ping finished~n");
8 | ping(Pong_Pid, N) ->
9 | Pong_Pid ! {self(), ping},
10 | receive
11 | pong ->
12 | io:format("ping received pong~n")
13 | end,
14 | ping(Pong_Pid, N - 1).
15 |
16 | pong() ->
17 | receive
18 | finished ->
19 | io:format("pong finished~n");
20 | {Ping_Pid, ping} ->
21 | io:format("pong received ping~n"),
22 | Ping_Pid ! pong,
23 | pong()
24 | end.
25 |
26 | wait()->wait().
27 |
28 | main(_) ->
29 | Pong_Pid = spawn(fun() -> pong() end),
30 | spawn(fun() -> ping(Pong_Pid, 3) end),
31 | wait().
32 |
33 |
34 |
--------------------------------------------------------------------------------
/javascript/tools/monitor2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/golang/basic/interface_test3.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type notifier interface {
8 | notify()
9 | }
10 |
11 | type user struct {
12 | name string
13 | email string
14 | }
15 |
16 | func (u *user) notify() {
17 | fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
18 | }
19 |
20 | type admin struct {
21 | name string
22 | email string
23 | }
24 |
25 | func (a *admin) notify() {
26 | fmt.Printf("Sending admin email to %s<%s>\n", a.name, a.email)
27 | }
28 |
29 | func main() {
30 | bill := user{"Bill", "bill@email.com"}
31 | sendNotification(&bill)
32 | lisa := admin{"Lisa", "lisa@email.com"}
33 | sendNotification(&lisa)
34 | }
35 |
36 | func sendNotification(n notifier) {
37 | n.notify()
38 | }
39 |
--------------------------------------------------------------------------------
/golang/goroutine/goroutine_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "runtime"
6 | "sync"
7 | )
8 |
9 | var wg sync.WaitGroup
10 |
11 | func main() {
12 | runtime.GOMAXPROCS(1)
13 | wg.Add(2)
14 |
15 | fmt.Println("Start Goroutines")
16 | go printPrime("A")
17 | go printPrime("B")
18 |
19 | fmt.Println("Waiting To Finish")
20 | wg.Wait()
21 |
22 | fmt.Println("\nTerminating Program")
23 | }
24 |
25 | func printPrime(prefix string) {
26 | defer wg.Done()
27 |
28 | next:
29 | for outer := 2; outer < 5000; outer++ {
30 | for inner := 2; inner < outer; inner++ {
31 | if outer%inner == 0 {
32 | continue next
33 | }
34 | }
35 | fmt.Printf("%s:%d\n", prefix, outer)
36 | }
37 | fmt.Println("Completed", prefix)
38 | }
39 |
--------------------------------------------------------------------------------
/golang/goroutine/goroutine_test3.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "runtime"
6 | "sync"
7 | )
8 |
9 | var wg sync.WaitGroup
10 |
11 | func main() {
12 | runtime.GOMAXPROCS(2)
13 | wg.Add(2)
14 |
15 | fmt.Println("Start Goroutines")
16 | go printPrime("A")
17 | go printPrime("B")
18 |
19 | fmt.Println("Waiting To Finish")
20 | wg.Wait()
21 |
22 | fmt.Println("\nTerminating Program")
23 | }
24 |
25 | func printPrime(prefix string) {
26 | defer wg.Done()
27 |
28 | next:
29 | for outer := 2; outer < 5000; outer++ {
30 | for inner := 2; inner < outer; inner++ {
31 | if outer%inner == 0 {
32 | continue next
33 | }
34 | }
35 | fmt.Printf("%s:%d\n", prefix, outer)
36 | }
37 | fmt.Println("Completed", prefix)
38 | }
39 |
--------------------------------------------------------------------------------
/erlang/translate.erl:
--------------------------------------------------------------------------------
1 | -module(translate).
2 | -export([loop/0, main/1]).
3 |
4 | loop() ->
5 | receive
6 | "casa" ->
7 | io:format("house~n"),
8 | loop();
9 |
10 | "blanca" ->
11 | io:format("white~n"),
12 | loop();
13 |
14 | "exit" ->
15 | io:format("exit here~n"),
16 | ok;
17 |
18 | _ ->
19 | io:format("I don't understand.~n"),
20 | loop()
21 | end.
22 |
23 | wait() ->
24 | wait().
25 |
26 | main(_) ->
27 | Pid = spawn(fun() -> loop() end),
28 | Pid ! "casa",
29 | Pid ! "blanca",
30 | Pid ! "dfdfdf",
31 | io:format("Pid: ~p~n", [Pid]),
32 | Pid ! "exit",
33 | Pid ! "casa",
34 | Pid ! "blanca",
35 | Pid ! "dfdfdf",
36 | io:format("Pid: ~p~n", [Pid]),
37 | wait(),
38 | ok.
39 |
40 |
--------------------------------------------------------------------------------
/golang/goroutine/goroutine_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "runtime"
6 | "sync"
7 | )
8 |
9 | func main() {
10 | runtime.GOMAXPROCS(1)
11 | var wg sync.WaitGroup
12 | wg.Add(2)
13 | fmt.Println("Start Goroutines")
14 |
15 | go func() {
16 | defer wg.Done()
17 |
18 | for count := 0; count < 3; count++ {
19 | for char := 'a'; char < 'a'+26; char++ {
20 | fmt.Printf("%c ", char)
21 | }
22 | }
23 | }()
24 |
25 | go func() {
26 | defer wg.Done()
27 |
28 | for count := 0; count < 3; count++ {
29 | for char := 'A'; char < 'A'+26; char++ {
30 | fmt.Printf("%c ", char)
31 | }
32 | }
33 | }()
34 |
35 | fmt.Println("Waiting To Finish")
36 | wg.Wait()
37 |
38 | fmt.Println("\nTerminating Program")
39 | }
40 |
--------------------------------------------------------------------------------
/erlang/echo.erl:
--------------------------------------------------------------------------------
1 | -module(echo).
2 | -author('skywind3000').
3 | -export([listen/1, main/1]).
4 |
5 | -define(TCP_OPTIONS, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]).
6 |
7 | listen(Port) ->
8 | {ok, ListenSocket} = gen_tcp:listen(Port, ?TCP_OPTIONS),
9 | accept(ListenSocket).
10 |
11 | accept(ListenSocket) ->
12 | {ok, Socket} = gen_tcp:accept(ListenSocket),
13 | spawn(fun() -> loop(Socket) end),
14 | accept(ListenSocket).
15 |
16 |
17 | loop(Socket) ->
18 | case gen_tcp:recv(Socket, 0) of
19 | {ok, Data} ->
20 | gen_tcp:send(Socket, Data),
21 | loop(Socket);
22 | {error, closed} ->
23 | ok
24 | end.
25 |
26 | main(_) ->
27 | io:format("Listen on port 2000\n"),
28 | listen(2000),
29 | halt(0).
30 |
31 |
32 |
--------------------------------------------------------------------------------
/scheme/queen2.scm:
--------------------------------------------------------------------------------
1 | (define (f vec x y)
2 | (define u (vector-ref vec (if (>= x 0) x 0)))
3 | (define v (vector-ref vec (if (>= y 0) y 0)))
4 | (define d (- x y))
5 | (or (< y 0) (not (or (= u v) (= v (+ u d)) (= v (- u d)) ))) )
6 |
7 | (define (g vec x y)
8 | (or (or (= x 0) (< y 0)) (and (f vec x y) (g vec x (- y 1)) )))
9 |
10 | (define (h vec x)
11 | (cond ((or (= x 0) (g vec x (- x 1))) 1) (else 0)))
12 |
13 | (define (p vec x i)
14 | (define n (vector-length vec))
15 | (vector-set! vec x i)
16 | (cond ((or (>= i n) (>= x n)) 0)
17 | ((= x (- n 1)) (+ (h vec x) (p vec x (+ i 1))))
18 | ((= (h vec x) 1) (+ (p vec (+ x 1) 0) (p vec x (+ i 1))) )
19 | (else (p vec x (+ i 1))) ))
20 |
21 | (display (p #(0 1 2 3 4 7 6 7) 0 0))
22 | (newline)
23 |
24 |
25 |
--------------------------------------------------------------------------------
/golang/basic/func_test2.go:
--------------------------------------------------------------------------------
1 | // =====================================================================
2 | //
3 | // func_test2.go -
4 | //
5 | // Created by skywind on 2024/11/18
6 | // Last Modified: 2024/11/18 20:59:42
7 | //
8 | // =====================================================================
9 | package main
10 |
11 | type FnType func()
12 |
13 | type Worker struct {
14 | name string
15 | salary int
16 | }
17 |
18 | func NewWorker(name string, salary int) *Worker {
19 | return &Worker{name, salary}
20 | }
21 |
22 | func (self *Worker) Show() {
23 | println("Worker:", self.name, self.salary)
24 | }
25 |
26 | func main() {
27 | w1 := NewWorker("Tom", 1000)
28 | w2 := NewWorker("Jerry", 2000)
29 | var fn FnType = nil
30 | fn = w1.Show
31 | fn()
32 | fn = w2.Show
33 | fn()
34 | }
35 |
--------------------------------------------------------------------------------
/golang/basic/interface_test5.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | type notifier interface {
8 | notify()
9 | }
10 |
11 | type user struct {
12 | name string
13 | email string
14 | }
15 |
16 | func (u *user) notify() {
17 | fmt.Printf("Sending user email to %s<%s>\n", u.name, u.email)
18 | }
19 |
20 | type admin struct {
21 | user
22 | level string
23 | }
24 |
25 | func (a *admin) notify() {
26 | fmt.Printf("Sending admin email to %s<%s>\n", a.name, a.email)
27 | }
28 |
29 | func main() {
30 | ad := admin{
31 | user: user{
32 | name: "John Smith",
33 | email: "john@yahoo.com",
34 | },
35 | level: "super",
36 | }
37 | sendNotification(&ad)
38 | ad.user.notify()
39 | ad.notify()
40 | }
41 |
42 | func sendNotification(n notifier) {
43 | n.notify()
44 | }
45 |
--------------------------------------------------------------------------------
/prolog/qsort.pro:
--------------------------------------------------------------------------------
1 |
2 |
3 | less([], X, []).
4 | less([A], X, [A]) :- A < X.
5 | less([A], X, [A]) :- A = X.
6 | less([A], X, []) :- A > X.
7 |
8 | less([HA|LA], X, B) :-
9 | \+(LA=[]),
10 | less([HA], X, B1),
11 | less(LA, X, B2),
12 | append(B1, B2, B).
13 |
14 | great([], X, []).
15 | great([A], X, [A]) :- A > X.
16 | great([A], X, []) :- A = X.
17 | great([A], X, []) :- A < X.
18 |
19 | great([HA|LA], X, B) :-
20 | \+(LA=[]),
21 | great([HA], X, B1),
22 | great(LA, X, B2),
23 | append(B1, B2, B).
24 |
25 |
26 | qsort([], []).
27 | qsort([X], [X]).
28 |
29 | qsort([HA|LA], B) :-
30 | \+(LA=[]),
31 | less(LA, HA, A1),
32 | great(LA, HA, A2),
33 | qsort(A1, B1),
34 | qsort(A2, B2),
35 | append(B1, [HA], B3),
36 | append(B3, B2, B).
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/scala/compass.scala:
--------------------------------------------------------------------------------
1 |
2 | class Compass {
3 | val directions = List("North", "east", "south", "west")
4 | var bearing = 0
5 | print("Initial bearing: ")
6 | println(direction)
7 |
8 | def direction() = directions(bearing)
9 |
10 | def inform(turnDirection: String) {
11 | println("Turning " + turnDirection + ". Now bearing " + direction)
12 | }
13 |
14 | def turnRight() {
15 | bearing = (bearing + 1) % directions.size
16 | inform("right")
17 | }
18 |
19 | def turnLeft() {
20 | bearing = (bearing + (directions.size - 1)) % directions.size
21 | inform("left")
22 | }
23 |
24 | }
25 |
26 | val myCompass = new Compass
27 |
28 | myCompass.turnRight
29 | myCompass.turnRight
30 | myCompass.turnLeft
31 | myCompass.turnLeft
32 | myCompass.turnLeft
33 |
34 |
35 |
--------------------------------------------------------------------------------
/golang/goroutine/channel_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "sync"
6 | "time"
7 | )
8 |
9 | var wg sync.WaitGroup
10 |
11 | func main() {
12 | baton := make(chan int)
13 | wg.Add(1)
14 | go Runner(baton)
15 | baton <- 1
16 | wg.Wait()
17 | }
18 |
19 | func Runner(baton chan int) {
20 | var newRunner int
21 | runner := <-baton
22 | fmt.Printf("Runner %d Running With Baton\n", runner)
23 | if runner != 4 {
24 | newRunner = runner + 1
25 | fmt.Printf("Runner %d To The Line\n", newRunner)
26 | go Runner(baton)
27 | }
28 | time.Sleep(100 * time.Millisecond)
29 | if runner == 4 {
30 | fmt.Printf("Runner %d Finished, Race Over\n", runner)
31 | wg.Done()
32 | return
33 | }
34 | fmt.Printf("Runner %d Exchange With Runner %d\n", runner, newRunner)
35 | baton <- newRunner
36 | }
37 |
--------------------------------------------------------------------------------
/golang/goroutine/channel_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "math/rand"
6 | "sync"
7 | "time"
8 | )
9 |
10 | var wg sync.WaitGroup
11 |
12 | func init() {
13 | rand.Seed(time.Now().UnixNano())
14 | }
15 |
16 | func main() {
17 | court := make(chan int)
18 | wg.Add(2)
19 | go player("Nadal", court)
20 | go player("Djokovic", court)
21 | court <- 1
22 | wg.Wait()
23 | }
24 |
25 | func player(name string, court chan int) {
26 | defer wg.Done()
27 | for {
28 | ball, ok := <-court
29 | if !ok {
30 | println("Player", name, "won")
31 | return
32 | }
33 | n := rand.Intn(100)
34 | if n%13 == 0 {
35 | fmt.Printf("Player %s missed\n", name)
36 | close(court)
37 | return
38 | }
39 | fmt.Printf("Player %s hit %d\n", name, ball)
40 | ball++
41 | court <- ball
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/html/basic/component3.html:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/javascript/basic/class_range3.js:
--------------------------------------------------------------------------------
1 |
2 | function Range(from, to) {
3 | this.from = from;
4 | this.to = to;
5 | }
6 |
7 | Range.prototype = {
8 | includes: function (x) {
9 | return this.from <= x && x <= this.to;
10 | },
11 | foreach: function (f) {
12 | for (var x = Math.ceil(this.from); x <= this.to; x++)
13 | f(x);
14 | },
15 | toString: function () {
16 | return"(" + this.from + "..." + this.to + ")";
17 | },
18 | };
19 |
20 | var r = Object.create(Range.prototype);
21 | Range.call(r, 1, 3);
22 |
23 | console.log(r.includes(2));
24 | r.foreach(console.log);
25 | console.log(r);
26 |
27 | console.log(typeof r);
28 |
29 | console.log(r instanceof Range);
30 |
31 | var R2 = function() {};
32 | R2.prototype = Range.prototype;
33 |
34 | console.log(r instanceof R2);
35 |
36 |
37 |
--------------------------------------------------------------------------------
/html/basic/layout_table2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | | 左边列 |
29 | 右边列 |
30 |
31 |
32 |
33 |
34 | | 内容1 |
35 | 内容2 |
36 |
37 |
38 | | 内容3 |
39 | 内容4 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/ruby/acts_as_csv_module.rb:
--------------------------------------------------------------------------------
1 | module ActsAsCsv
2 | def self.included(base)
3 | base.extend ClassMethods
4 | end
5 | module ClassMethods
6 | def acts_as_csv
7 | include InstanceMethods
8 | end
9 | end
10 |
11 | module InstanceMethods
12 | def read
13 | @csv_contents = []
14 | filename = self.class.to_s.downcase + '.txt'
15 | file = File.new(filename)
16 | @headers = file.gets.chomp.split(', ')
17 | file.each do |row|
18 | @csv_contents << row.chomp.split(', ')
19 | end
20 | end
21 |
22 | attr_accessor :headers, :csv_contents
23 |
24 | def initialize
25 | read
26 | end
27 | end
28 | end
29 |
30 | class RubyCsv
31 | include ActsAsCsv
32 | acts_as_csv
33 | end
34 |
35 | m = RubyCsv.new
36 | puts m.headers.inspect
37 | puts m.csv_contents.inspect
38 |
39 |
40 |
--------------------------------------------------------------------------------
/csharp/hello.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 |
4 | class Hello {
5 | static void Main(string[] args) {
6 | Console.WriteLine("Hello, World !!");
7 | Hashtable ht = new Hashtable();
8 | ht.Add(1, 1024);
9 | ht.Add("key1", "value1");
10 | ht.Add("key2", 2048);
11 | Console.WriteLine(ht.Contains(1));
12 | Console.WriteLine(ht.Contains(5));
13 | Console.WriteLine(ht.Contains("key1"));
14 | ht.Remove("key1");
15 | foreach (DictionaryEntry it in ht) {
16 | Console.WriteLine(" - {0} and {1}", it.Key, it.Value);
17 | }
18 | int i = 0;
19 | while (true) {
20 | if (++i > 10) break;
21 | Console.WriteLine(i);
22 | }
23 | string s1 = " haha ";
24 | Console.WriteLine(s1);
25 | Console.WriteLine(s1.Trim());
26 | Console.WriteLine(s1);
27 | }
28 | }
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/html/basic/layout_table4.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | | 左边列 |
23 | 中间列 |
24 | 右边列 |
25 |
26 |
27 |
28 |
29 | | 内容1 |
30 | 内容2 |
31 | 内容3 |
32 |
33 |
34 | | 内容4 |
35 | 内容5 |
36 | 内容6 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/javascript/react/start-page.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/python/parser/grammar/test_bnf.txt:
--------------------------------------------------------------------------------
1 | E: E + T | E - T | T ;
2 | T: T * F | T / F | F ;
3 | F: digit | "(" E ")" ;
4 |
5 | N: %empty ;
6 |
7 | V: | N N | N N N;
8 |
9 | %token digit NUMBER
10 | %left '+' '-'
11 | %left '*' "/"
12 | %nonassoc UMINUS
13 |
14 | %%
15 | expr: expr + term | expr - term | term;
16 |
17 | term:
18 | term * factor
19 | | term / factor
20 | | factor
21 | ;
22 |
23 | factor: {haha} digit
24 | | {action0} '(' expr ')' {action2} %prec UMINUS;
25 |
26 | factor: primary;
27 |
28 | # 'abc': F;
29 |
30 | empty: | | | ;
31 |
32 | test_empty: V | N N V | V V N | NUMBER;
33 | test_empty2: '+' NUMBER test_empty2 | test_empty;
34 | test_empty3: empty | V V V NUMBER N N;
35 | total_empty: empty | V V V N N;
36 | total_null: ;
37 | W: WEI | 'fuck' ;
38 | %%
39 |
40 | %start term
41 |
42 |
--------------------------------------------------------------------------------
/golang/json_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "encoding/json"
5 | "log"
6 | )
7 |
8 | var JSON = `{
9 | "name": "Gopher",
10 | "title": "programmer",
11 | "contact": {
12 | "home": "415.333.3333",
13 | "cell": "415.555.5555"
14 | }
15 | }
16 | `
17 |
18 | func main() {
19 | var obj interface{}
20 | err := json.Unmarshal([]byte(JSON), &obj)
21 | if err != nil {
22 | log.Printf("ERROR: %s\n", err)
23 | return
24 | }
25 | if obj == nil {
26 | log.Println("decode: obj is nil")
27 | return
28 | }
29 | if m, ok := obj.(map[string]interface{}); ok {
30 | log.Printf("name: %s\n", m["name"])
31 | log.Printf("title: %s\n", m["title"])
32 | if contact, ok := m["contact"].(map[string]interface{}); ok {
33 | log.Printf("home: %s\n", contact["home"])
34 | log.Printf("cell: %s\n", contact["cell"])
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/javascript/basic/class_range4.js:
--------------------------------------------------------------------------------
1 |
2 | function Range(from, to) {
3 | this.from = from;
4 | this.to = to;
5 | }
6 |
7 | Range.prototype.includes = function (x) {
8 | return this.from <= x && x <= this.to;
9 | }
10 |
11 | Range.prototype.foreach = function (f) {
12 | for (var x = Math.ceil(this.from); x <= this.to; x++)
13 | f(x);
14 | }
15 |
16 | Range.prototype.toString = function () {
17 | return"(" + this.from + "..." + this.to + ")";
18 | }
19 |
20 | var r = Object.create(Range.prototype);
21 | Range.call(r, 1, 3);
22 |
23 | console.log(r.includes(2));
24 | r.foreach(console.log);
25 | console.log(r);
26 |
27 | console.log(typeof r);
28 |
29 | console.log(r instanceof Range);
30 |
31 | var R2 = function() {};
32 | R2.prototype = Range.prototype;
33 |
34 | console.log(r instanceof R2);
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/html/basic/layout_flex5.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
31 |
32 |
33 |
34 |
35 |
test1
36 |
test2
37 |
test3
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/python/panda3d/tut3.py:
--------------------------------------------------------------------------------
1 | import math
2 |
3 | from direct.showbase.ShowBase import ShowBase
4 |
5 | class MyApp (ShowBase):
6 |
7 | def __init__ (self):
8 | ShowBase.__init__(self)
9 | self.scene = self.loader.loadModel('models/environment')
10 | self.scene.reparentTo(self.render)
11 | self.scene.setScale(0.25, 0.25, 0.25)
12 | self.scene.setPos(-8, 42, 0)
13 | self.taskMgr.add(self.spinCameraTask, 'SpinCameraTask')
14 |
15 | def spinCameraTask (self, task):
16 | angleDegrees = task.time * 6.0
17 | angleRadians = angleDegrees * (math.pi / 180.0)
18 | self.camera.setPos(20 * math.sin(angleRadians), -20.0 * math.cos(angleRadians), 3)
19 | self.camera.setHpr(angleDegrees, 0, 0)
20 | return task.cont
21 |
22 | app = MyApp()
23 | app.run()
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ruby/treenode.rb:
--------------------------------------------------------------------------------
1 | class Tree
2 | attr_accessor :children, :node_name
3 |
4 | def initialize(root)
5 | if root.class != {}.class
6 | raise "different type"
7 | elsif root.length != 1
8 | raise "size error"
9 | end
10 | @node_name = root.keys[0]
11 | @children = []
12 | root[@node_name].each do |name, childs|
13 | node = Tree.new({name=>childs})
14 | @children.push(node)
15 | end
16 | end
17 |
18 | def visit_all(&block)
19 | visit &block
20 | children.each {|c| c.visit_all &block}
21 | end
22 |
23 | def visit(&block)
24 | block.call self
25 | end
26 | end
27 |
28 |
29 | d = {"grandpa" => {
30 | 'dad'=>{'child1'=>{}, 'child2'=>{} },
31 | 'uncle'=>{'child3'=>{}, 'child4'=>{} }
32 | }}
33 |
34 | node = Tree.new(d)
35 | node.
36 |
37 | node.visit_all {|node| puts node.node_name}
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/golang/legacy/gob_encode.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "os"
5 | "encoding/gob"
6 | )
7 |
8 |
9 | func main() {
10 | info := map[string]string {
11 | "name" : "lilei",
12 | "age" : "24",
13 | }
14 | fp, _ := os.OpenFile("test.gob", os.O_RDWR | os.O_CREATE, 644)
15 | enc := gob.NewEncoder(fp)
16 | if err := enc.Encode(info); err != nil {
17 | println(err)
18 | }
19 | pos, _ := fp.Seek(0, 1)
20 | println("current", pos)
21 | if err := enc.Encode(info); err != nil {
22 | println(err)
23 | }
24 | pos, _ = fp.Seek(0, 1)
25 | println("current", pos)
26 |
27 | fp.Close()
28 |
29 | var m map[string]string
30 |
31 | fp, _ = os.Open("test.gob")
32 | dec := gob.NewDecoder(fp)
33 | if err := dec.Decode(&m); err != nil {
34 | println(err)
35 | }
36 |
37 | pos, _ = fp.Seek(0, 1)
38 | println(pos)
39 | }
40 |
41 |
42 |
--------------------------------------------------------------------------------
/scheme/predefined.scm:
--------------------------------------------------------------------------------
1 | #lang r5rs
2 |
3 | ;(define-syntax error
4 | ; (syntax-rules ()
5 | ; ((_ REASON ARG ...) (error REASON ARG ...))))
6 |
7 | (define-syntax error
8 | (syntax-rules ()
9 | ((error) (begin (newline) "ERROR-Output END"))
10 | ((error a) (display a))
11 | ((error a b ...) (begin (display a) (display " ") (error b ...)))))
12 |
13 | (define true #t)
14 |
15 | (define false #f)
16 |
17 | (define nil '())
18 |
19 | (define (identity x) x)
20 |
21 | (define (inc x) (+ x 1))
22 |
23 | (define (dec x) (- x 1))
24 |
25 | ;;; @section Streams
26 |
27 | (define-syntax cons-stream
28 | (syntax-rules ()
29 | ((_ A B) (cons A (delay B)))))
30 |
31 | (define the-empty-stream '())
32 |
33 | (define (stream-null? x) (null? x))
34 |
35 | (define (stream-car stream) (car stream))
36 |
37 | (define (stream-cdr stream) (force (cdr?stream)))
38 |
--------------------------------------------------------------------------------
/scheme/lesson2.scm:
--------------------------------------------------------------------------------
1 | ((lambda (x y z)
2 | (begin
3 | (display x)
4 | (newline)
5 | (display y)
6 | (newline)
7 | (display z)
8 | (newline)
9 | )
10 | ) 1 2 3)
11 |
12 | ((lambda x
13 | (begin
14 | (display x)
15 | (newline)
16 | )
17 | ) 1 2 3 4)
18 |
19 | ((lambda (x . y)
20 | (begin
21 | (display x)
22 | (newline)
23 | (display y)
24 | (newline)
25 | )
26 | ) 1 2 3 4)
27 |
28 | (define (t x . y)
29 | (begin
30 | (display x)
31 | (newline)
32 | (display y)
33 | (newline)
34 | )
35 | )
36 |
37 | (t 1 2 3 4)
38 |
39 |
40 | (define display3
41 | (lambda (arg1 arg2 arg3)
42 | (begin
43 | (display arg1)
44 | (display " ")
45 | (display arg2)
46 | (display " ")
47 | (display arg3)
48 | (newline)
49 | )
50 | )
51 | )
52 |
53 | (display3 7 8 9)
54 | (display3 7 8 9)
55 |
56 |
--------------------------------------------------------------------------------
/golang/rot13_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "io"
5 | "os"
6 | "strings"
7 | )
8 |
9 | type rot13Reader struct {
10 | r io.Reader
11 | }
12 |
13 | func (self *rot13Reader) Read(b []byte) (int, error) {
14 | size, err := self.r.Read(b)
15 | for i := 0; i < size; i++ {
16 | ch := int(b[i])
17 | if ch >= int('A') && ch <= int('Z') {
18 | n := ch - int('A')
19 | if n >= 13 {
20 | n = n - 13
21 | } else {
22 | n = n + 13
23 | }
24 | ch = int('A') + n
25 | } else if ch >= int('a') && ch <= int('z') {
26 | n := ch - int('a')
27 | if n >= 13 {
28 | n = n - 13
29 | } else {
30 | n = n + 13
31 | }
32 | ch = int('a') + n
33 | }
34 | b[i] = byte(ch & 0xff)
35 | }
36 | return size, err
37 | }
38 |
39 | func main() {
40 | s := strings.NewReader("Lbh penpxrq gur pbqr!")
41 | r := rot13Reader{s}
42 | io.Copy(os.Stdout, &r)
43 | }
44 |
--------------------------------------------------------------------------------
/html/basic/component4.html:
--------------------------------------------------------------------------------
1 |
2 | haha
3 |
4 |
5 |
6 |
21 |
22 |
23 |
24 | think
25 |
26 |
27 |
28 |
29 |
37 |
38 |
--------------------------------------------------------------------------------
/javascript/basic/class_type.js:
--------------------------------------------------------------------------------
1 |
2 | function type(o) {
3 | var t, c, n;
4 | if (o === null) return "null";
5 | if (!o == o) return 'nan';
6 | if ((t = typeof o) !== 'object') return t;
7 | if ((c = classof(o)) !== 'Object') return c;
8 | if (o.constructor && typeof o.constructor === 'function'
9 | && (n = o.constructor.getName()))
10 | return n;
11 | return 'Object';
12 | }
13 |
14 | function classof(o) {
15 | return Object.prototype.toString.call(o).slice(8, -1);
16 | }
17 |
18 | Function.prototype.getName = function () {
19 | if ('name' in this) return this.name;
20 | this.name = this.toString().match(/function\s*([^(]*)\(/)[1];
21 | return this.name;
22 | }
23 |
24 | function Range(){}
25 |
26 | var r = new Range();
27 |
28 | console.log(type(r));
29 |
30 | var m = new Map();
31 | console.log(type(m));
32 | console.log(typeof Map);
33 |
34 |
--------------------------------------------------------------------------------
/javascript/dom/dom-query.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
JavaScript
4 |
Java
5 |
6 |
7 |
Python
8 |
Ruby
9 |
Swift
10 |
11 |
12 |
Scheme
13 |
Haskell
14 |
15 |
16 |
17 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/javascript/dom/dom-sort.html:
--------------------------------------------------------------------------------
1 |
2 | - Scheme
3 | - JavaScript
4 | - Python
5 | - Ruby
6 | - Haskell
7 |
8 |
9 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/golang/basic/interface_test6.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "reflect"
6 | )
7 |
8 | func getInterface(what string) interface{} {
9 | switch what {
10 | case "int":
11 | return (interface{})(1)
12 | case "string":
13 | return (interface{})("hello")
14 | case "bool":
15 | return (interface{})(true)
16 | }
17 | return nil
18 | }
19 |
20 | func main() {
21 | var obj interface{}
22 |
23 | obj = getInterface("int")
24 | fmt.Printf("obj: %v, type: %T\n", obj, reflect.TypeOf(obj))
25 |
26 | x, ok := obj.(int)
27 | if ok {
28 | fmt.Printf("value: %v\n", x)
29 | }
30 |
31 | obj = getInterface("string")
32 | fmt.Printf("obj: %v, type: %T\n", obj, reflect.TypeOf(obj))
33 |
34 | y, ok := obj.(string)
35 | if ok {
36 | fmt.Printf("value: %v\n", y)
37 | }
38 |
39 | obj = getInterface("other")
40 | if obj == nil {
41 | fmt.Println("obj is nil")
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/golang/basic/generic_test2.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 | )
7 |
8 | // List represents a singly-linked list that holds
9 | // values of any type.
10 | type List[T any] struct {
11 | next *List[T]
12 | val T
13 | }
14 |
15 | func (self *List[T]) Size() int {
16 | count := 0
17 | for {
18 | if self == nil {
19 | break
20 | }
21 | self = self.next
22 | count++
23 | }
24 | return count
25 | }
26 |
27 | func (self *List[T]) String() string {
28 | var nodes []string
29 | for self != nil {
30 | t := fmt.Sprintf("%v", self.val)
31 | nodes = append(nodes, t)
32 | self = self.next
33 | }
34 | return strings.Join(nodes, "->")
35 | }
36 |
37 | func main() {
38 | var n1 *List[int] = &List[int]{nil, 10}
39 | var n2 *List[int] = &List[int]{n1, 20}
40 | var n3 *List[int] = &List[int]{n2, 30}
41 | fmt.Printf("size=%d\n", n3.Size())
42 | fmt.Printf("%v\n", n3)
43 | }
44 |
--------------------------------------------------------------------------------
/golang/legacy/variable_slice.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "reflect"
6 | )
7 |
8 | func isSliceOrArray(x interface{}) string {
9 | t := reflect.TypeOf(x)
10 | switch t.Kind() {
11 | case reflect.Slice:
12 | return "Slice"
13 | case reflect.Array:
14 | return "Array"
15 | default:
16 | return "not a slice or an array"
17 | }
18 | }
19 |
20 | func displaySlice(x []int) {
21 | fmt.Printf("slice cap=%d len=%d: %s\n", cap(x), len(x), x)
22 | }
23 |
24 | func main() {
25 | x := [...]int{1, 2, 3}
26 | y := x[0:2]
27 | z := []int{1, 2, 3}
28 | fmt.Printf("%s\n", isSliceOrArray(x))
29 | fmt.Printf("%s\n", isSliceOrArray(y))
30 | fmt.Printf("%s\n", isSliceOrArray(z))
31 | fmt.Printf("cap=%d size=%d\n", cap(z), len(z))
32 | u := append(z, 4)
33 | v := append(u, 5)
34 | v[1] = 100
35 | displaySlice(z)
36 | displaySlice(u)
37 | displaySlice(v)
38 | }
39 |
--------------------------------------------------------------------------------
/golang/lib/udp_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "net"
6 | "time"
7 | )
8 |
9 | func main() {
10 | // Create a UDP listener
11 | ln, err := net.ListenUDP("udp", &net.UDPAddr{Port: 12345})
12 | if err != nil {
13 | fmt.Println(err)
14 | return
15 | }
16 | defer ln.Close()
17 |
18 | go func() {
19 | buf := make([]byte, 1024)
20 | n, addr, err := ln.ReadFromUDP(buf)
21 | if err != nil {
22 | fmt.Printf("Error reading from UDP: %v\n", err)
23 | return
24 | }
25 | fmt.Printf("Received message from %s: %s\n", addr, string(buf[:n]))
26 | }()
27 |
28 | time.Sleep(1 * time.Second) // Simulate some work
29 |
30 | // Close the connection after a delay
31 | time.AfterFunc(2*time.Second, func() {
32 | err = ln.Close()
33 | if err != nil {
34 | fmt.Printf("Error closing UDP connection: %v\n", err)
35 | }
36 | })
37 |
38 | select {} // Keep the main goroutine alive
39 | }
40 |
--------------------------------------------------------------------------------
/javascript/tools/monitor3.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/golang/legacy/slice_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func main() {
6 | a := []int {1, 2, 3}
7 | b := append(a, 4)
8 | c := append(b, 5)
9 | fmt.Printf("slice a cap=%d len=%d: %v\n", cap(a), len(a), a)
10 | fmt.Printf("slice b cap=%d len=%d: %v\n", cap(b), len(b), b)
11 | fmt.Printf("slice c cap=%d len=%d: %v\n", cap(c), len(c), c)
12 | c[1] = 100
13 | fmt.Printf("change c[1] to 100\n")
14 | fmt.Printf("slice a cap=%d len=%d: %v\n", cap(a), len(a), a)
15 | fmt.Printf("slice b cap=%d len=%d: %v\n", cap(b), len(b), b)
16 | fmt.Printf("slice c cap=%d len=%d: %v\n", cap(c), len(c), c)
17 | }
18 |
19 | // Output:
20 | // slice a cap=3 len=3: [1 2 3]
21 | // slice b cap=6 len=4: [1 2 3 4]
22 | // slice c cap=6 len=5: [1 2 3 4 5]
23 | // change c[1] to 100
24 | // slice a cap=3 len=3: [1 2 3]
25 | // slice b cap=6 len=4: [1 100 3 4]
26 | // slice c cap=6 len=5: [1 100 3 4 5]
27 |
28 |
29 |
--------------------------------------------------------------------------------
/golang/basic/slice_test1.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func main() {
8 | var slice []int
9 | if slice == nil {
10 | fmt.Println("it is nil")
11 | fmt.Printf("size=%d cap=%d\n", len(slice), cap(slice))
12 | slice = append(slice, 5)
13 | fmt.Printf("size=%d cap=%d\n", len(slice), cap(slice))
14 | fmt.Println(slice)
15 | slice = slice[:0]
16 | if slice == nil {
17 | fmt.Println("nil again")
18 | } else {
19 | fmt.Printf("size=%d cap=%d\n", len(slice), cap(slice))
20 | }
21 | }
22 | slice = nil
23 | fmt.Printf("size=%d\n", len(slice))
24 | fmt.Println(slice)
25 | var slice2 []int = []int{1, 2, 3}
26 | fmt.Println(slice2)
27 | slice3 := make([]int, 0)
28 | if slice3 == nil {
29 | fmt.Println("slice3 is nil")
30 | fmt.Printf("size=%d cap=%d\n", len(slice3), cap(slice3))
31 | } else {
32 | fmt.Println("slice3 is not nil")
33 | fmt.Printf("size=%d cap=%d\n", len(slice3), cap(slice3))
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore all executable files
2 | *
3 | !*/
4 | !*.*
5 |
6 | # Prerequisites
7 | *.d
8 |
9 | # Compiled Object files
10 | *.slo
11 | *.lo
12 | *.o
13 | *.obj
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 | *.ipch
19 | *.sdf
20 |
21 | # Compiled Dynamic libraries
22 | *.so
23 | *.dylib
24 | *.dll
25 |
26 | # Fortran module files
27 | *.smod
28 |
29 | # Compiled Static libraries
30 | *.lai
31 | *.la
32 | *.a
33 | *.lib
34 |
35 | # Executables
36 | *.exe
37 | *.out
38 | *.app
39 | *.lib
40 |
41 | # Customize
42 | *.class
43 | *.pyc
44 | *.pyo
45 | *.pyd
46 | *.bak
47 | *.old
48 |
49 | *.pdf
50 | *.epub
51 | *.mht
52 | *.chm
53 | *.mobi
54 |
55 | *.rar
56 | *.zip
57 | *.tar.gz
58 | *.tar.bz2
59 | *.tar.xz
60 | *.log
61 |
62 | .netrwhist
63 | .DS_Store
64 | .tags
65 | .cscope
66 | .tasks
67 | .root
68 | .vscode/
69 | __pycache__/
70 | tags
71 |
72 | /test/*
73 | /language/incoming
74 | /language/parser/incoming
75 | vendor/*
76 | vendor/
77 |
78 |
--------------------------------------------------------------------------------
/prolog/plib.pro:
--------------------------------------------------------------------------------
1 | % Prolog Common Lib - skywind3000@gmail.com
2 | %
3 | % reference: https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_11.html
4 | %
5 |
6 | car([A|_], A).
7 | cdr([_|B], B).
8 | cons(X, R, [X|R]).
9 |
10 | sizeof([], 0).
11 | sizeof([_|Y], S) :- sizeof(Y, S1), S is S1 + 1.
12 |
13 | concatinate([], A, A).
14 | concatinate([H|L1], B, [H|L2]) :- concatinate(L1, B, L2).
15 |
16 | include([X|_], X).
17 | include([Y|R], X) :- \+(Y=X), include(R, X).
18 |
19 | exclude([], _).
20 | exclude([HA|LA], B) :- \+(HA=B), exclude(LA,B).
21 |
22 | different([]).
23 | different([HA|LA]) :- exclude(LA,HA), different(LA).
24 |
25 | takeout(X, [X|R], R).
26 | takeout(X, [F|R], [F|S]) :- takeout(X,R,S).
27 |
28 | imp_reverse([], X, X).
29 | imp_reverse([X|Y], Z, W) :- imp_reverse(Y, [X|Z], W).
30 |
31 | reverse(X, Y) :- imp_reverse(X, [], Y).
32 |
33 | perm([], []).
34 | perm([X|Y], Z) :- perm(Y, W), takeout(X, Z, W).
35 |
36 |
37 |
--------------------------------------------------------------------------------
/iolang/matrix2.io:
--------------------------------------------------------------------------------
1 |
2 | Matrix := List clone
3 |
4 | Matrix dim := method(x, y,
5 | m := Matrix clone
6 | z := 0
7 | fuck := 3
8 | for (i, 0, y - 1,
9 | n := list()
10 | for (j, 0, x - 1, n append(0))
11 | m append(n))
12 | m row := y
13 | m col := x
14 | m)
15 |
16 | Matrix rotate := method(
17 | row := self row
18 | col := self col
19 | m := Matrix dim(self col, self row)
20 | for (j, 0, row - 1,
21 | for (i, 0, col - 1, m set(i, j, self get(j, i))))
22 | m
23 | )
24 |
25 | Matrix get := method(x, y, (self at(y)) at(x))
26 | Matrix set := method(x, y, z, (self at(y)) atPut(x, z))
27 |
28 | m := Matrix dim(4, 4)
29 | n := Matrix dim(2, 2)
30 |
31 |
32 | m set(0, 1, 1)
33 | m set(1, 0, 3)
34 | m set(0, 3, 8)
35 | m set(2, 2, 6)
36 | m set(3, 0, 9)
37 | n set(1, 0, 99)
38 | n set(0, 1, 3)
39 |
40 | m println
41 | n println
42 | m rotate println
43 | n rotate println
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/elisp/hello.el:
--------------------------------------------------------------------------------
1 | (message "Hello, \"Emacs\" World !!")
2 | (setq my-text (format "hello %s %s %c %d %s" 1 2 ?X #x10 (or t 0)))
3 | (message (format "%s %s" [1 2 3 4 5] 'adsfasdf))
4 | (message (format "%s %s %s" '(1 2 (+ 3 4))
5 | (quote (1 2 (+ 3 4)))
6 | (list 1 2 (+ 3 4)))
7 | )
8 | (message my-text)
9 | (message (format "compare: %s" (/= 32 (+ 1 1))))
10 | (message (concat "this" " is " "concat string"))
11 |
12 | (setq foo 100)
13 | (message (format "compare: %s" (eq foo 100)))
14 | (message (format "vector: %s" (vector 1 2 3 4)))
15 |
16 | (if (= foo 100)
17 | (progn (message "true") (message "haha"))
18 | (message "false") )
19 |
20 | (when (eq foo 100)
21 | (message "foo is 100")
22 | (message "hahahah"))
23 |
24 | (setq foo 200)
25 |
26 | (cond
27 | (100
28 | (message "foo=100")
29 | (message "end1"))
30 | (200
31 | (message "foo=200")
32 | (message "end2")))
33 |
34 |
35 |
36 |
37 | '( (apple . "red"))
38 |
39 |
--------------------------------------------------------------------------------
/javascript/basic/class_define.js:
--------------------------------------------------------------------------------
1 | function extend(target, o) {
2 | var names = Object.getOwnPropertyNames(o);
3 | for (var i = 0; i < names.length; i++) {
4 | // if (names[i] in target) continue;
5 | var desc = Object.getOwnPropertyDescriptor(o, names[i]);
6 | Object.defineProperty(target, names[i], desc);
7 | }
8 | }
9 |
10 | function defineClass(constructor, methods, statics) {
11 | if (methods) extend(constructor.prototype, methods);
12 | if (statics) extend(constructor, statics);
13 | return constructor
14 | }
15 |
16 | var SimpleRange = defineClass(
17 | function (f, t) { this.f = f; this.t = t; },
18 | {
19 | includes: function(x) { return this.f <= x && x <= this.t; },
20 | toString: function() { return this.f+"..."+this.t; },
21 | },
22 | {
23 | upto: function (t) { return new SimpleRange(0, t); },
24 | },
25 | );
26 |
27 |
28 | var r = new SimpleRange(1, 3);
29 |
30 | console.log(r.includes(2));
31 | console.log(r.toString());
32 |
33 |
34 |
--------------------------------------------------------------------------------
/javascript/basic/class_range.js:
--------------------------------------------------------------------------------
1 | function inherit(p) {
2 | if (p == null)
3 | throw TypeError();
4 | if (Object.create && false)
5 | return Object.create(p);
6 | var t = typeof(p);
7 | if (t != 'function' && t != 'object')
8 | throw TypeError();
9 | function f() {};
10 | f.prototype = p;
11 | return new f();
12 | }
13 |
14 | function range(from, to) {
15 | var r = inherit(range.methods);
16 | r.from = from;
17 | r.to = to;
18 | return r;
19 | }
20 |
21 | range.methods = {
22 | includes: function (x) {
23 | return this.from <= x && x <= this.to;
24 | },
25 | foreach: function (f) {
26 | for (var x = Math.ceil(this.from); x <= this.to; x++)
27 | f(x);
28 | },
29 | toString: function () {
30 | return"(" + this.from + "..." + this.to + ")";
31 | },
32 | };
33 |
34 | var r = range(1, 3);
35 |
36 | console.log(r.includes(2));
37 | r.foreach(console.log);
38 | console.log(r);
39 |
40 |
41 | console.log(r instanceof range);
42 |
43 |
44 |
--------------------------------------------------------------------------------
/golang/basic/map_test5.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "math/rand"
6 | "time"
7 | )
8 |
9 | const N = 40000
10 | const PPS = 1000000
11 |
12 | func benchmark() {
13 | ras := make([]int32, N)
14 | cmap := make(map[int32]int32)
15 | for i := 0; i < N; i++ {
16 | for {
17 | k := int32(rand.Intn(0x7fffffff))
18 | if _, ok := cmap[k]; !ok {
19 | ras[i] = k
20 | cmap[k] = int32(i)
21 | break
22 | }
23 | }
24 | }
25 | log.Printf("start:\n")
26 | ts := time.Now().UnixMilli()
27 | hit := 0
28 | for i := 0; i < PPS; i++ {
29 | p := rand.Intn(N)
30 | k := int32(ras[p])
31 | v, ok := cmap[k]
32 | if !ok {
33 | log.Fatal("not find")
34 | break
35 | }
36 | if v != int32(p) {
37 | log.Fatal("not match")
38 | break
39 | } else {
40 | hit++
41 | }
42 | }
43 | diff := time.Now().UnixMilli() - ts
44 | log.Printf("end: time=%dms hit=%v", int(diff), hit)
45 | }
46 |
47 | func main() {
48 | log.Println("Hello, World!")
49 | benchmark()
50 | }
51 |
--------------------------------------------------------------------------------
/elisp/start_compile.el:
--------------------------------------------------------------------------------
1 | (setq option '((:cwd . "e:\\lab\\casuald") (:open . :same)))
2 | ;(vimmake-run "python e:/lab/timer.py " :process option)
3 | ;(vimmake-run "cmd" :windows option)
4 | (vimmake-run "dir" :process option)
5 |
6 | (message "default-directory: %s" default-directory)
7 |
8 | (setq info (vimmake-buffer-info))
9 | (vimmake-init-environ info)
10 |
11 | (message "%d/%d"
12 | (cdr (assoc :line info))
13 | (cdr (assoc :column info))
14 | )
15 | ;
16 |
17 | (defun display-line-number ()
18 | (let ((info (vimmake-buffer-info))
19 | (x 0) (y 0) (z 0) (w ""))
20 | (setq x (cdr (assoc :column info)))
21 | (setq y (cdr (assoc :line info)))
22 | (setq z (point))
23 | (setq w (cdr (assoc :cword info)))
24 | (setq s (cdr (assoc :csymbol info)))
25 | (message "%d: %d/%d -> <%s> (%s)" z y x w s))
26 | )
27 |
28 | (display-line-number)
29 | (global-set-key [f11] (lambda() (interactive) (display-line-number)))
30 |
31 |
32 | (message "endup")
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/javascript/react/react-start.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | React Start
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/python/example_echo.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 |
3 | async def echo_client():
4 | reader, writer = await asyncio.open_connection('127.0.0.1', 5001)
5 | while 1:
6 | writer.write(b'HELLO')
7 | await writer.drain()
8 | p = await reader.readexactly(5)
9 | if p == b'HELLO':
10 | print('ping')
11 | else:
12 | print('error')
13 | await asyncio.sleep(1)
14 | return 0
15 |
16 | async def echo_server(reader, writer):
17 | while True:
18 | s = await reader.read(4096)
19 | if not s:
20 | break
21 | writer.write(s)
22 | await writer.drain()
23 | return 0
24 |
25 |
26 | async def main():
27 | server = await asyncio.start_server(echo_server, '0.0.0.0', 5001)
28 | task = asyncio.create_task(echo_client())
29 | print('serving on {}'.format(server.sockets[0].getsockname()))
30 | await server.serve_forever()
31 | task.cancel()
32 | return 0
33 |
34 |
35 | asyncio.run(main())
36 |
37 |
38 |
--------------------------------------------------------------------------------
/golang/basic/type_check.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import "fmt"
4 |
5 | func check(i interface{}) {
6 | if i == nil {
7 | fmt.Printf("check: obj is nil\n")
8 | } else {
9 | switch v := i.(type) {
10 | case int:
11 | fmt.Printf("Twice %v is %v\n", v, v*2)
12 | case string:
13 | fmt.Printf("%q is %v bytes long\n", v, len(v))
14 | case map[string]interface{}:
15 | fmt.Printf("map[string]interface{}: %v\n", v)
16 | default:
17 | fmt.Printf("I don't know about type %T!\n", v)
18 | }
19 | }
20 | }
21 |
22 | func main() {
23 | check(21)
24 | check("hello")
25 | check(true)
26 | check(nil)
27 | var i1 interface{} = nil
28 | var i2 interface{} = 32
29 | var i3 map[string]interface{} = make(map[string]interface{})
30 | var i4 map[string]interface{} = nil
31 | check(i1)
32 | check(i2)
33 | check(i3)
34 | check(i4)
35 | }
36 |
37 | /* OUTPUT:
38 | Twice 21 is 42
39 | "hello" is 5 bytes long
40 | I don't know about type bool!
41 | check: obj is nil
42 | check: obj is nil
43 | Twice 32 is 64
44 | */
45 |
--------------------------------------------------------------------------------
/javascript/react/tutor-css1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | React Start
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/erlang/log_server.erl:
--------------------------------------------------------------------------------
1 | -module(log_server).
2 | -export([main/1]).
3 |
4 | -define(TCP_OPTIONS, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]).
5 |
6 | listen(Port) ->
7 | {ok, ListenSocket} = gen_tcp:listen(Port, ?TCP_OPTIONS),
8 | register(recorder, spawn(fun() -> record() end)),
9 | io:format("listen on port ~p~n", [Port]),
10 | accept(ListenSocket).
11 |
12 |
13 | accept(ListenSocket) ->
14 | {ok, Socket} = gen_tcp:accept(ListenSocket),
15 | spawn(fun() -> loop(Socket) end),
16 | accept(ListenSocket).
17 |
18 | loop(Socket) ->
19 | case gen_tcp:recv(Socket, 0) of
20 | {ok, Data} ->
21 | recorder ! {log, Data},
22 | loop(Socket);
23 | {error, closed} ->
24 | ok
25 | end.
26 |
27 | record() ->
28 | {ok, F} = file:open("log_server.txt", write),
29 | logging(F).
30 |
31 | logging(F) ->
32 | receive
33 | {log, What} ->
34 | io:format(F, "~p~n", [What]),
35 | io:format("record: ~p~n", [What]),
36 | logging(F)
37 | end.
38 |
39 |
40 | main(_) ->
41 | listen(2000),
42 | ok.
43 |
44 |
45 |
--------------------------------------------------------------------------------
/python/cotest3.py:
--------------------------------------------------------------------------------
1 | import asyncio
2 | import time
3 | import threading
4 | import queue
5 |
6 |
7 | q1 = queue.Queue()
8 |
9 | def system_thread():
10 | for i in range(1000):
11 | time.sleep(2)
12 | q1.put('obj-%d'%i)
13 | return 0
14 |
15 | threading.Thread(target = system_thread).start()
16 |
17 | async def task1():
18 | for i in range(1000):
19 | await asyncio.sleep(1)
20 | print('task1 is alive', i)
21 | return 0
22 |
23 | async def main():
24 | loop = asyncio.get_running_loop()
25 | asyncio.create_task(task1())
26 | while 1:
27 | result = await loop.run_in_executor(None, lambda: q1.get())
28 | print('get', result)
29 | return 0
30 |
31 | asyncio.run(main())
32 |
33 | '''
34 | task1 is alive 0
35 | get obj-0
36 | task1 is alive 1
37 | task1 is alive 2
38 | get obj-1
39 | task1 is alive 3
40 | task1 is alive 4
41 | get obj-2
42 | task1 is alive 5
43 | task1 is alive 6
44 | get obj-3
45 | task1 is alive 7
46 | task1 is alive 8
47 | '''
48 |
49 |
50 |
--------------------------------------------------------------------------------
/javascript/react/tutor-form1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | React Start
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/prolog/queen2.pro:
--------------------------------------------------------------------------------
1 | :-use_module(library(clpfd)).
2 |
3 | valid_queen((_, Col)) :- member(Col, [1,2,3,4,5,6,7,8]).
4 |
5 | valid_board([]).
6 | valid_board([Head|Tail]) :- valid_queen(Head), valid_board(Tail).
7 |
8 |
9 | cols([], []).
10 | cols([(_, Col)|QueenTail], [Col|ColTail]) :-
11 | cols(QueenTail, ColTail).
12 |
13 | diags1([], []).
14 | diags1([(Row, Col)|QueenTail], [DH|DL]) :-
15 | DH is Col - Row,
16 | diags1(QueenTail, DL).
17 |
18 | diags2([], []).
19 | diags2([(Row, Col)|QueenTail], [DH|DL]) :-
20 | DH is Col + Row,
21 | diags2(QueenTail, DL).
22 |
23 | eight_queens(Board) :-
24 | Board = [(1,_),(2,_),(3,_),(4,_),(5,_),(6,_),(7,_),(8,_)],
25 | valid_board(Board),
26 |
27 | cols(Board, Cols),
28 | diags1(Board, Diags1),
29 | diags2(Board, Diags2),
30 |
31 | all_different(Cols),
32 | all_different(Diags1),
33 | all_different(Diags2).
34 |
35 | solve :-
36 | Board = [(1,A),(2,B),(3,C),(4,D),(5,E),(6,F),(7,G),(8,H)],
37 | eight_queens(Board),
38 | List = [A, B, C, D, E, F, G, H],
39 | write(List),
40 | nl.
41 |
42 |
--------------------------------------------------------------------------------
/golang/goroutine/channel_test3.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "math/rand"
6 | "sync"
7 | "time"
8 | )
9 |
10 | const (
11 | numberGoroutines = 4
12 | taskLoad = 10
13 | )
14 |
15 | var wg sync.WaitGroup
16 |
17 | func init() {
18 | rand.Seed(time.Now().UnixNano())
19 | }
20 |
21 | func main() {
22 | tasks := make(chan string, taskLoad)
23 | wg.Add(numberGoroutines)
24 | for gr := 1; gr <= numberGoroutines; gr++ {
25 | go worker(tasks, gr)
26 | }
27 | for post := 1; post <= taskLoad; post++ {
28 | tasks <- fmt.Sprintf("Task: %d", post)
29 | }
30 | close(tasks)
31 | fmt.Println("main: sent all tasks")
32 | wg.Wait()
33 | }
34 |
35 | func worker(tasks chan string, worker int) {
36 | defer wg.Done()
37 | for {
38 | task, ok := <-tasks
39 | if !ok {
40 | fmt.Printf("Worker: %d: Shutting Down\n", worker)
41 | return
42 | }
43 | fmt.Printf("Worker: %d: Started %s\n", worker, task)
44 | sleep := rand.Int63n(100)
45 | time.Sleep(time.Duration(sleep) * time.Millisecond)
46 | fmt.Printf("Worker: %d: Completed %s\n", worker, task)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/prolog/queen1.pro:
--------------------------------------------------------------------------------
1 | :-use_module(library(clpfd)).
2 |
3 | valid_queen((Row, Col)) :-
4 | Range = [1,2,3,4,5,6,7,8],
5 | member(Row, Range), member(Col, Range).
6 |
7 | valid_queen2((R, C)) :- [R, C] ins 1..8.
8 |
9 | valid_board([]).
10 | valid_board([Head|Tail]) :- valid_queen(Head), valid_board(Tail).
11 |
12 | rows([], []).
13 | rows([(Row, _)|QueenTail], [Row|RowTail]) :-
14 | rows(QueenTail, RowTail).
15 |
16 | cols([], []).
17 | cols([(_, Col)|QueenTail], [Col|ColTail]) :-
18 | cols(QueenTail, ColTail).
19 |
20 | diags1([], []).
21 | diags1([(Row, Col)|QueenTail], [DH|DL]) :-
22 | DH is Col - Row,
23 | diags1(QueenTail, DL).
24 |
25 | diags2([], []).
26 | diags2([(Row, Col)|QueenTail], [DH|DL]) :-
27 | DH is Col + Row,
28 | diags2(QueenTail, DL).
29 |
30 | eight_queens(Board) :-
31 | length(Board, 8),
32 | valid_board(Board),
33 |
34 | rows(Board, Rows),
35 | cols(Board, Cols),
36 | diags1(Board, Diags1),
37 | diags2(Board, Diags2),
38 |
39 | all_different(Rows),
40 | all_different(Cols),
41 | all_different(Diags1),
42 | all_different(Diags2).
43 |
44 |
45 |
--------------------------------------------------------------------------------
/javascript/react/tutor-event1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | React Start
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Linwei
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/erlang/translate_service.erl:
--------------------------------------------------------------------------------
1 | -module(translate_service).
2 | -export([loop/0, translate/2, main/1]).
3 |
4 |
5 |
6 | loop() ->
7 | receive
8 | {From, "casa"} ->
9 | From ! "house",
10 | loop();
11 |
12 | {From, "blanca"} ->
13 | From ! "white",
14 | loop();
15 |
16 | {From, "exit"} ->
17 | From ! "exit here",
18 | ok;
19 |
20 | {From, _} ->
21 | From ! "I don't understand.",
22 | loop()
23 | end.
24 |
25 |
26 | translate(To, Word) ->
27 | To ! { self(), Word},
28 | receive
29 | Translation ->
30 | Translation
31 | end.
32 |
33 |
34 | wait() ->
35 | wait().
36 |
37 | main(_) ->
38 | Translator = spawn(fun () -> loop() end),
39 | Translator ! "SomeThing",
40 | P1 = translate(Translator, "blanca"),
41 | io:format("~p~n", [P1]),
42 | P2 = translate(Translator, "casa"),
43 | io:format("~p~n", [P2]),
44 | P3 = translate(Translator, "tasa"),
45 | io:format("~p~n", [P3]),
46 | P4 = translate(Translator, "exit"),
47 | io:format("~p~n", [P4]),
48 | P5 = translate(Translator, "exit"),
49 | io:format("~p~n", [P5]),
50 | ok.
51 |
52 |
53 |
--------------------------------------------------------------------------------