├── .gitignore ├── README ├── android └── CounterService │ ├── .classpath │ ├── .project │ ├── AndroidManifest.xml │ ├── bin │ ├── CounterService.apk │ ├── classes.dex │ └── resources.ap_ │ ├── default.properties │ ├── gen │ └── com │ │ └── muthanna │ │ └── playground │ │ └── android │ │ └── counter │ │ └── R.java │ ├── res │ ├── drawable │ │ └── icon.png │ ├── layout │ │ ├── local_service_controller.xml │ │ └── main.xml │ └── values │ │ └── strings.xml │ └── src │ └── com │ └── muthanna │ └── playground │ └── android │ └── counter │ ├── CounterService.java │ └── CounterServiceManager.java ├── arduino └── Siren │ └── Siren.ino ├── asm ├── Makefile ├── args.asm ├── atoi.asm ├── factorial.asm ├── hello64.asm ├── lib.asm ├── loop.asm ├── mean.asm ├── old │ ├── Makefile │ ├── asm.S │ ├── disasm.c │ └── disasm.s ├── printf.asm └── sum.asm ├── asterisk ├── README ├── res_hello.c └── test_call.sh ├── cpp ├── #binary.cpp# ├── boost │ ├── BUILD │ ├── bind.cc │ ├── function.cc │ ├── scoped_test.cc │ ├── simple.cc │ ├── tags │ └── unittest.cc ├── brk.c ├── cache_size.cc ├── casting.cc ├── casting_virtual.cc ├── cin.cc ├── container.cc ├── double.c ├── interview.cpp ├── istream.cc ├── perm.c ├── skiplist.cc ├── test.c └── whileone.cc ├── cs └── hellocoffee.html ├── emdr ├── .eslintrc ├── .gitignore ├── README.md ├── index.html ├── package-lock.json ├── package.json ├── src │ ├── api.ts │ ├── bouncer.ts │ ├── circle.ts │ ├── index.ts │ ├── logger.ts │ └── static │ │ └── index.css ├── tsconfig.json └── webpack.config.js ├── go ├── astar.go ├── echo.go ├── empty.go ├── hello.go ├── parity.go ├── shuffle │ ├── README.md │ └── shuffle_test.go ├── stack.go └── wscript ├── haskell ├── First.hs ├── LineServer.hs ├── LineServerTest.hs ├── PCRESub.hs ├── PCRESubTest.hs ├── PNM.hs ├── README ├── TCPConnection.hs ├── TCPServer.hs ├── Test.hs ├── TokenBucket.hs ├── TokenBucketTest.hs ├── avg.hs ├── binary.hs ├── binaryfile ├── bitarray.hs ├── chan.hs ├── concat.hs ├── debugging.hs ├── elf.hs ├── euler1.hs ├── euler10.hs ├── euler2.hs ├── euler3.hs ├── euler35.hs ├── euler7.hs ├── evilbot.hs ├── factrec.hs ├── file.hs ├── file.txt ├── fold.hs ├── hello.hs ├── hexdump.hs ├── homework2.hs ├── http.hs ├── interact.hs ├── io.hs ├── irc.hs ├── join.hs ├── list.hs ├── logger.hs ├── max.hs ├── maybe.hs ├── median.hs ├── min.hs ├── monad.hs ├── mvar.hs ├── par.hs ├── pardata.hs ├── picture.hs ├── powerset.hs ├── primes.hs ├── pscan.hs ├── quicksort.hs ├── random.hs ├── readert.hs ├── readline.hs ├── regsub.hs ├── renamer.hs ├── rot13.hs ├── splitlines.hs ├── states.hs ├── stmonad.hs ├── suffixes.hs ├── t1.hs ├── typeclass.hs ├── udpserver.hs ├── unlines.hs ├── unwrapio.hs ├── vector.hs ├── wc.hs └── xmlrep.hs ├── images └── cleanup.sh ├── java ├── .DS_Store ├── AdSaver.java ├── AdviceGuy.java ├── Dog.java ├── DogTester.java ├── EasyChatClient.java ├── EasyChatServer.java ├── GlassDemo.java ├── HelloWorld.java ├── ImageDownloader.java ├── MusicMan.java ├── PhraseOMatic.java ├── Quizzer.java ├── Rot13.java ├── SearchMap.java ├── Test3d.java ├── WriteFile.java ├── fullscreen.java ├── games │ └── TestTimer.java ├── j2d │ ├── AdSaver.java │ ├── ShapeExample.java │ └── mohit_muthanna_hindi.png ├── j3d │ ├── Checkers3D │ │ ├── CheckerFloor.java │ │ ├── Checkers3D.bat │ │ ├── Checkers3D.java │ │ ├── ColouredTiles.java │ │ ├── WrapCheckers3D.java │ │ ├── compileChk.bat │ │ └── readme.txt │ ├── Loader3D │ │ ├── CheckerFloor.java │ │ ├── ColouredTiles.java │ │ ├── Loader3D.bat │ │ ├── Loader3D.java │ │ ├── PropManager.java │ │ ├── WrapLoader3D.java │ │ ├── compileLd.bat │ │ ├── icons │ │ │ ├── down.gif │ │ │ ├── in.gif │ │ │ ├── left.gif │ │ │ ├── out.gif │ │ │ ├── right.gif │ │ │ └── up.gif │ │ ├── models │ │ │ ├── AARAM.3DS │ │ │ ├── AaramCoords.txt │ │ │ ├── BoxConeSphere.wrl │ │ │ ├── BoxConeSphereCoords.txt │ │ │ ├── CASTLE.COB │ │ │ ├── COOLROBO.3DS │ │ │ ├── CastleCoords.txt │ │ │ ├── CoolroboCoords.txt │ │ │ ├── MAA-1.3DS │ │ │ ├── bldg4.3ds │ │ │ ├── bldg4Coords.txt │ │ │ ├── hand1.obj │ │ │ ├── house.wrl │ │ │ └── houseCoords.txt │ │ └── readme.txt │ ├── LoaderInfo3D │ │ ├── CheckerFloor.java │ │ ├── ColouredTiles.java │ │ ├── LoaderInfo3D.bat │ │ ├── LoaderInfo3D.java │ │ ├── WrapLoaderInfo3D.java │ │ ├── compileLI.bat │ │ ├── examObj.txt │ │ ├── models │ │ │ ├── AARAM.3DS │ │ │ ├── BoxConeSphere.wrl │ │ │ ├── CASTLE.COB │ │ │ ├── COOLROBO.3DS │ │ │ ├── GUN1.3DS │ │ │ ├── MAA-1.3DS │ │ │ ├── column.3ds │ │ │ ├── dolphins.3ds │ │ │ ├── hand1.obj │ │ │ └── stone.jpg │ │ ├── portfolio.jar │ │ ├── portfolioLicense.txt │ │ └── readme.txt │ ├── Position.java │ ├── Random.java │ └── Test3d.java ├── macbundle │ └── GlassDemo.app │ │ └── Contents │ │ ├── Info.plist │ │ ├── MacOS │ │ └── JavaApplicationStub │ │ ├── PkgInfo │ │ └── Resources │ │ └── GenericJavaApp.icns ├── model.xml ├── quiz.data ├── servlets │ ├── beer │ │ ├── build.xml │ │ ├── etc │ │ │ └── web.xml │ │ ├── nbproject │ │ │ ├── private │ │ │ │ └── private.xml │ │ │ └── project.xml │ │ ├── src │ │ │ └── com │ │ │ │ ├── model │ │ │ │ └── BeerExpert.java │ │ │ │ └── test │ │ │ │ ├── BeerListener.java │ │ │ │ └── BeerSelect.java │ │ └── web │ │ │ ├── beer.html │ │ │ └── beer.jsp │ └── first │ │ ├── etc │ │ └── web.xml │ │ └── src │ │ └── FirstServlet.java ├── test.java ├── xmlrpc │ ├── XmlRpcClientTest.java │ ├── commons-logging-1.1.jar │ ├── run.sh │ ├── ws-commons-util-1.0.2.jar │ ├── xml_sample.java │ ├── xmlrpc-client-3.1.jar │ ├── xmlrpc-common-3.1.jar │ └── xmlrpc-server-3.1.jar └── xmpp │ ├── Makefile │ ├── SmackTest.java │ ├── lib │ ├── smack.jar │ ├── smackx-debug.jar │ ├── smackx-jingle.jar │ └── smackx.jar │ └── run.sh ├── js ├── canvas │ └── first.html ├── deno_test.js ├── denolib.ts ├── denorun.ts ├── glyphnames.js.gz ├── glyphnames2.js.gz ├── greasemonkey │ ├── helloworld.user.js │ ├── renamer.user.js │ └── yoogle.user.js ├── notify.js └── v8 │ ├── README │ ├── SConstruct │ └── test.cc ├── kernel ├── .hello.ko.cmd ├── .hello.mod.o.cmd ├── .hello.o.cmd ├── .tmp_versions │ └── hello.mod ├── Makefile ├── build.sh ├── hello.c ├── hello.ko ├── hello.mod.c ├── hello.mod.o └── hello.o ├── latex ├── hello.aux ├── hello.dvi ├── hello.log ├── hello.ps ├── hello.tex └── hello1.png ├── minikube ├── .gitignore ├── README.md ├── client │ ├── client.go │ └── cmd │ │ └── main.go ├── dice │ ├── dice.pb.go │ ├── dice.proto │ └── dice_grpc.pb.go ├── go.mod ├── go.sum ├── helm │ ├── dice │ │ ├── .helmignore │ │ ├── Chart.yaml │ │ ├── templates │ │ │ ├── envoy-configmap.yaml │ │ │ ├── envoy-depl.yaml │ │ │ ├── ingress.yaml │ │ │ ├── main-depl.yaml │ │ │ ├── nfs-pv.yaml │ │ │ └── server-depl.yaml │ │ └── values.yaml │ ├── k3s.yaml │ └── minikube.yaml ├── iptables.old ├── main.Dockerfile ├── main.arm64.Dockerfile ├── main.go ├── server.Dockerfile ├── server.arm64.Dockerfile ├── server │ └── main.go └── tls │ ├── .gitignore │ ├── README.md │ ├── ca.json │ ├── cfssl.json │ ├── ingress_host.json │ └── intermediate-ca.json ├── ocaml ├── README ├── average.ml └── comment.ml ├── octave ├── pitchshift.m └── timestretch.m ├── opencv ├── SConstruct └── capture.cc ├── perl ├── Lyndebrook.csv ├── Lyndebrook.glf ├── beer.pl ├── glf2csv ├── glfoutv2.pl └── printf.pl ├── python ├── README ├── anime.py ├── cartman.mp3 ├── challenges │ ├── add_two_numbers.py │ ├── all_subsets.py │ ├── easy_div7_not5.py │ ├── fib.py │ ├── find_duplicate_number.py │ ├── house_robber.py │ ├── longest_palindrome.py │ ├── longest_substring.py │ ├── lru_cache.py │ ├── max_profit.py │ ├── max_subarray.py │ ├── median_finder.py │ ├── merge_intervals.py │ ├── merge_k_lists.py │ ├── minimum_window_substring.py │ ├── num_islands.py │ └── trapping_water.py ├── colors.py ├── combwords.py ├── constraint.py ├── curses_test.py ├── hellomac.py ├── learner.py ├── marilyn.jpg ├── ml │ └── recommendations.py ├── mp3renamer.py ├── permute.py ├── permwords.py ├── pigame.py ├── piglet.py ├── readline_test.py ├── selenium_test.py ├── sqlalchemy_test.py ├── system.py ├── torchtest.py ├── tornado_test.py ├── webapp │ ├── app.py │ ├── login.py │ ├── model_test.py │ ├── models │ │ ├── __init__.py │ │ ├── api.py │ │ ├── metadata.py │ │ └── user.py │ ├── static │ │ ├── js │ │ │ ├── jquery.validate.js │ │ │ ├── main.js │ │ │ ├── require.js │ │ │ ├── user_api.js │ │ │ ├── vex.js │ │ │ └── vexutils.js │ │ ├── marilyn.jpg │ │ ├── reset.css │ │ └── style.css │ ├── templates │ │ ├── base.html │ │ ├── frontpage.html │ │ └── login.html │ └── vexweb │ │ ├── __init__.py │ │ ├── db.py │ │ └── handlers.py ├── webdriver_test.py ├── webpinger.py └── zebra.py ├── r ├── palette.rscript ├── recolor.rscript └── waves.rscript ├── ruby ├── README.md ├── anonymize.rb ├── browser_test.rb ├── gencsv.rb ├── heap.rb ├── markdown.pl ├── midi │ └── README.md ├── nc.rb ├── parsecsv.rb ├── push.sh ├── refresher.css ├── refresher.md ├── urlencode │ └── u.rb └── wget.rb ├── rust ├── .gitignore ├── btree │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ ├── btree.rs │ │ └── main.rs ├── echo │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── hello │ ├── .gitignore │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ └── src │ │ ├── args.rs │ │ ├── arrays.rs │ │ ├── asyncawait.rs │ │ ├── dynamic.rs │ │ ├── functions.rs │ │ ├── generics.rs │ │ ├── iterators.rs │ │ ├── json.rs │ │ ├── lifetimes.rs │ │ ├── main.rs │ │ ├── pointers.rs │ │ ├── print.rs │ │ ├── server.rs │ │ ├── strings.rs │ │ ├── structs.rs │ │ ├── threadpool.rs │ │ ├── threads.rs │ │ ├── traits.rs │ │ ├── tuples.rs │ │ ├── types.rs │ │ └── vars.rs ├── hype │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ ├── lib.rs │ │ ├── main.rs │ │ ├── parser.rs │ │ ├── response.rs │ │ ├── server.rs │ │ └── status.rs ├── leetcode │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ ├── add_two_numbers.rs │ │ ├── lib.rs │ │ ├── longest_palindromic_substring.rs │ │ ├── longest_substring_without_repeating_characters.rs │ │ ├── median_of_two_sorted_arrays.rs │ │ ├── reverse_integer.rs │ │ ├── string_to_integer_atoi.rs │ │ ├── two_sum.rs │ │ └── zigzag_conversion.rs ├── stack │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ │ ├── main.rs │ │ └── stack.rs └── threads │ ├── Cargo.lock │ ├── Cargo.toml │ └── src │ ├── atomics.rs │ ├── locks.rs │ ├── main.rs │ └── thread.rs ├── scala ├── Args.scala ├── AsteriskClient │ ├── Client.scala │ ├── Connection.scala │ ├── Message.scala │ ├── README │ ├── TestCall.scala │ └── Util.scala ├── CometServlet.scala ├── ForEach.scala ├── HelloWorld.scala ├── JettyHello.scala ├── JettyServlet.scala ├── ManyServlets.scala ├── MapTest.scala ├── NetBeansProjects │ └── AsteriskClient │ │ ├── AMIConnection.scala │ │ ├── build.xml │ │ ├── dist │ │ ├── AsteriskClient.jar │ │ └── README.TXT │ │ ├── manifest.mf │ │ ├── nbproject │ │ ├── build-impl.xml │ │ ├── genfiles.properties │ │ ├── private │ │ │ ├── config.properties │ │ │ ├── private.properties │ │ │ └── private.xml │ │ ├── project.properties │ │ └── project.xml │ │ └── src │ │ └── asteriskclient │ │ ├── AMIClient.scala │ │ ├── AMIConnection.scala │ │ ├── Main.scala │ │ └── Util.scala ├── Privacy.scala ├── README ├── SocketClient.scala ├── Timer.scala ├── YamlReader.scala ├── hello.rb └── script.scala ├── stats ├── README.md ├── hellotf.py ├── helloworld.ipynb ├── housing.py ├── stopwords.js ├── tesla.py └── tstf │ ├── .babelrc │ ├── .eslintignore │ ├── .eslintrc.js │ ├── index.html │ ├── package-lock.json │ ├── package.json │ ├── postcss.config.js │ ├── src │ ├── index.ts │ └── style.css │ ├── stylelint.config.js │ ├── tailwind.config.js │ └── webpack.config.js └── www ├── GoL.js ├── README ├── analyzer ├── css │ ├── le-frog │ │ ├── images │ │ │ ├── ui-bg_diagonals-small_0_aaaaaa_40x40.png │ │ │ ├── ui-bg_diagonals-thick_15_444444_40x40.png │ │ │ ├── ui-bg_diagonals-thick_95_ffdc2e_40x40.png │ │ │ ├── ui-bg_glass_55_fbf5d0_1x400.png │ │ │ ├── ui-bg_highlight-hard_30_285c00_1x100.png │ │ │ ├── ui-bg_highlight-soft_33_3a8104_1x100.png │ │ │ ├── ui-bg_highlight-soft_50_4eb305_1x100.png │ │ │ ├── ui-bg_highlight-soft_60_4ca20b_1x100.png │ │ │ ├── ui-bg_inset-soft_10_285c00_1x100.png │ │ │ ├── ui-icons_4eb305_256x240.png │ │ │ ├── ui-icons_72b42d_256x240.png │ │ │ ├── ui-icons_cd0a0a_256x240.png │ │ │ └── ui-icons_ffffff_256x240.png │ │ └── jquery-ui-1.8.15.custom.css │ └── tone.css ├── index.html └── js │ ├── sinewave.js │ ├── spectrum.js │ └── support │ ├── jquery-1.6.2.min.js │ └── jquery-ui-1.8.15.custom.min.js ├── audio.html ├── audio └── snare.wav ├── brown.css ├── chords ├── css │ └── style.css ├── index.html └── js │ ├── chart.js │ ├── chord.js │ └── support │ ├── jquery-1.6.2.min.js │ ├── jquery-ui-1.8.15.custom.min.js │ └── raphael-min.js ├── draggable.html ├── filter.html ├── grid.js ├── index.html ├── jstest.html ├── mandelbrot ├── mandelbrot.html ├── mandelbrot.js ├── mandelbrot_test.html └── mandelbrot_test.js ├── maps.html ├── mjk ├── animations.css ├── index.html └── mjk.jpg ├── notifyme.html ├── rubyrefresher ├── index.html └── refresher.css ├── something.html ├── style.css ├── tone ├── css │ ├── le-frog │ │ ├── images │ │ │ ├── ui-bg_diagonals-small_0_aaaaaa_40x40.png │ │ │ ├── ui-bg_diagonals-thick_15_444444_40x40.png │ │ │ ├── ui-bg_diagonals-thick_95_ffdc2e_40x40.png │ │ │ ├── ui-bg_glass_55_fbf5d0_1x400.png │ │ │ ├── ui-bg_highlight-hard_30_285c00_1x100.png │ │ │ ├── ui-bg_highlight-soft_33_3a8104_1x100.png │ │ │ ├── ui-bg_highlight-soft_50_4eb305_1x100.png │ │ │ ├── ui-bg_highlight-soft_60_4ca20b_1x100.png │ │ │ ├── ui-bg_inset-soft_10_285c00_1x100.png │ │ │ ├── ui-icons_4eb305_256x240.png │ │ │ ├── ui-icons_72b42d_256x240.png │ │ │ ├── ui-icons_cd0a0a_256x240.png │ │ │ └── ui-icons_ffffff_256x240.png │ │ └── jquery-ui-1.8.15.custom.css │ └── tone.css ├── index.html └── js │ ├── jquery-1.6.2.min.js │ ├── jquery-ui-1.8.15.custom.min.js │ └── sinewave.js └── wavebox ├── audio └── track.mp3 ├── css └── style.css ├── index.html └── js ├── remoteaudioplayer.js ├── spectrum.js └── support └── jquery-1.6.2.min.js /.gitignore: -------------------------------------------------------------------------------- 1 | ruby_sess.* 2 | .*.swp 3 | .hi 4 | .[oa] 5 | *.pyc 6 | .svn 7 | .class 8 | *.o 9 | # except foo.o which is hand maintained 10 | !foo.o 11 | -------------------------------------------------------------------------------- /android/CounterService/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /android/CounterService/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | CounterService 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /android/CounterService/bin/CounterService.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/android/CounterService/bin/CounterService.apk -------------------------------------------------------------------------------- /android/CounterService/bin/classes.dex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/android/CounterService/bin/classes.dex -------------------------------------------------------------------------------- /android/CounterService/bin/resources.ap_: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/android/CounterService/bin/resources.ap_ -------------------------------------------------------------------------------- /android/CounterService/default.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=Google Inc.:Google APIs:3 12 | -------------------------------------------------------------------------------- /android/CounterService/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/android/CounterService/res/drawable/icon.png -------------------------------------------------------------------------------- /android/CounterService/res/layout/local_service_controller.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 9 | 10 | 15 | 16 | 21 | 22 | 26 | 27 | -------------------------------------------------------------------------------- /android/CounterService/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /android/CounterService/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello World, PagerServiceManager! 4 | PagerService 5 | Service Started. 6 | Service Stopped. 7 | Service Label. 8 | App/Service/Local Service Controller 9 | This demonstrates how you can implement persistent services that 10 | may be started and stopped as desired. 11 | Start Service 12 | Stop Service 13 | 14 | 15 | -------------------------------------------------------------------------------- /asm/Makefile: -------------------------------------------------------------------------------- 1 | targets = printf loop args atoi factorial mean 2 | 3 | all: $(targets) hello64 sum 4 | 5 | $(targets): $(targets:%=%.o) 6 | 7 | %.o: %.asm 8 | nasm -f elf64 -g -F dwarf -o $@ $< 9 | 10 | %: %.o 11 | gcc -no-pie -g -m64 -o $@ $< 12 | 13 | clean: 14 | rm *.o 15 | rm $(targets) hello64 sum 16 | 17 | # This one is special 18 | hello64: hello64.asm 19 | nasm -f elf64 -g -F dwarf -o $@.o $< 20 | ld -o hello64 hello64.o -I/lib64/ld-linux-x86-64.so.2 21 | 22 | sum: sum.o lib.o 23 | gcc -no-pie -g -m64 -o $@ $< lib.o -------------------------------------------------------------------------------- /asm/hello64.asm: -------------------------------------------------------------------------------- 1 | global _start 2 | 3 | ; 4 | ; CONSTANTS 5 | ; 6 | SYS_WRITE equ 1 7 | SYS_EXIT equ 60 8 | STDOUT equ 1 9 | 10 | ; 11 | ; Initialised data goes here 12 | ; 13 | SECTION .data 14 | hello db "Hello World!", 10 ; char * 15 | hello_len equ $-hello ; size_t 16 | 17 | ; 18 | ; Code goes here 19 | ; 20 | SECTION .text 21 | 22 | _start: 23 | ; syscall(SYS_WRITE, STDOUT, hello, hello_len); 24 | mov rax, SYS_WRITE 25 | mov rdi, STDOUT 26 | mov rsi, hello 27 | mov rdx, hello_len 28 | syscall 29 | push rax 30 | 31 | ; syscall(SYS_EXIT, - hello_len); 32 | mov rax, SYS_EXIT 33 | pop rdi 34 | sub rdi, hello_len 35 | syscall 36 | -------------------------------------------------------------------------------- /asm/lib.asm: -------------------------------------------------------------------------------- 1 | ; sum list of integers in arguments 2 | 3 | global atoi, strlen 4 | section .text 5 | 6 | atoi: 7 | push rbp 8 | mov rbp, rsp 9 | 10 | mov r9, 10 ; power of 10 for mul 11 | mov rcx, 0 12 | xor rax, rax 13 | 14 | atoi_loop: 15 | movzx rsi, byte [rdi+rcx] 16 | cmp rsi, 0 17 | je atoi_done 18 | 19 | cmp rsi, 48 20 | jl atoi_done 21 | 22 | cmp rsi, 57 23 | jg atoi_done 24 | 25 | sub rsi, 48 26 | mul r9 27 | add rax, rsi 28 | inc rcx 29 | jmp atoi_loop 30 | 31 | atoi_done: 32 | leave 33 | ret 34 | 35 | 36 | strlen: 37 | push rbp 38 | mov rbp, rsp 39 | mov rcx, 0 40 | 41 | strlen_count: 42 | cmp [rdi+rcx], byte 0 43 | je strlen_done 44 | inc rcx 45 | jmp strlen_count 46 | 47 | strlen_done: 48 | mov rax, rcx 49 | leave 50 | ret 51 | -------------------------------------------------------------------------------- /asm/loop.asm: -------------------------------------------------------------------------------- 1 | global main 2 | extern printf 3 | 4 | SECTION .data 5 | val dq 42 6 | 7 | SECTION .rodata 8 | hello db "Hello %ld!",10,0 9 | ; 10 | SECTION .text 11 | 12 | main: 13 | push rbp 14 | mov r12, [val] 15 | 16 | loop_start: 17 | lea rdi, [hello] 18 | mov rsi, r12 19 | xor rax, rax 20 | call printf 21 | sub r12, 1 22 | jnz loop_start 23 | 24 | mov rax, 0 25 | pop rbp 26 | ret 27 | -------------------------------------------------------------------------------- /asm/old/Makefile: -------------------------------------------------------------------------------- 1 | all: asm 2 | 3 | asm.o: asm.S 4 | nasm -f elf asm.S 5 | 6 | asm: asm.o 7 | ld -o asm asm.o 8 | 9 | clean: 10 | rm asm asm.o 11 | -------------------------------------------------------------------------------- /asm/old/asm.S: -------------------------------------------------------------------------------- 1 | section .data 2 | hello: db 'Hello World!', 10, 13 3 | helloLen: db $ - hello 4 | 5 | section .text 6 | global _start 7 | 8 | _start: 9 | mov eax, 4 10 | mov ebx, 2 11 | mov ecx, hello 12 | mov edx, [ helloLen ] 13 | int 80h 14 | 15 | mov ebx, eax 16 | mov eax, 1 17 | int 80h 18 | -------------------------------------------------------------------------------- /asm/old/disasm.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int show(const char* msg) { 4 | printf(msg); 5 | } 6 | 7 | int main(int argc, char** argv) { 8 | show("Hello World\n"); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /asm/old/disasm.s: -------------------------------------------------------------------------------- 1 | .text 2 | .globl _show 3 | _show: 4 | pushl %ebp 5 | movl %esp, %ebp 6 | subl $24, %esp 7 | movl 8(%ebp), %eax 8 | movl %eax, (%esp) 9 | call L_printf$stub 10 | leave 11 | ret 12 | .cstring 13 | LC0: 14 | .ascii "Hello World\12\0" 15 | .text 16 | .globl _main 17 | _main: 18 | pushl %ebp 19 | movl %esp, %ebp 20 | pushl %ebx 21 | subl $20, %esp 22 | call L5 23 | "L00000000001$pb": 24 | L5: 25 | popl %ebx 26 | leal LC0-"L00000000001$pb"(%ebx), %eax 27 | movl %eax, (%esp) 28 | call _show 29 | movl $0, %eax 30 | addl $20, %esp 31 | popl %ebx 32 | leave 33 | ret 34 | .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5 35 | L_printf$stub: 36 | .indirect_symbol _printf 37 | hlt ; hlt ; hlt ; hlt ; hlt 38 | .subsections_via_symbols 39 | -------------------------------------------------------------------------------- /asm/printf.asm: -------------------------------------------------------------------------------- 1 | global main 2 | extern printf 3 | default rel 4 | 5 | SECTION .data 6 | val dq 42 7 | 8 | SECTION .rodata 9 | hello db "Hello %ld!",10,0 10 | ; 11 | SECTION .text 12 | 13 | main: 14 | push rbx 15 | lea rdi, [hello] 16 | mov rsi, [val] 17 | xor rax, rax 18 | call printf 19 | mov rax, 0 20 | pop rbx 21 | ret 22 | -------------------------------------------------------------------------------- /asm/sum.asm: -------------------------------------------------------------------------------- 1 | ; sum list of integers in arguments 2 | 3 | 4 | global main 5 | extern printf, atoi 6 | 7 | section .data 8 | E_badargs db "Usage: sum N [N ...]", 10, 0 9 | P_print_sum db "Sum: %ld", 10, 0 10 | 11 | section .text 12 | 13 | main: 14 | push rbp 15 | mov rbp, rsp 16 | 17 | ; enough args? 18 | cmp rdi, 2 19 | jl arg_error 20 | 21 | mov r12, rdi ; argc 22 | mov r13, 0 ; total 23 | mov r14, rsi ; argv 24 | mov r15, 1 ; counter 25 | 26 | sum_loop: 27 | ; convert arg to integer 28 | mov rdi, [r14+r15*8] 29 | call atoi ; from lib.asm 30 | add r13, rax 31 | inc r15 32 | cmp r15, r12 33 | jl sum_loop 34 | 35 | lea rdi, [P_print_sum] ; arg 0 - the format string 36 | mov rsi, r13 ; arg 1 - the number 37 | xor rax, rax ; must be 0 if no FP args 38 | call printf 39 | 40 | xor rax, rax 41 | pop rbp 42 | ret 43 | 44 | arg_error: 45 | mov rdi, E_badargs 46 | mov rax, 0 47 | call printf 48 | mov rax, 1 49 | mov rsp, rbp 50 | pop rbp 51 | ret -------------------------------------------------------------------------------- /asterisk/res_hello.c: -------------------------------------------------------------------------------- 1 | #include "asterisk.h" 2 | 3 | ASTERISK_FILE_VERSION(__FILE__, "blah"); 4 | 5 | #include "asterisk/module.h" 6 | #include "asterisk/logger.h" 7 | 8 | static int load_module(void) { 9 | ast_log(LOG_NOTICE, "Hello World!\n"); 10 | return AST_MODULE_LOAD_SUCCESS; 11 | } 12 | 13 | static int unload_module(void) { 14 | ast_log(LOG_NOTICE, "Goodbye World!\n"); 15 | return 0; 16 | } 17 | 18 | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hello World"); 19 | -------------------------------------------------------------------------------- /asterisk/test_call.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # SPOOL=/var/spool/asterisk/outgoing 4 | SPOOL=/opt/asterisk/var/spool/asterisk/outgoing 5 | TEMP=`/bin/mktemp /tmp/$0.XXXXXX` 6 | SOURCE=172.25.189.35 7 | TARGET=$1 8 | MESSAGE=$2 9 | 10 | cat >$TEMP < 3 | #include 4 | 5 | using namespace std; 6 | using boost::bind; 7 | 8 | class MyClass { 9 | public: 10 | void MemberFunction(int num) { 11 | cout << "Member function: " << num << endl; 12 | } 13 | }; 14 | 15 | void FreeFunction(int num) { 16 | cout << "Free function: " << num << endl; 17 | } 18 | 19 | int FreeWithReturn(int num) { 20 | cout << "Free with return: " << num << endl; 21 | return num + 1; 22 | } 23 | 24 | int main() { 25 | (bind(&FreeFunction, _1)) (45); 26 | 27 | MyClass me; 28 | (bind(&MyClass::MemberFunction, _1, _2)) (&me, 50); 29 | 30 | int returned = (bind(&FreeWithReturn, _1)) (45); 31 | cout << "Returned: " << returned << endl; 32 | } 33 | -------------------------------------------------------------------------------- /cpp/boost/scoped_test.cc: -------------------------------------------------------------------------------- 1 | #include "boost/scoped_ptr.hpp" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | using boost::scoped_ptr; 7 | 8 | int main() { 9 | scoped_ptr s(new string("Scoped string.")); 10 | 11 | cout << *s << "\n"; 12 | } 13 | -------------------------------------------------------------------------------- /cpp/boost/simple.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | using namespace boost::lambda; 8 | 9 | typedef std::istream_iterator in; 10 | std::for_each( 11 | in(std::cin), in(), std::cout << (_1 * 3) << " "); 12 | } 13 | -------------------------------------------------------------------------------- /cpp/boost/tags: -------------------------------------------------------------------------------- 1 | BOOST_AUTO_TEST_CASE unittest.cc /^BOOST_AUTO_TEST_CASE(case2) {$/ 2 | BOOST_AUTO_TEST_SUITE unittest.cc /^BOOST_AUTO_TEST_SUITE(adder)$/ 3 | FreeFunction bind.cc /^void FreeFunction(int num) {$/ 4 | FreeWithReturn bind.cc /^int FreeWithReturn(int num) {$/ 5 | Mbind.cc bind.cc /^int main() {$/ 6 | Mfunction.cc function.cc /^int main() {$/ 7 | Mscoped_test.cc scoped_test.cc /^int main() {$/ 8 | Msimple.cc simple.cc /^int main() {$/ 9 | add unittest.cc /^int add(int i, int j) { return i + j; }$/ 10 | in simple.cc /^ typedef std::istream_iterator in;$/ 11 | -------------------------------------------------------------------------------- /cpp/boost/unittest.cc: -------------------------------------------------------------------------------- 1 | // Unit test test. 2 | // Mohit Cheppudira. 3 | // 4 | // Build with (if BOOST_TEST_DYN_LINK is defined): 5 | // $ g++ unittest.cc -lboost_unit_test_framework 6 | // 7 | // or statically: 8 | // $ g++ unittest.cc /usr/lib/libboost_unit_test_framework.a 9 | 10 | #define BOOST_TEST_DYN_LINK 11 | #define BOOST_TEST_MAIN 12 | #include 13 | 14 | int add(int i, int j) { return i + j; } 15 | 16 | BOOST_AUTO_TEST_SUITE(adder) 17 | 18 | BOOST_AUTO_TEST_CASE(case1) { 19 | // Check for failure 20 | BOOST_CHECK(add(2, 2) == 4); 21 | 22 | // Carp on failure 23 | BOOST_REQUIRE(add(2, 2) == 4); 24 | } 25 | 26 | BOOST_AUTO_TEST_CASE(case2) { 27 | // Check for failure 28 | BOOST_CHECK(add(2, 3) == 4); 29 | 30 | // Carp on failure 31 | BOOST_REQUIRE(add(2, 2) == 4); 32 | } 33 | 34 | BOOST_AUTO_TEST_CASE(case3) { 35 | // Check for failure 36 | BOOST_CHECK(add(2, 3) == 4); 37 | 38 | // Carp on failure 39 | BOOST_REQUIRE(add(2, 2) == 4); 40 | } 41 | 42 | BOOST_AUTO_TEST_SUITE_END() 43 | -------------------------------------------------------------------------------- /cpp/brk.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char** argv) { 5 | void *last_valid_address; 6 | 7 | last_valid_address = sbrk(0); 8 | 9 | printf("last_valid_address: %p\n", last_valid_address); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /cpp/casting.cc: -------------------------------------------------------------------------------- 1 | // Author: mmuthanna@google.com (Mohit Cheppudira) 2 | 3 | #include 4 | class Object{ 5 | public: 6 | virtual int Hash() {return (int)this;} 7 | }; 8 | class A:public Object{ 9 | public: 10 | int x; 11 | A(){x=1;} 12 | }; 13 | class B:public Object{ 14 | public: 15 | int y; 16 | B(){y=2;} 17 | }; 18 | class C:public A,public B{ 19 | public: 20 | int z; 21 | C() {z=3;} 22 | }; 23 | 24 | void blah (Object * reallyC) { 25 | C* cP = dynamic_cast(reallyC); 26 | printf ("cP.x: %d cP.y: %d\n",cP->x,cP->y); 27 | } 28 | 29 | int main () { 30 | C * c= new C; 31 | A * aP=c; 32 | B * bP=c; 33 | printf ("aP.x %d bP.y: %d\n",aP->x ,bP->y); 34 | { 35 | C * cP=(C*)(void*)aP; 36 | printf ("cP.x: %d cP.y: %d\n",cP->x,cP->y); 37 | } 38 | C * cP=(C*)(void*)bP; 39 | printf ("cP.x: %d cP.y: %d\n",cP->x,cP->y); 40 | C * cPgood= (C*)bP; 41 | printf ("dyncP.x: %d dyncP.y: %d\n",cPgood->x, cPgood->y); 42 | 43 | printf("%d\n", aP->Hash()); 44 | printf("%d\n", bP->Hash()); 45 | printf("%d\n", c->A::Hash()); 46 | printf("%d\n", c->B::Hash()); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /cpp/casting_virtual.cc: -------------------------------------------------------------------------------- 1 | // Author: mmuthanna@google.com (Mohit Cheppudira) 2 | 3 | 4 | #include 5 | class Object{ 6 | public: 7 | virtual int Hash() {return (int)this;} 8 | }; 9 | class A:virtual public Object{ 10 | public: 11 | int x; 12 | A(){x=1;} 13 | }; 14 | class B:virtual public Object{ 15 | public: 16 | int y; 17 | B(){y=2;} 18 | }; 19 | class C:public A,public B{ 20 | public: 21 | int z; 22 | C() {z=3;} 23 | }; 24 | 25 | void blah (Object * reallyC) { 26 | C* cP = dynamic_cast(reallyC); 27 | printf ("cP.x: %d cP.y: %d\n",cP->x,cP->y); 28 | } 29 | 30 | int main () { 31 | C * c= new C; 32 | A * aP=c; 33 | B * bP=c; 34 | printf ("aP.x %d bP.y: %d\n",aP->x ,bP->y); 35 | { 36 | C * cP=(C*)(void*)aP; 37 | printf ("cP.x: %d cP.y: %d\n",cP->x,cP->y); 38 | } 39 | C * cP=(C*)(void*)bP; 40 | printf ("cP.x: %d cP.y: %d\n",cP->x,cP->y); 41 | C * cPgood= (C*)bP; 42 | printf ("dyncP.x: %d dyncP.y: %d\n",cPgood->x, cPgood->y); 43 | 44 | printf("%d\n", aP->Hash()); 45 | printf("%d\n", bP->Hash()); 46 | printf("%d\n", c->A::Hash()); 47 | printf("%d\n", c->B::Hash()); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /cpp/cin.cc: -------------------------------------------------------------------------------- 1 | // Author: mmuthanna@google.com (Mohit Cheppudira) 2 | // 3 | #include 4 | #include 5 | 6 | int main(int argc, char argv[]) { 7 | std::string a; 8 | 9 | std::cin >> a; 10 | std::cout << "1: " << a << std::endl; 11 | 12 | std::cin >> a; 13 | std::cout << "2: " << a << std::endl; 14 | 15 | if (a.empty()) { 16 | std::cout << "A is empty." << std::endl; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /cpp/container.cc: -------------------------------------------------------------------------------- 1 | // Author: mmuthanna@google.com (Mohit Cheppudira) 2 | // 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | template 9 | class Container { 10 | public: 11 | T internal; 12 | static Container* lastInstance; 13 | 14 | Container(T value) { 15 | internal = value; 16 | lastInstance = this; 17 | } 18 | }; 19 | 20 | int main(int argc, char** argv) { 21 | Container* str = new Container("abc"); 22 | Container* i = new Container(1); 23 | 24 | cout << str->lastInstance->internal << "\n"; 25 | } 26 | -------------------------------------------------------------------------------- /cpp/double.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Sizeof float: %d\n", sizeof(float)); 5 | printf("Sizeof double: %d\n", sizeof(double)); 6 | } 7 | -------------------------------------------------------------------------------- /cpp/interview.cpp: -------------------------------------------------------------------------------- 1 | Node* a; 2 | Node* b; 3 | 4 | Node* search (Node* cur, 5 | vector& pathA, 6 | vector& pathB, 7 | vector& curPath) { 8 | if (cur != NULL) { 9 | curPath.push_back(cur); 10 | if (cur == a) { 11 | copy(cur.begin(), cur.end(), pathA.begin()); 12 | } 13 | 14 | if (cur == b) { 15 | copy(cur.begin(), cur.end(), pathB.begin()); 16 | } 17 | 18 | if (pathA.size() > 0 && pathB.size() > 0) { 19 | return compute(pathA, pathB); 20 | } 21 | 22 | Node* answer = search(cur->lchild, pathA, pathB, curPath); 23 | if (ans != NULL) { 24 | return ans; 25 | } 26 | 27 | answer = search(cur->rchild, pathA, pathB, curPath); 28 | if (ans != NULL) { 29 | return ans; 30 | } 31 | 32 | curPath.pop_back(); 33 | 34 | return NULL; 35 | } else return NULL; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /cpp/istream.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // build with: 7 | // g++ -o istream istream.cc 8 | 9 | using namespace std; 10 | 11 | int main(int argc, char** argv) { 12 | copy(istream_iterator(cin), 13 | istream_iterator(), 14 | ostream_iterator(cout)); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /cpp/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main( int argc, char** argv ) { 4 | return asm_main(); 5 | } 6 | -------------------------------------------------------------------------------- /cpp/whileone.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(int argc, char** argv) { 6 | long c = 1; 7 | 8 | while (1) { 9 | if ((++c % 10000000) == 0) { 10 | printf("%ld\n", c); 11 | } 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /cs/hellocoffee.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 14 | -------------------------------------------------------------------------------- /emdr/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "plugins": [ 5 | "@typescript-eslint", 6 | "prettier" 7 | ], 8 | "extends": [ 9 | "eslint:recommended", 10 | "plugin:@typescript-eslint/eslint-recommended", 11 | "plugin:@typescript-eslint/recommended", 12 | "prettier" 13 | ], 14 | "rules": { 15 | "no-console": 1, // Means warning 16 | "prettier/prettier": 2 // Means error 17 | } 18 | } -------------------------------------------------------------------------------- /emdr/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | -------------------------------------------------------------------------------- /emdr/README.md: -------------------------------------------------------------------------------- 1 | # EMDR Remote 2 | 3 | ## Run 4 | 5 | ``` 6 | npm run develop 7 | ``` 8 | -------------------------------------------------------------------------------- /emdr/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 |

Remote EMDR

10 | 11 | 12 |
13 | 14 | 23 |
24 | 25 | -------------------------------------------------------------------------------- /emdr/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "emdr", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "develop": "webpack-dev-server --mode development", 9 | "build": "webpack --mode production" 10 | }, 11 | "keywords": [], 12 | "author": "", 13 | "license": "ISC", 14 | "devDependencies": { 15 | "@types/node": "^18.11.18", 16 | "@typescript-eslint/eslint-plugin": "^5.50.0", 17 | "@typescript-eslint/parser": "^5.50.0", 18 | "css-loader": "^6.7.3", 19 | "eslint": "^8.33.0", 20 | "html-webpack-plugin": "^5.5.0", 21 | "prettier": "^2.8.3", 22 | "style-loader": "^3.3.1", 23 | "ts-loader": "^9.4.2", 24 | "typescript": "^4.9.4", 25 | "webpack": "^5.75.0", 26 | "webpack-cli": "^5.0.1", 27 | "webpack-dev-server": "^4.11.1" 28 | }, 29 | "dependencies": { 30 | "axios": "^1.3.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /emdr/src/index.ts: -------------------------------------------------------------------------------- 1 | import Circle from './circle'; 2 | import Bouncer from './bouncer'; 3 | 4 | import './static/index.css' 5 | 6 | function main() { 7 | const circlebox = document.getElementById( 'circlebox' ); 8 | const width = circlebox.getBoundingClientRect().width; 9 | const bouncer = new Bouncer(new Circle(300, 300, 30).createElement("circlebox")); 10 | bouncer.setBounds(100, width - 100); 11 | 12 | const startstopEl = document.getElementById("startstop") as HTMLButtonElement; 13 | startstopEl.addEventListener("click", function() { 14 | bouncer.toggle(); 15 | startstopEl.innerHTML = bouncer.running ? "Stop" : "Start"; 16 | }); 17 | 18 | const speedEl = document.getElementById("speed") as HTMLInputElement; 19 | speedEl.addEventListener('change', function() { 20 | bouncer.setSpeed(Number(speedEl.value)); 21 | }); 22 | } 23 | 24 | main(); -------------------------------------------------------------------------------- /emdr/src/logger.ts: -------------------------------------------------------------------------------- 1 | let LOGLEVEL = 50; 2 | 3 | function log(level: number, ...args: string[]) { 4 | if (level <= LOGLEVEL) { 5 | // eslint-disable-next-line 6 | console.log(`[pitchy:${level}]`, ...args); 7 | } 8 | } 9 | 10 | function debug(...args: string[]) { 11 | log(50, ...args); 12 | } 13 | 14 | function info(...args: string[]) { 15 | log(30, ...args); 16 | } 17 | 18 | function warn(...args: string[]) { 19 | log(20, ...args); 20 | } 21 | 22 | function error(...args: string[]) { 23 | log(10, ...args); 24 | } 25 | 26 | function setLevel(level: number) { 27 | info('Setting log level to', level.toString()); 28 | LOGLEVEL = level; 29 | } 30 | 31 | export { 32 | log, debug, info, warn, error, setLevel, 33 | }; -------------------------------------------------------------------------------- /emdr/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true, 4 | "target": "ES5", 5 | "module": "ES2015" 6 | } 7 | } -------------------------------------------------------------------------------- /emdr/webpack.config.js: -------------------------------------------------------------------------------- 1 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 2 | const path = require('path'); 3 | 4 | module.exports = { 5 | entry: './src/index.ts', 6 | module: { 7 | rules: [ 8 | { test: /\.ts?$/, use: 'ts-loader', exclude: /node_modules/, }, 9 | { test: /\.css$/, use: ['style-loader', 'css-loader'] }, 10 | ], 11 | }, 12 | resolve: { 13 | extensions: ['.tsx', '.ts', '.js'], 14 | }, 15 | output: { 16 | filename: 'bundle.js', 17 | path: path.resolve(__dirname, 'dist'), 18 | }, 19 | devServer: { 20 | static: path.join(__dirname, "dist"), 21 | compress: true, 22 | port: 4000, 23 | }, 24 | plugins: [ 25 | new HtmlWebpackPlugin({ 26 | title: 'Remote EMDR', 27 | template: 'index.html' }) 28 | ], 29 | }; -------------------------------------------------------------------------------- /go/echo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ("os" 4 | "flag") 5 | 6 | var omitNewLine = flag.Bool("n", false, "Omit new line") 7 | 8 | const (Space = " "; Newline = "\n") 9 | 10 | func main() { 11 | flag.Parse() 12 | 13 | var s string = ""; 14 | 15 | for i := 0; i < flag.NArg(); i++ { 16 | if i > 0 { s += Space } 17 | 18 | s += flag.Arg(i); 19 | } 20 | 21 | if !*omitNewLine { s += Newline } 22 | 23 | os.Stdout.WriteString(s) 24 | } 25 | -------------------------------------------------------------------------------- /go/empty.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // Bottom is a valueless type 6 | type Bottom struct{} 7 | 8 | func main() { 9 | set := make(map[string]Bottom) 10 | exists := Bottom{} 11 | 12 | set["foo"] = exists 13 | set["bar"] = exists 14 | 15 | fmt.Printf("%v+\n", set) 16 | 17 | for k, v := range set { 18 | fmt.Printf("%v = %v\n", k, v) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /go/hello.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Printf("hello, world\n"); 7 | } 8 | -------------------------------------------------------------------------------- /go/parity.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // Parity is a naive parity calculator 6 | func Parity(v int64) int64 { 7 | parity := int64(0) 8 | 9 | for v > 0 { 10 | parity ^= v & 1 11 | v >>= 1 12 | } 13 | 14 | return parity 15 | } 16 | 17 | func main() { 18 | fmt.Printf("1 << 0: %v\n", 1<<0) 19 | fmt.Printf("1 << 1: %v\n", 1<<1) 20 | fmt.Printf("1 << 2: %v\n", 1<<2) 21 | fmt.Printf("1 << 3: %v\n", 1<<3) 22 | fmt.Printf("parity of 1: %v\n", Parity(1)) 23 | fmt.Printf("parity of 2: %v\n", Parity(2)) 24 | fmt.Printf("parity of 3: %v\n", Parity(3)) 25 | fmt.Printf("parity of 4: %v\n", Parity(4)) 26 | } 27 | -------------------------------------------------------------------------------- /go/wscript: -------------------------------------------------------------------------------- 1 | APPNAME = "gohello" 2 | VERSION = "1.0" 3 | 4 | top = "." 5 | out = "build" 6 | 7 | def configure(ctx): 8 | ctx.env.GOC = "6g" 9 | ctx.env.GOL = "6l" 10 | 11 | def build(ctx): 12 | sources = ["echo.go", "hello.go", "slices.go"] 13 | 14 | for file in sources: 15 | # Files with ".go" extensions are automatically compiled and linked 16 | ctx(source=file) 17 | 18 | # Remove .bin extension from file 19 | binary = file.replace(".go", "") 20 | ctx(rule="mv ${SRC} ${TGT}", source=(binary + ".bin"), target=binary) 21 | 22 | """ 23 | Code to automatically compile and link files with ".go" as their extension. 24 | """ 25 | 26 | from waflib import TaskGen 27 | 28 | TaskGen.declare_chain( 29 | name = "goc", 30 | rule = "${GOC} -o ${TGT} ${SRC}", 31 | ext_in = ".go", 32 | ext_out = ".6") 33 | 34 | TaskGen.declare_chain( 35 | name = "gol", 36 | rule = "${GOL} -o ${TGT} ${SRC}", 37 | ext_in = ".6", 38 | ext_out = ".bin", 39 | reentrant = False) 40 | -------------------------------------------------------------------------------- /haskell/First.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | import System.Environment 3 | import Text.ParserCombinators.Parsec hiding (spaces) 4 | 5 | data Picture = Picture {pic_header::String, pic_body::[Int], 6 | pic_checksum::Int} deriving Show 7 | 8 | data LispVal = Atom String 9 | List [LispVal] 10 | DottedList [LispVal] LispVal 11 | Number Integer 12 | String String 13 | Bool Bool 14 | 15 | symbol :: Parser Char 16 | symbol = oneOf "!$#%&|*+-/:<=>?@^_-" 17 | 18 | spaces :: Parser () 19 | spaces = skipMany1 space 20 | 21 | parseString :: Parser LispVal 22 | parseString = do char '"' 23 | x <- many (noneOf "\"") 24 | char '"' 25 | return $ String x 26 | 27 | readExpr :: String -> String 28 | readExpr input = case parse (spaces >> symbol) "lisp" input of 29 | Left err -> "No match: " ++ show err 30 | Right val -> "Found value" 31 | 32 | main :: IO () 33 | main = do args <- getArgs 34 | putStrLn $ readExpr (args !! 0) 35 | -------------------------------------------------------------------------------- /haskell/LineServerTest.hs: -------------------------------------------------------------------------------- 1 | import Control.Concurrent.MVar 2 | import System.IO 3 | 4 | import LineServer 5 | 6 | data State = State 7 | { payload :: String 8 | , counter :: MVar Int } 9 | 10 | myConnectHandler h = do 11 | putStrLn "New connection" 12 | hPutStrLn h "HELLO" 13 | 14 | myLineHandler state h line = do 15 | let ctrMVar = counter state 16 | ctr <- modifyMVar ctrMVar (\c -> return (c + 1, c)) 17 | hPutStrLn h $ (payload state) ++ " [" ++ (show ctr) ++ "] : " ++ line 18 | 19 | myErrHandler errMsg = putStrLn $ "Connection closed: " ++ errMsg 20 | 21 | main = do 22 | ctr <- newMVar 0 23 | 24 | h <- LineServer.init $ Options 25 | { port = "10000" 26 | , connectHandler = myConnectHandler 27 | , lineHandler = (myLineHandler (State "hsterm" ctr)) 28 | , errHandler = myErrHandler } 29 | 30 | start h 31 | -------------------------------------------------------------------------------- /haskell/PCRESubTest.hs: -------------------------------------------------------------------------------- 1 | import PCRESub 2 | 3 | main = do 4 | let text = "me boo" =~$ ("(me) boo", "he \\1") 5 | print text 6 | -------------------------------------------------------------------------------- /haskell/PNM.hs: -------------------------------------------------------------------------------- 1 | import qualified Data.ByteString.Lazy.Char8 as L8 2 | import qualified Data.ByteString.Lazy as L 3 | import Data.Char (isSpace) 4 | 5 | data Greymap = Greymap { 6 | greyWidth :: Int, 7 | greyHeight :: Int, 8 | greyMax :: Int, 9 | greyData :: L.ByteString 10 | } deriving (Eq) 11 | 12 | instance Show Greymap where 13 | show (Greymap w h m _) = "Greymap " ++ show w ++ "x" ++ 14 | show h ++ " " ++ show m 15 | 16 | parseP5 :: L.ByteString -> Maybe (Greymap, L.ByteString) 17 | 18 | main = do 19 | putStrLn "Greymap 1.0" 20 | -- print $ Greymap 4 5 6 (L.ByteString "ABC") 21 | 22 | -------------------------------------------------------------------------------- /haskell/Test.hs: -------------------------------------------------------------------------------- 1 | module Main 2 | where 3 | 4 | import IO 5 | import Random 6 | 7 | x = 5 8 | y = (6, "hello") 9 | z = x * fst y 10 | 11 | addthem x y = x + y 12 | 13 | run_this = do 14 | putStrLn ("A") 15 | putStrLn ("B") 16 | 17 | getNumbers = do 18 | putStrLn "enter a number: " 19 | word <- getLine 20 | 21 | if read word == 0 22 | then return [] 23 | else do 24 | rest <- getNumbers 25 | return ((read word :: Int ): rest) 26 | 27 | showNumbers [] = return () 28 | showNumbers (x:xs) = do 29 | putStrLn (show x) 30 | showNumbers xs 31 | 32 | my_min :: [a] -> Maybe a 33 | my_min [] = Nothing 34 | my_min (x:xs) = do 35 | min <- read my_min xs 36 | if min < x 37 | then Just min 38 | else Just x 39 | 40 | 41 | main = do 42 | numbers <- getNumbers 43 | showNumbers numbers 44 | putStrLn ("Minimum: ") 45 | 46 | min <- my_min numbers 47 | putStrLn (show min) 48 | -------------------------------------------------------------------------------- /haskell/TokenBucketTest.hs: -------------------------------------------------------------------------------- 1 | -- Test harness for TokenBucket module. 2 | -- Mohit Cheppudira 3 | 4 | import TokenBucket 5 | 6 | main :: IO () 7 | main = TokenBucket.test 8 | -------------------------------------------------------------------------------- /haskell/avg.hs: -------------------------------------------------------------------------------- 1 | -- Custom average function calculates the length and sum in 2 | -- a single iteration. 3 | 4 | import System (getArgs) 5 | 6 | avg (x:xs) (sum,len) = avg xs ((x + sum), (len + 1)) 7 | avg [] (sum,len) = sum / (fromIntegral len) 8 | 9 | average xs = avg xs (0,0) 10 | 11 | main = do 12 | args <- getArgs 13 | 14 | if length args > 0 15 | then putStrLn $ show $ average [1 .. (read $ args!!0)] 16 | else putStrLn "Usage: avg " 17 | -------------------------------------------------------------------------------- /haskell/binary.hs: -------------------------------------------------------------------------------- 1 | import qualified Data.ByteString.Lazy.Char8 as L8 2 | import Control.Monad 3 | import Control.Applicative 4 | import Data.Char 5 | 6 | hello :: L8.ByteString 7 | hello = L8.pack "Hello World" 8 | 9 | ordify :: L8.ByteString -> [Int] 10 | ordify s = map ord (L8.unpack s) 11 | 12 | main = do 13 | L8.putStrLn hello 14 | print hello 15 | print $ ordify hello 16 | 17 | -- <$> = fmap 18 | ordify <$> (L8.readFile "binaryfile") >>= print 19 | 20 | -- same as above 21 | (L8.readFile "binaryfile") >>= (print . ordify) 22 | -------------------------------------------------------------------------------- /haskell/binaryfile: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /haskell/chan.hs: -------------------------------------------------------------------------------- 1 | import Control.Concurrent 2 | import Control.Concurrent.Chan 3 | import Control.Monad 4 | import Ix 5 | 6 | chanExample = do 7 | -- Create channel 8 | chan <- newChan 9 | 10 | -- Spawn 10 threads and send messages to the channel. 11 | forM_ (range (1,10)) (\i -> forkIO $ writeChan chan (show i)) 12 | 13 | -- Read messages from the channel. 14 | replicateM_ 10 (readChan chan >>= print) 15 | 16 | main = chanExample 17 | -------------------------------------------------------------------------------- /haskell/concat.hs: -------------------------------------------------------------------------------- 1 | concatS:: String -> String -> String 2 | concatS s1 s2 = s1 ++ s2 3 | 4 | showI :: Int -> String 5 | showI i = show i 6 | 7 | -- g :: String -> Int -> String 8 | g n s = concatS (showI n) s 9 | 10 | -- foldright :: (String -> Int -> String) -> String -> [Int] -> String 11 | foldright h y [] = y 12 | foldright h y (x:xs) = h x (foldright h y xs) 13 | 14 | -- f :: [Int] -> String 15 | f l = foldright g "" l 16 | 17 | main = do 18 | print $ f [1,4,5] 19 | -------------------------------------------------------------------------------- /haskell/debugging.hs: -------------------------------------------------------------------------------- 1 | import Debug.Trace 2 | 3 | -- A neat debugging trick. Use "trace" in a guard that always fails 4 | -- to log a message every time the function is evaluated. 5 | 6 | f :: Int -> Int 7 | f n | trace ("f was called: " ++ show n) False = undefined 8 | f 0 = 1 9 | f n = n * f (n - 1) 10 | 11 | 12 | main = do 13 | print $ f 7 14 | -------------------------------------------------------------------------------- /haskell/elf.hs: -------------------------------------------------------------------------------- 1 | -- Usage: elf 2 | 3 | import qualified Data.ByteString.Lazy as L 4 | import System (getArgs) 5 | 6 | hasElfMagic :: L.ByteString -> Bool 7 | hasElfMagic content = L.take 4 content == elfMagic 8 | where elfMagic = L.pack [0x7f, 0x45, 0x4c, 0x46] 9 | 10 | isElfFile :: FilePath -> IO Bool 11 | isElfFile path = do 12 | content <- L.readFile path 13 | return $ hasElfMagic content 14 | 15 | main = do 16 | args <- getArgs 17 | isElf <- isElfFile $ args !! 0 18 | putStrLn $ if isElf then "ELF" else "NOT ELF" 19 | -------------------------------------------------------------------------------- /haskell/euler1.hs: -------------------------------------------------------------------------------- 1 | -- Project Euler: Problem 1 2 | -- Author: Mohit Muthanna Cheppudira 3 | -- 4 | -- If we list all the natural numbers below 10 that are multiples of 3 or 5, 5 | -- we get 3, 5, 6 and 9. The sum of these multiples is 23. 6 | -- 7 | -- Find the sum of all the multiples of 3 or 5 below 1000. 8 | 9 | import System (getArgs) 10 | 11 | sum35 :: Int -> Int 12 | sum35 n = sum $ filter multiple35 $ [1..n-1] 13 | where multiple35 a = any ((== 0) . (a `mod`)) [3, 5] 14 | 15 | main :: IO () 16 | main = do 17 | a <- getArgs 18 | print $ sum35 $ if length a == 0 then 1000 else read $ a !! 0 19 | -------------------------------------------------------------------------------- /haskell/euler10.hs: -------------------------------------------------------------------------------- 1 | -- Project Euler: Problem 10 2 | -- Author: Mohit Muthanna Cheppudira 3 | -- 4 | -- Calculate the sum of all the primes below two million. 5 | 6 | import System (getArgs) 7 | 8 | -- Memoized prime number generator. 9 | primes :: Integral a => [a] 10 | primes = 3 : 5 : filter (not . hasFactor) [7,9..] 11 | where hasFactor n = any (divides n) $ takeWhile (<= lowestFactor n) primes 12 | divides n m = n `mod` m == 0 13 | lowestFactor = ceiling . sqrt . fromIntegral 14 | 15 | euler10 :: Int -> Int 16 | euler10 limit = sum $ takeWhile (< limit) (primes :: [Int]) 17 | 18 | main :: IO () 19 | main = do 20 | a <- getArgs 21 | print $ euler10 $ defaultArg a 2000000 22 | where defaultArg a b = if length a == 0 then b else read $ a !! 0 23 | -------------------------------------------------------------------------------- /haskell/euler2.hs: -------------------------------------------------------------------------------- 1 | -- Project Euler: Problem 2 2 | -- Author: Mohit Muthanna Cheppudira 3 | -- 4 | -- Each new term in the Fibonacci sequence is generated by adding the previous 5 | -- two terms. By starting with 1 and 2, the first 10 terms will be: 6 | -- 7 | -- 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... 8 | -- 9 | -- Find the sum of all the even-valued terms in the sequence which do not 10 | -- exceed four million. 11 | 12 | import System (getArgs) 13 | 14 | -- Simple memoized Fibonacci sequence 15 | fibs :: [Integer] 16 | fibs = map genFib [0..] 17 | where 18 | genFib 0 = 0 19 | genFib 1 = 1 20 | genFib 2 = 2 21 | genFib x = (fibs !! (x - 1)) + (fibs !! (x - 2)) 22 | 23 | -- Solving Euler 2 for arbitrary limit 24 | euler2 :: Integer -> Integer 25 | euler2 limit = sum $ filter (not . odd) (takeWhile ( [Integer] 19 | primeFactors n = takeUntil allFactorsFound [] $ filter isFactor primes 20 | where takeUntil d acc (x:xs) = 21 | if d (x:acc) then (x:acc) else takeUntil d (x:acc) xs 22 | allFactorsFound acc = product acc == n 23 | isFactor m = n `mod` m == 0 24 | 25 | main :: IO () 26 | main = do 27 | a <- getArgs 28 | print $ maximum $ primeFactors $ defaultArg a 600851475143 29 | where defaultArg a b = if length a == 0 then b else read $ a !! 0 30 | -------------------------------------------------------------------------------- /haskell/euler7.hs: -------------------------------------------------------------------------------- 1 | -- Project Euler: Problem 7 2 | -- Author: Mohit Muthanna Cheppudira 3 | -- 4 | -- Find the 10001st Prime 5 | 6 | import System (getArgs) 7 | 8 | -- Memoized prime number generator. 9 | primes :: [Int] 10 | primes = 2 : 3 : 5 : filter (not . hasFactor) [7..] 11 | where hasFactor n = any (divides n) $ takeWhile (<= lowestFactor n) primes 12 | divides n m = n `mod` m == 0 13 | lowestFactor = ceiling . sqrt . fromIntegral 14 | 15 | main :: IO () 16 | main = do 17 | a <- getArgs 18 | print $ primes !! ((defaultArg a 10001) - 1) 19 | where defaultArg a b = if length a == 0 then b else read $ a !! 0 20 | -------------------------------------------------------------------------------- /haskell/factrec.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE FlexibleInstances #-} 2 | 3 | y f = f $ y ( f ) 4 | 5 | factRec g x = case x of 6 | 0 -> 1 7 | _ -> x * (g (x - 1)) 8 | 9 | fact = y factRec 10 | 11 | fibRec g x = case x of 12 | 0 -> 0 13 | 1 -> 1 14 | _ -> (g (x - 1) + g (x - 2)) 15 | 16 | fib = y fibRec 17 | 18 | reduceRec g f l = case l of 19 | [] -> undefined 20 | [x] -> x 21 | (x : xs) -> f x (g f xs) 22 | 23 | reduce = y reduceRec 24 | -------------------------------------------------------------------------------- /haskell/file.hs: -------------------------------------------------------------------------------- 1 | module Main 2 | where 3 | 4 | import IO 5 | 6 | file = "file.txt" 7 | 8 | process :: String -> Int 9 | process contents = 10 | let x = read $ take 1 contents in 11 | x + 1 12 | 13 | main = do 14 | bracket (openFile file ReadMode) hClose 15 | (\h -> do contents <- hGetContents h 16 | putStrLn $ show $ process contents) 17 | putStrLn "All done!" 18 | -------------------------------------------------------------------------------- /haskell/file.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | -------------------------------------------------------------------------------- /haskell/fold.hs: -------------------------------------------------------------------------------- 1 | main = do 2 | -- This won't compile. 3 | -- print $ foldl (:) [] [1..10] -- Does not compile, obviously! 4 | print $ foldr (:) [] [1..10] 5 | 6 | -- These work 7 | print $ foldl (+) 0 [1..10] 8 | print $ foldr (+) 0 [1..10] 9 | -------------------------------------------------------------------------------- /haskell/hello.hs: -------------------------------------------------------------------------------- 1 | -- Haskell is very very fast, so if you're calling this, you 2 | -- should be throttling. 3 | shouldThrottle = True 4 | 5 | main = do 6 | putStrLn "Hello World!" 7 | -------------------------------------------------------------------------------- /haskell/hexdump.hs: -------------------------------------------------------------------------------- 1 | -- Usage: hexdump 2 | -- Author: Mohit Cheppudira 3 | 4 | import Control.Monad (when) 5 | import Data.Char 6 | import Data.List 7 | import Numeric 8 | import qualified Data.ByteString.Lazy as L 9 | import System.Exit 10 | import System (getArgs) 11 | import Text.Printf 12 | 13 | bytesPerLine = 16 14 | 15 | toHex c = showIntAtBase 16 intToDigit c "" 16 | toHexList = (map $ printf "%02s" . toHex) . L.unpack 17 | 18 | fileToHex path = do 19 | content <- L.readFile path 20 | return $ toHexList content 21 | 22 | formatList 0 _ = error "x < 1" 23 | formatList x [] = [] 24 | formatList x l = h : formatList x t 25 | where (h, t) = splitAt x l 26 | 27 | showWithAddress [] _ = [] 28 | showWithAddress (x:xs) a = prettify : showWithAddress xs (a + bytesPerLine) 29 | where prettify = (toHex a) ++ " " ++ (intercalate " " x) 30 | 31 | showHexFile file = do 32 | hexData <- fileToHex $ file 33 | mapM putStrLn $ showWithAddress (formatList bytesPerLine hexData) 0 34 | 35 | main = do 36 | args <- getArgs 37 | 38 | when (length args /= 1) $ do 39 | putStrLn "Syntax: hexdump " 40 | exitFailure 41 | 42 | showHexFile $ args !! 0 43 | -------------------------------------------------------------------------------- /haskell/http.hs: -------------------------------------------------------------------------------- 1 | import Control.Monad 2 | import Control.Applicative 3 | import Data.Maybe 4 | import Network.HTTP 5 | import Network.URI 6 | import System (getArgs) 7 | 8 | downloadURL :: String -> IO (Either String String) 9 | downloadURL url = 10 | do resp <- simpleHTTP request 11 | case resp of 12 | Left x -> return $ Left $ "Error: " ++ show x 13 | Right r -> 14 | case rspCode r of 15 | (2, _, _) -> return $ Right (rspBody r) 16 | _ -> return $ Left $ "Error: " ++ show r 17 | where request = Request { rqURI = uri, 18 | rqMethod = GET, 19 | rqHeaders = [], 20 | rqBody = "" } 21 | uri = fromJust $ parseURI url 22 | 23 | wget :: String -> IO String 24 | wget url = do 25 | body <- downloadURL url 26 | case body of 27 | Left x -> return x 28 | Right r -> return r 29 | 30 | main :: IO () 31 | main = do 32 | args <- getArgs 33 | if length args == 0 34 | then putStrLn "Usage: http.hs url" 35 | else putStrLn =<< (wget $ args !! 0) 36 | 37 | -------------------------------------------------------------------------------- /haskell/interact.hs: -------------------------------------------------------------------------------- 1 | import System.Environment (getArgs) 2 | import Data.Char 3 | 4 | upperify = map toUpper 5 | 6 | interactWith function inputFile outputFile = do 7 | input <- readFile inputFile 8 | writeFile outputFile (function input) 9 | 10 | main = mainWith myFunction 11 | where mainWith function = do 12 | args <- getArgs 13 | case args of 14 | [input, output] -> interactWith function input output 15 | _ -> putStrLn "error: two arguments needed" 16 | 17 | myFunction = upperify 18 | -------------------------------------------------------------------------------- /haskell/io.hs: -------------------------------------------------------------------------------- 1 | -- times :: Integer -> a -> m () 2 | times 0 f = return () 3 | times x f = do 4 | f 5 | times (x - 1) f 6 | 7 | -- This works because the type of main is IO t 8 | main = do 9 | putStrLn "How many more times?" 10 | inpStr <- getLine 11 | times (read inpStr) (putStrLn "Hello") 12 | 13 | -------------------------------------------------------------------------------- /haskell/join.hs: -------------------------------------------------------------------------------- 1 | join :: String -> [String] -> String 2 | join s (x : []) = x 3 | join s (x : xs) = x ++ s ++ (join s xs) 4 | join s [] = [] 5 | 6 | 7 | main = do 8 | print $ join ", " ["a", "b", "c"] 9 | -------------------------------------------------------------------------------- /haskell/list.hs: -------------------------------------------------------------------------------- 1 | remove_second xs = 2 | head xs : tail (tail xs) 3 | 4 | main = do 5 | print $ remove_second [1, 2, 3, 4, 5, 6] 6 | -------------------------------------------------------------------------------- /haskell/logger.hs: -------------------------------------------------------------------------------- 1 | -- Build a logger monad, and use it in an operation 2 | 3 | type Log = [String] 4 | 5 | newtype Logger a = Logger { execLogger :: (a, Log) } 6 | 7 | -- Here runLogger is aliased to execLogger. This works because 8 | -- execLogger is a function that takes a Logger and returns the 9 | -- associated data element: (a, Log). 10 | runLogger :: Logger a -> (a, Log) 11 | runLogger = execLogger 12 | 13 | -- Return nothing, just log the string. 14 | record s = Logger ((), [s]) 15 | 16 | instance Monad Logger where 17 | -- Return a, log nothing 18 | return a = Logger (a, []) 19 | 20 | -- The magic happens here. Execute m then k, and concatenate 21 | -- the associated log message array. 22 | m >>= k = let (a, w) = execLogger m 23 | n = k a 24 | (b, x) = execLogger n 25 | in Logger (b, w ++ x) 26 | 27 | 28 | main = do print $ runLogger $ 29 | do record "Hello World!" 30 | return 3.1337 31 | -------------------------------------------------------------------------------- /haskell/max.hs: -------------------------------------------------------------------------------- 1 | module Main 2 | where 3 | 4 | import System 5 | 6 | type Person = String 7 | type Book = String 8 | 9 | type Database = [ (Person, Book) ] 10 | 11 | exampleBase :: Database 12 | exampleBase = [ ("Mohit", "Life of Pi"), ("Anna", "Asterix"), 13 | ("Jon", "Slaves to the Grind"), ("Mohit", "Machine Learning")] 14 | 15 | borrow :: Database -> Person -> Book -> Database 16 | borrow d p b = (p, b):d 17 | 18 | maxarr :: [Int] -> Int 19 | maxarr (x:xs) | xs == [] = x 20 | | otherwise = max x (maxarr xs) 21 | maxarr [] = 0 22 | 23 | minarr :: [Int] -> Int 24 | minarr (x:xs) 25 | | xs == [] = x 26 | | otherwise = min x (minarr xs) 27 | minarr [] = 0 28 | 29 | sumarr :: [Int] -> Int 30 | sumarr [] = 0 31 | sumarr (x:xs) = x + (sumarr xs) 32 | 33 | main = do 34 | args <- getArgs 35 | let arr = map read args 36 | print arr 37 | putStrLn $ "Maximum: " ++ (show $ maxarr arr) 38 | putStrLn $ "Minimum: " ++ (show $ minarr arr) 39 | putStrLn $ "Sum: " ++ (show $ sumarr arr) 40 | print exampleBase 41 | print $ borrow exampleBase "George" "The World is Flat" 42 | -------------------------------------------------------------------------------- /haskell/maybe.hs: -------------------------------------------------------------------------------- 1 | import Data.Maybe 2 | 3 | main = do 4 | print $ Just "just" 5 | print $ fromMaybe "Nothing" $ Just "just" 6 | -------------------------------------------------------------------------------- /haskell/min.hs: -------------------------------------------------------------------------------- 1 | mymin :: (Ord a) => a -> a -> a 2 | mymin a b = if a < b then a 3 | else b 4 | 5 | mymax :: (Ord a) => a -> a -> a 6 | mymax a b = if a > b then a 7 | else b 8 | 9 | minarr :: (Ord a) => [a] -> Maybe a 10 | minarr [] = Nothing 11 | minarr xs = Just $ helper xs 12 | where helper (x : []) = x 13 | helper (x : xs) = mymin x (helper xs) 14 | 15 | minarr2 :: (Ord a) => [a] -> Maybe a 16 | minarr2 [] = Nothing 17 | minarr2 (x : xs) = Just $ foldr mymin x xs 18 | 19 | fromMaybe :: a -> Maybe a -> a 20 | fromMaybe defval Nothing = defval 21 | fromMaybe defval (Just a) = a 22 | 23 | main = do 24 | print $ mymin 4 5 25 | print $ mymax 4 5 26 | print $ fromMaybe (-1) (minarr [12, 4, 5, 76, 3, 4, 4, 8, 43]) 27 | print $ fromMaybe (-1) (minarr2 [12, 4, 5, 76, 3, 4, 4, 8, 43]) 28 | print $ fromMaybe (-1) (minarr2 []) 29 | -------------------------------------------------------------------------------- /haskell/mvar.hs: -------------------------------------------------------------------------------- 1 | import Control.Concurrent 2 | import Control.Monad 3 | import Ix (range) 4 | 5 | communicate :: Int -> IO () 6 | communicate n = do 7 | m <- newEmptyMVar 8 | 9 | thread_list <- forM (range (1, n)) $ \i -> forkIO $ putMVar m i 10 | 11 | putStrLn $ "Started threads: " ++ show thread_list 12 | 13 | replicateM_ n $ do 14 | v <- takeMVar m 15 | putStrLn $ "Got: " ++ show v 16 | 17 | main :: IO () 18 | main = communicate 10 19 | -------------------------------------------------------------------------------- /haskell/pardata.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE PArr #-} 2 | 3 | -- Testing Parallel Arrays 4 | -- $ ghc --make -threaded -fdph-par -fforce-recomp pardata.hs 5 | -- $ ./pardata +RTS -N2 6 | 7 | import Data.Array.Parallel.Prelude 8 | import qualified Data.Array.Parallel.Prelude.Double as D 9 | 10 | sumSq :: [: Double :] -> Double 11 | sumSq a = D.sumP (mapP (\x -> x * x) a) 12 | 13 | main :: IO () 14 | main = do 15 | let sum = sumSq [: 4, 5, 6, 3.2, 5.3, 45.2 :] 16 | putStrLn $ show sum 17 | -------------------------------------------------------------------------------- /haskell/picture.hs: -------------------------------------------------------------------------------- 1 | module Main where 2 | 3 | import Data.List 4 | 5 | type PictureHeader = String 6 | type PictureBody = [Int] 7 | type Checksum = Int 8 | 9 | data Picture = Picture { 10 | pic_header :: PictureHeader, 11 | pic_body :: PictureBody, 12 | pic_checksum :: Checksum 13 | } deriving Show 14 | 15 | validPic p = 16 | case pic_header p of 17 | "" -> Nothing 18 | _ -> Just "Valid" 19 | 20 | fromMaybe defval wrapped = 21 | case wrapped of 22 | Nothing -> defval 23 | Just value -> value 24 | 25 | main = do 26 | let p = Picture "Hello" [1,2,3] 5 27 | let q = Picture "" [1, 2, 3] 6 28 | 29 | print p 30 | print q 31 | 32 | putStrLn $ "Picture header: " ++ pic_header (p) 33 | 34 | putStrLn $ "Valid: " ++ (fromMaybe "Invalid" $ validPic (p)) 35 | putStrLn $ "Valid: " ++ (fromMaybe "Invalid" $ validPic (q)) 36 | -------------------------------------------------------------------------------- /haskell/powerset.hs: -------------------------------------------------------------------------------- 1 | powerSet' = foldr (\x -> concatMap (\xs -> [x:xs,xs])) [[]] 2 | 3 | main = do 4 | print $ powerSet' ['m', 'o', 'h', 'i', 't'] 5 | -------------------------------------------------------------------------------- /haskell/quicksort.hs: -------------------------------------------------------------------------------- 1 | -- quick and dirty super simple quicksort functions 2 | 3 | sort (x:xs) = lesser ++ x:greater 4 | where lesser = sort $ filter (x) xs 6 | sort _ = [] 7 | 8 | sort1 (x:xs) = (pivot (x) 9 | where pivot f = sort1 $ filter f xs 10 | sort1 _ = [] 11 | 12 | sort2 (x:xs) = sort2 [y | y <-xs, y < x] ++ x : sort2 [y | y <-xs, y > x] 13 | sort2 _ = [] 14 | 15 | sort3 (x:xs) = (sort3 $ filter (x) xs) 16 | sort3 _ = [] 17 | 18 | myarray = [3,4,6,2,4,1,39,4,48,3,43,23,18,04] 19 | 20 | main = do print $ sort myarray 21 | print $ sort1 myarray 22 | print $ sort2 myarray 23 | print $ sort3 myarray 24 | -------------------------------------------------------------------------------- /haskell/random.hs: -------------------------------------------------------------------------------- 1 | module Main 2 | where 3 | 4 | import IO 5 | import Random 6 | 7 | doGuessing num = do 8 | putStrLn "Your guess?" 9 | guess <- getLine 10 | let guessNum = read guess 11 | if guessNum < num 12 | then do putStrLn "Too low!" 13 | doGuessing num 14 | else if guessNum > num 15 | then do putStrLn "Too high" 16 | doGuessing num 17 | else do putStrLn "Correct!" 18 | 19 | main = do 20 | hSetBuffering stdin LineBuffering 21 | num <- randomRIO(1::Int, 100) 22 | putStrLn "I'm thinking of a number between 1 and 100" 23 | doGuessing num 24 | -------------------------------------------------------------------------------- /haskell/readert.hs: -------------------------------------------------------------------------------- 1 | import Control.Monad.Reader 2 | 3 | doThis :: ReaderT String IO () 4 | doThis = do 5 | val <- ask 6 | liftIO . putStrLn $ val 7 | 8 | main = do 9 | runReaderT doThis "Boo" 10 | -------------------------------------------------------------------------------- /haskell/readline.hs: -------------------------------------------------------------------------------- 1 | -- Test the readline library, with history recall. 2 | 3 | module Main (main) where 4 | 5 | import IO 6 | import Maybe 7 | import System.Console.Readline 8 | 9 | getline :: IO String 10 | getline = do 11 | line <- readline "> " 12 | let parsed_line = fromJust line 13 | addHistory parsed_line 14 | return $ parsed_line 15 | 16 | main :: IO () 17 | main = do 18 | line <- getline 19 | if line == "q" 20 | then return () 21 | else main 22 | -------------------------------------------------------------------------------- /haskell/regsub.hs: -------------------------------------------------------------------------------- 1 | import Text.Regex 2 | import Text.Regex.PCRE 3 | 4 | main = print $ subRegex (mkRegex "(me) boo") "me boo" "he \\1" 5 | -------------------------------------------------------------------------------- /haskell/renamer.hs: -------------------------------------------------------------------------------- 1 | -- Requires PCRE 2 | -- 3 | -- cabal install regex-pcre 4 | 5 | import Control.Applicative 6 | import Control.Monad 7 | import Data.List 8 | import System 9 | import System.Posix.Directory 10 | import System.Posix.Files 11 | import Text.Regex.PCRE 12 | 13 | ls :: String -> IO ExitCode 14 | ls params = system $ "ls " ++ params 15 | 16 | getDirEntries :: FilePath -> IO [FilePath] 17 | getDirEntries dir = openDirStream dir >>= start 18 | where start s = readDirStream s >>= rest s 19 | rest s "" = return [] 20 | rest s entry = liftM (entry:) (start s) 21 | 22 | main :: IO () 23 | main = do 24 | if length args < 2 25 | then putStrLn "Usage: renamer dir match" 26 | else do 27 | files <- getDirEntries $ args !! 0 28 | let matches = filter (=~ (args !! 1)) files 29 | print matches 30 | -------------------------------------------------------------------------------- /haskell/splitlines.hs: -------------------------------------------------------------------------------- 1 | -- Cross platfrom line-splitting. 2 | -- Better than 'lines' 3 | 4 | splitLines [] = [] 5 | splitLines cs = 6 | let (pre, suf) = break isNewLine cs 7 | in pre : case suf of 8 | ('\r':'\n':rest) -> splitLines rest 9 | ('\r':rest) -> splitLines rest 10 | ('\n':rest) -> splitLines rest 11 | _ -> [] 12 | 13 | isNewLine c = c == '\r' || c == '\n' 14 | 15 | main = do 16 | print $ splitLines "Hello\nHow\rAre\r\nYou?" 17 | 18 | -------------------------------------------------------------------------------- /haskell/stmonad.hs: -------------------------------------------------------------------------------- 1 | import Control.Monad.ST.Lazy 2 | import Data.STRef.Lazy 3 | 4 | for (a, n) f = if a > n then return () 5 | else do 6 | f a 7 | for (a + 1, n) f 8 | 9 | showA n = runST $ do 10 | r <- newSTRef 0 11 | for (1, n) (\x -> do 12 | val <- readSTRef r 13 | writeSTRef r (val + 1) 14 | ) 15 | readSTRef r 16 | 17 | main = do print $ showA 5 18 | -------------------------------------------------------------------------------- /haskell/suffixes.hs: -------------------------------------------------------------------------------- 1 | import Data.List 2 | 3 | suffixes (x:xs) = (x:xs) : suffixes xs 4 | suffixes [] = [] 5 | 6 | suffixes2 = init . tails 7 | 8 | suffixes3 xs@(x:xs') = xs : suffixes xs' 9 | suffixes3 _ = [] 10 | 11 | main = do 12 | print $ suffixes "foobar" 13 | print $ suffixes2 "foobar" 14 | print $ suffixes3 "foobar" 15 | -------------------------------------------------------------------------------- /haskell/t1.hs: -------------------------------------------------------------------------------- 1 | import Data.Char 2 | 3 | data Tree a = TreeNode (Tree a) (Tree a) a | LeafNode a 4 | deriving (Show) 5 | 6 | process = map toUpper 7 | 8 | tree = TreeNode (LeafNode "a") (LeafNode "b") "r" 9 | 10 | main = do 11 | putStrLn "What's your name, bozo?" 12 | s <- getLine 13 | putStrLn $ "Hello " ++ (process s) ++ "!" 14 | putStrLn $ show tree 15 | -------------------------------------------------------------------------------- /haskell/typeclass.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE TypeSynonymInstances #-} 2 | 3 | data JValue = JBool Bool | 4 | JString String 5 | deriving (Show) 6 | 7 | class JSON a where 8 | toJValue :: a -> JValue 9 | fromJValue :: JValue -> Maybe a 10 | 11 | instance JSON JValue where 12 | toJValue = id 13 | fromJValue = Just 14 | 15 | instance JSON Bool where 16 | toJValue = JBool 17 | fromJValue (JBool b) = Just b 18 | fromJValue _ = Nothing 19 | 20 | fromMaybe defval Nothing = defval 21 | fromMaybe defval (Just v) = v 22 | 23 | main = do 24 | print $ fromMaybe "Nothing" (Just "A") 25 | print $ fromMaybe "Nothing" Nothing 26 | print $ toJValue True 27 | print $ ((fromJValue (toJValue False)) :: Maybe Bool) 28 | -------------------------------------------------------------------------------- /haskell/udpserver.hs: -------------------------------------------------------------------------------- 1 | import Data.Bits 2 | import Network.Socket 3 | import Network.BSD 4 | import Data.List 5 | 6 | type HandlerFunc = SockAddr -> String -> IO () 7 | 8 | getAddress port = do 9 | addressinfos <- addresses 10 | return $ head addressinfos 11 | where addresses = getAddrInfo 12 | (Just (defaultHints {addrFlags = [AI_PASSIVE]})) 13 | Nothing (Just port) 14 | 15 | udpServer :: String -> HandlerFunc -> IO () 16 | udpServer port handlerfunc = withSocketsDo $ 17 | do 18 | serveraddr <- getAddress port 19 | sock <- socket (addrFamily serveraddr) Datagram defaultProtocol 20 | bindSocket sock (addrAddress serveraddr) 21 | procMessages sock 22 | where procMessages sock = 23 | do 24 | (msg, _, addr) <- recvFrom sock 1024 25 | handlerfunc addr msg 26 | procMessages sock 27 | 28 | 29 | plainHandler :: HandlerFunc 30 | plainHandler addr msg = 31 | putStrLn $ "From " ++ show addr ++ ": " ++ msg 32 | 33 | main = do 34 | let portNum = "8888" 35 | serveraddr <- getAddress portNum 36 | putStrLn $ "Listening on " ++ (show $ addrAddress serveraddr) ++ "/udp" 37 | udpServer portNum plainHandler 38 | -------------------------------------------------------------------------------- /haskell/unlines.hs: -------------------------------------------------------------------------------- 1 | import System.Environment (getArgs) 2 | 3 | splitLines [] = [] 4 | splitLines cs = 5 | let (pre, suf) = break isNewLine cs 6 | in pre : case suf of 7 | ('\r':'\n':rest) -> splitLines rest 8 | ('\r':rest) -> splitLines rest 9 | ('\n':rest) -> splitLines rest 10 | _ -> [] 11 | 12 | isNewLine c = c == '\r' || c == '\n' 13 | 14 | interactWith function inputFile outputFile = do 15 | input <- readFile inputFile 16 | writeFile outputFile (function input) 17 | 18 | fixLines input = unlines (splitLines input) 19 | 20 | main = mainWith myFunction 21 | where mainWith function = do 22 | args <- getArgs 23 | case args of 24 | [input, output] -> interactWith function input output 25 | _ -> putStrLn "error: two arguments needed" 26 | 27 | myFunction = fixLines 28 | -------------------------------------------------------------------------------- /haskell/unwrapio.hs: -------------------------------------------------------------------------------- 1 | -- You can't unwrap an IO because it's a data constructor that's not 2 | -- in scope. 3 | 4 | somestring = return "ABC" 5 | 6 | unwrap (IO a) = a 7 | 8 | stuff = unwrap somestring 9 | 10 | main = do 11 | putStrLn stuff 12 | -------------------------------------------------------------------------------- /haskell/vector.hs: -------------------------------------------------------------------------------- 1 | data Vector a = Vector a a a 2 | deriving (Show) 3 | 4 | sumof :: (Num t) => Vector t -> t 5 | sumof (Vector a b c) = a + b + c 6 | 7 | main :: IO () 8 | main = do 9 | print $ sumof (Vector 1 2 3) 10 | print $ "Is all" 11 | -------------------------------------------------------------------------------- /haskell/wc.hs: -------------------------------------------------------------------------------- 1 | main = interact wordCount 2 | where wordCount input = show (length (lines input)) ++ "\n" 3 | -------------------------------------------------------------------------------- /haskell/xmlrep.hs: -------------------------------------------------------------------------------- 1 | data H_XML = Tag { name::String, children::[H_XML]} 2 | | Value { name::String, value::String } 3 | 4 | instance Show H_XML where 5 | show x = xml_show x 6 | 7 | instance Read H_XML where 8 | read x = xml_read x 9 | 10 | class XML_Rep a where 11 | toXML :: a -> H_XML 12 | fromXML :: H_XML -> a 13 | 14 | xml_show x = "String" 15 | xml_read x = Tag "Nothing" [Value "Int" "One"] 16 | 17 | main = do 18 | print $ show $ read "A" 19 | -------------------------------------------------------------------------------- /images/cleanup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | INPUT=$1 4 | OUTPUT=$2 5 | TMP=/tmp/snfsoudnf 6 | 7 | if [ "$2" == "" ]; then 8 | echo "Usage: $0 input output" 9 | exit 10 | fi 11 | 12 | echo Blurring... 13 | convert $INPUT -threshold '85%' -gaussian-blur 20 -quality 20 ${TMP}1.jpg 14 | 15 | echo Tracing... 16 | autotrace -despeckle-level 9 -despeckle-tightness 0.6 \ 17 | -error-threshold 1 -output-format pdf -filter-iterations 8 \ 18 | -report-progress ${TMP}1.jpg >${TMP}2.pdf 19 | 20 | echo Downsampling... 21 | convert ${TMP}2.pdf -quality 20 $OUTPUT 22 | -------------------------------------------------------------------------------- /java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/.DS_Store -------------------------------------------------------------------------------- /java/AdviceGuy.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.*; 3 | 4 | public class AdviceGuy { 5 | String[] adviceList = { 6 | "Take smaller bites", 7 | "One word: inappropriate", 8 | "Just for today, be honest. Lie tomorrow", 9 | "You might want to rethink that haircut" 10 | }; 11 | 12 | boolean running = true; 13 | 14 | public void go() { 15 | try { 16 | ServerSocket s = new ServerSocket(4242); 17 | 18 | while (running) { 19 | Socket sock = s.accept(); 20 | new Thread(new AdvisorThread(sock)).start(); 21 | } 22 | } catch (IOException ex) { 23 | ex.printStackTrace(); 24 | } 25 | } 26 | 27 | public class AdvisorThread implements Runnable { 28 | Socket sock; 29 | 30 | public AdvisorThread(Socket s) { 31 | sock = s; 32 | } 33 | 34 | public void run() { 35 | try { 36 | PrintWriter writer = new PrintWriter(sock.getOutputStream()); 37 | writer.println(adviceList[(int) (Math.random() * adviceList.length)]); 38 | writer.close(); 39 | } catch (IOException ex) { 40 | ex.printStackTrace(); 41 | } 42 | } 43 | } 44 | 45 | 46 | public static void main(String[] args) { 47 | new AdviceGuy().go(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /java/Dog.java: -------------------------------------------------------------------------------- 1 | class Dog { 2 | int vigour; 3 | String name; 4 | 5 | public Dog() { 6 | name = "Nobody"; 7 | vigour = 1; 8 | } 9 | 10 | public void bark() { 11 | String bark = ""; 12 | int x = 0; 13 | 14 | for (x = 0; x < vigour; x++) { 15 | bark += "Ruff!! "; 16 | } 17 | 18 | System.out.println(name + ": " + bark); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /java/DogTester.java: -------------------------------------------------------------------------------- 1 | public class DogTester { 2 | public static void main(String[] args) { 3 | Dog dog = new Dog(); 4 | dog.vigour = 4; 5 | dog.name = "Rufus"; 6 | 7 | dog.bark(); 8 | 9 | Dog nodog = new Dog(); 10 | nodog.bark(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /java/EasyChatServer.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.net.*; 3 | 4 | -------------------------------------------------------------------------------- /java/HelloWorld.java: -------------------------------------------------------------------------------- 1 | class HelloWorld { 2 | public static void main(String[] args) { 3 | System.out.println("Hello World!"); 4 | System.out.println("I rule the world!"); 5 | 6 | int x = 0; 7 | 8 | while (x < 10) { 9 | System.out.println("Why not? " + x); 10 | x++; 11 | 12 | if (x == 3) { 13 | System.out.println("Because x is 3"); 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /java/ImageDownloader.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | import java.io.*; 3 | 4 | public class ImageDownloader { 5 | public static void StreamCopier(InputStream in, OutputStream out) throws Exception { 6 | // Stick to 4K page size 7 | byte[] buffer = new byte[4096]; 8 | 9 | while (true) { 10 | int bytesRead = in.read(buffer); 11 | if (bytesRead == -1) break; 12 | out.write(buffer, 0, bytesRead); 13 | } 14 | } 15 | 16 | public ImageDownloader(String location, String fileName) throws Exception { 17 | StreamCopier(new URL(location).openStream(), 18 | new FileOutputStream(fileName)); 19 | } 20 | 21 | public static void main(String[] args) throws Exception { 22 | if (args.length < 2) { 23 | System.out.println("Usage: ImageDownloader URL filename"); 24 | System.exit(0); 25 | } 26 | 27 | new ImageDownloader(args[0], args[1]); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /java/PhraseOMatic.java: -------------------------------------------------------------------------------- 1 | public class PhraseOMatic { 2 | public static void main(String[] args) { 3 | String[] wordlist1 = { "Say Goodnight", 4 | "To", 5 | "The", 6 | "Bad Guy" }; 7 | 8 | int random = (int) (Math.random() * wordlist1.length); 9 | 10 | System.out.println("Random = " + random); 11 | System.out.println("Length = " + wordlist1.length); 12 | System.out.println(wordlist1[random]); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /java/SearchMap.java: -------------------------------------------------------------------------------- 1 | import java.util.Map; 2 | import java.util.HashMap; 3 | 4 | public class TreeNode { 5 | private TreeNode left; 6 | private TreeNode right; 7 | private String name; 8 | private Object value; 9 | 10 | TreeNode(String name) { 11 | name = name; 12 | left = null; 13 | right = null; 14 | } 15 | 16 | TreeNode(String name, TreeNode l, TreeNode r) { 17 | name = name; 18 | left = l; 19 | right = r; 20 | } 21 | 22 | void Dump() { 23 | if (left != null) { 24 | left.Dump(); 25 | } 26 | 27 | if (right != null) { 28 | right.Dump(); 29 | } 30 | 31 | System.out.println(name); 32 | } 33 | } 34 | 35 | public class SearchMap { 36 | public static void main(String[] args) { 37 | Map m = new HashMap(); 38 | 39 | m.put("one", new Integer(1)); 40 | m.put("two", new Integer(2)); 41 | m.put("three", new Integer(3)); 42 | 43 | System.out.println(m.get(args[0])); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /java/WriteFile.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class WriteFile { 4 | public static void main(String[] args) { 5 | try { 6 | FileWriter fw = new FileWriter("model.xml"); 7 | 8 | fw.write("\n"); 9 | fw.write(" XML Sucks Balls\n"); 10 | fw.write("\n"); 11 | 12 | fw.close(); 13 | } catch(IOException ex) { 14 | ex.printStackTrace(); 15 | } 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /java/j2d/mohit_muthanna_hindi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j2d/mohit_muthanna_hindi.png -------------------------------------------------------------------------------- /java/j3d/Checkers3D/Checkers3D.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Executing Java3D application... 3 | 4 | java -cp "%CLASSPATH%;..\j3dtree.jar" Checkers3D 5 | echo Finished. -------------------------------------------------------------------------------- /java/j3d/Checkers3D/compileChk.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Compiling Checkers3D files... 3 | 4 | javac -classpath "%CLASSPATH%;..\j3dtree.jar" *.java 5 | echo Finished. -------------------------------------------------------------------------------- /java/j3d/Loader3D/Loader3D.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Executing Java3D application... 3 | 4 | java -cp %CLASSPATH%;ncsa\portfolio.jar Loader3D %1 %2 5 | echo Finished. -------------------------------------------------------------------------------- /java/j3d/Loader3D/compileLd.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Compiling Loader3D files... 3 | 4 | javac -classpath %CLASSPATH%;ncsa\portfolio.jar *.java 5 | echo Finished. -------------------------------------------------------------------------------- /java/j3d/Loader3D/icons/down.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/icons/down.gif -------------------------------------------------------------------------------- /java/j3d/Loader3D/icons/in.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/icons/in.gif -------------------------------------------------------------------------------- /java/j3d/Loader3D/icons/left.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/icons/left.gif -------------------------------------------------------------------------------- /java/j3d/Loader3D/icons/out.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/icons/out.gif -------------------------------------------------------------------------------- /java/j3d/Loader3D/icons/right.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/icons/right.gif -------------------------------------------------------------------------------- /java/j3d/Loader3D/icons/up.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/icons/up.gif -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/AARAM.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/models/AARAM.3DS -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/AaramCoords.txt: -------------------------------------------------------------------------------- 1 | Aaram.3ds 2 | -p 0 0.7 2.1 3 | -r 11111111111222226666666666555555566666621333335555555552221 4 | -s 1.668 5 | -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/BoxConeSphereCoords.txt: -------------------------------------------------------------------------------- 1 | BoxConeSphere.wrl 2 | -p 0 0.6 0 3 | -r 555555555432111111111112 4 | -s 1.772 5 | -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/CASTLE.COB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/models/CASTLE.COB -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/COOLROBO.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/models/COOLROBO.3DS -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/CastleCoords.txt: -------------------------------------------------------------------------------- 1 | Castle.cob 2 | -p 7.3 2.2 -3.3 3 | -r 22222222221555555555555555555 4 | -s 27.372 5 | -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/CoolroboCoords.txt: -------------------------------------------------------------------------------- 1 | Coolrobo.3ds 2 | -p 0 1.4 0 3 | -r 666666666 4 | -s 3.452 5 | -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/MAA-1.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/models/MAA-1.3DS -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/bldg4.3ds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/Loader3D/models/bldg4.3ds -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/bldg4Coords.txt: -------------------------------------------------------------------------------- 1 | bldg4.3ds 2 | -p 0 0.8 0 3 | -r 1122222222222221111111 4 | -s 4.177 5 | -------------------------------------------------------------------------------- /java/j3d/Loader3D/models/houseCoords.txt: -------------------------------------------------------------------------------- 1 | house.wrl 2 | -p 0 0.5 1.1 3 | -r 334444444444443321344124433333333333 4 | -s 1.745 5 | -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/LoaderInfo3D.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Executing Java3D application... 3 | 4 | java -cp %CLASSPATH%;ncsa\portfolio.jar LoaderInfo3D %1 %2 5 | echo Finished. -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/compileLI.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Compiling LoaderInfo3D files... 3 | 4 | javac -classpath %CLASSPATH%;ncsa\portfolio.jar *.java 5 | echo Finished. -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/models/AARAM.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/models/AARAM.3DS -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/models/CASTLE.COB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/models/CASTLE.COB -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/models/COOLROBO.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/models/COOLROBO.3DS -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/models/GUN1.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/models/GUN1.3DS -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/models/MAA-1.3DS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/models/MAA-1.3DS -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/models/column.3ds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/models/column.3ds -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/models/dolphins.3ds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/models/dolphins.3ds -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/models/stone.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/models/stone.jpg -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/portfolio.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/j3d/LoaderInfo3D/portfolio.jar -------------------------------------------------------------------------------- /java/j3d/LoaderInfo3D/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | NCSA Portfolio 3 | 4 | Portfolio is a very useful collection of model loaders, 5 | developed by the now-defunct NCSA Java 3D Group, in a 6 | project led by Steve Pietrowicz (srp@ncsa.uiuc.edu) and 7 | Chris Heistad (chris@heistad.org). 8 | 9 | Neither of those people is working on NCSA Portfolio now. 10 | 11 | Portfolio is used in chapters 16, 18, 19, 24, 27, and 32 12 | of the book: 13 | Killer Game Programming in Java 14 | http://fivedots.coe.psu.ac.th/~ad/jg 15 | 16 | Contact Address: 17 | Dr. Andrew Davison 18 | Dept. of Computer Engineering 19 | Prince of Songkla University 20 | Hat Yai, Songkhla 90112, Thailand 21 | E-mail: ad@fivedots.coe.psu.ac.th 22 | 23 | 24 | -------------------------------------------------- 25 | How to Install 26 | 27 | Read the license agreement in portfolioLicense.txt 28 | (In essence it says that a person is allowed to distribute 29 | NCSA Portfolio as long as he/she isn't charging money 30 | for it.) 31 | 32 | Extract portfolio.jar from the zip file, and place it 33 | in a location suitable for your application. 34 | 35 | --------- 36 | Last updated: 25th February 2006 -------------------------------------------------------------------------------- /java/j3d/Random.java: -------------------------------------------------------------------------------- 1 | public class Random { 2 | public static void main(String[] args) { 3 | System.out.println(Math.random()); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /java/macbundle/GlassDemo.app/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LSUIElement 6 | 1 7 | LSUIPresentationMode 8 | 4 9 | CFBundleName 10 | GlassDemo 11 | CFBundleVersion 12 | 100.0 13 | CFBundleAllowMixedLocalizations 14 | true 15 | CFBundleExecutable 16 | JavaApplicationStub 17 | CFBundleDevelopmentRegion 18 | English 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleInfoDictionaryVersion 24 | 6.0 25 | CFBundleIconFile 26 | GenericJavaApp.icns 27 | Java 28 | 29 | MainClass 30 | GlassDemo 31 | JVMVersion 32 | 1.5* 33 | ClassPath 34 | $JAVAROOT/ 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /java/macbundle/GlassDemo.app/Contents/MacOS/JavaApplicationStub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/macbundle/GlassDemo.app/Contents/MacOS/JavaApplicationStub -------------------------------------------------------------------------------- /java/macbundle/GlassDemo.app/Contents/PkgInfo: -------------------------------------------------------------------------------- 1 | APPL???? -------------------------------------------------------------------------------- /java/macbundle/GlassDemo.app/Contents/Resources/GenericJavaApp.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/macbundle/GlassDemo.app/Contents/Resources/GenericJavaApp.icns -------------------------------------------------------------------------------- /java/model.xml: -------------------------------------------------------------------------------- 1 | 2 | XML Sucks Balls 3 | 4 | -------------------------------------------------------------------------------- /java/quiz.data: -------------------------------------------------------------------------------- 1 | Who are you?/Yo Mama 2 | Why are you?/Just Because 3 | -------------------------------------------------------------------------------- /java/servlets/beer/etc/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Asterisk Server 5 | server 6 | lonsdale:5050 7 | 8 | 9 | 10 | ServletContextListener 11 | com.test.BeerListener 12 | 13 | 14 | 15 | Beer Servlet 16 | com.test.BeerSelect 17 | 18 | 19 | 20 | Beer Servlet 21 | /SelectBeer.do 22 | 23 | 24 | -------------------------------------------------------------------------------- /java/servlets/beer/nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /java/servlets/beer/src/com/model/BeerExpert.java: -------------------------------------------------------------------------------- 1 | package com.model; 2 | 3 | import java.util.*; 4 | 5 | public class BeerExpert { 6 | public List getBrands(String color) { 7 | List brands = new ArrayList(); 8 | 9 | if (color.equals("amber")) { 10 | brands.add("Jack Amber"); 11 | brands.add("Red Moose"); 12 | } else { 13 | brands.add("Some Pale Ale"); 14 | brands.add("Gout Stout"); 15 | } 16 | 17 | return brands; 18 | } 19 | 20 | public static void main(String[] args) { 21 | for (String b : new BeerExpert().getBrands("amber")) { 22 | System.out.println("Brand: " + b); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /java/servlets/beer/src/com/test/BeerListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package com.test; 7 | 8 | import javax.servlet.*; 9 | 10 | /** 11 | * Web application lifecycle listener. 12 | * @author mmuthanna 13 | */ 14 | 15 | public class BeerListener implements ServletContextListener { 16 | 17 | public void contextInitialized(ServletContextEvent arg0) { 18 | ServletContext sc = arg0.getServletContext(); 19 | sc.setAttribute("jazz", "Renee Olstead"); 20 | } 21 | 22 | public void contextDestroyed(ServletContextEvent arg0) { 23 | throw new UnsupportedOperationException("Not supported yet."); 24 | } 25 | } -------------------------------------------------------------------------------- /java/servlets/beer/src/com/test/BeerSelect.java: -------------------------------------------------------------------------------- 1 | package com.test; 2 | 3 | import com.model.*; 4 | 5 | import javax.servlet.*; 6 | import javax.servlet.http.*; 7 | import java.io.*; 8 | 9 | public class BeerSelect extends HttpServlet { 10 | 11 | @Override 12 | public void doPost(HttpServletRequest request, 13 | HttpServletResponse response) 14 | throws IOException { 15 | response.setContentType("text/html"); 16 | PrintWriter out = response.getWriter(); 17 | 18 | out.println("Beer Selection Advice

"); 19 | 20 | String c = request.getParameter("color"); 21 | 22 | out.println("Got color: " + c + "

"); 23 | 24 | for (String brand : new BeerExpert().getBrands(c)) { 25 | out.println("Brand: " + brand + "
"); 26 | } 27 | 28 | out.println("Initialized jazz = " + (String) getServletContext().getAttribute("jazz")); 29 | 30 | out.println("

Connecting to Asterisk server: " + 31 | getServletContext().getInitParameter("server")); 32 | } 33 | } -------------------------------------------------------------------------------- /java/servlets/beer/web/beer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Select Beer

4 | 5 |
6 | Select Beer 7 | 8 |

9 | 10 | 16 | 17 |

18 | 19 |

20 | 21 |
22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /java/servlets/beer/web/beer.jsp: -------------------------------------------------------------------------------- 1 | <%@ page import="java.util.*" %> 2 | 3 | 4 | 5 |

Beer Recommendations

6 | 7 |

8 | 9 | <% 10 | List styles = (List)request.getAttribute("styles"); 11 | 12 | for (String style : styles) { 13 | out.print("Style: " + style + "
"); 14 | } 15 | %> 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /java/servlets/first/etc/web.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | First Servlet 8 | FirstServlet 9 | 10 | 11 | 12 | First Servlet 13 | /first 14 | 15 | 16 | -------------------------------------------------------------------------------- /java/servlets/first/src/FirstServlet.java: -------------------------------------------------------------------------------- 1 | import javax.servlet.*; 2 | import javax.servlet.http.*; 3 | import java.io.*; 4 | 5 | public class FirstServlet extends HttpServlet { 6 | public void doGet(HttpServletRequest request, 7 | HttpServletResponse response) 8 | throws IOException { 9 | PrintWriter out = response.getWriter(); 10 | java.util.Date today = new java.util.Date(); 11 | 12 | out.println("" + 13 | "" + 14 | "

Today is " + today + 15 | "

" + 16 | "" + 17 | ""); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /java/test.java: -------------------------------------------------------------------------------- 1 | class HelloWorld { 2 | public static void main( String[] args ) throws TestException { 3 | System.out.println( "Hello World!" ); 4 | } 5 | } 6 | 7 | -------------------------------------------------------------------------------- /java/xmlrpc/XmlRpcClientTest.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.logging.Logger; 3 | import java.net.*; 4 | 5 | import org.apache.xmlrpc.*; 6 | import org.apache.xmlrpc.client.*; 7 | 8 | public class XmlRpcClientTest { 9 | private static Logger logger = Logger.global; 10 | 11 | public static void main(String [] args) throws Exception { 12 | XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); 13 | config.setServerURL(new URL("http://127.0.0.1:8999/xmlrpc")); 14 | 15 | XmlRpcClient client = new XmlRpcClient(); 16 | client.setConfig(config); 17 | 18 | logger.info("Sending RPC to server."); 19 | Object[] params = new Object[] { new String("123456FFF") }; 20 | String result = (String) client.execute("DeliveryServlet.getAdImageURL", params); 21 | logger.info("Got result: " + result); 22 | 23 | logger.info("Shutting down RPC server."); 24 | result = (String) client.execute("ControlServlet.shutdownServer", params); 25 | logger.info("Got result: " + result); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /java/xmlrpc/commons-logging-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmlrpc/commons-logging-1.1.jar -------------------------------------------------------------------------------- /java/xmlrpc/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -x 2 | 3 | javac -cp xmlrpc-common-3.1.jar:xmlrpc-client-3.1.jar XmlRpcClientTest.java 4 | java -cp xmlrpc-common-3.1.jar:xmlrpc-client-3.1.jar:ws-commons-util-1.0.2.jar:. XmlRpcClientTest 5 | -------------------------------------------------------------------------------- /java/xmlrpc/ws-commons-util-1.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmlrpc/ws-commons-util-1.0.2.jar -------------------------------------------------------------------------------- /java/xmlrpc/xmlrpc-client-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmlrpc/xmlrpc-client-3.1.jar -------------------------------------------------------------------------------- /java/xmlrpc/xmlrpc-common-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmlrpc/xmlrpc-common-3.1.jar -------------------------------------------------------------------------------- /java/xmlrpc/xmlrpc-server-3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmlrpc/xmlrpc-server-3.1.jar -------------------------------------------------------------------------------- /java/xmpp/Makefile: -------------------------------------------------------------------------------- 1 | SmackTest.class: SmackTest.java 2 | javac -cp lib/smack.jar SmackTest.java 3 | 4 | clean: 5 | rm SmackTest.class 6 | -------------------------------------------------------------------------------- /java/xmpp/SmackTest.java: -------------------------------------------------------------------------------- 1 | import org.jivesoftware.smack.*; 2 | import org.jivesoftware.smack.packet.*; 3 | import java.io.*; 4 | import java.util.logging.*; 5 | 6 | class SmackTest { 7 | private static Logger logger = Logger.global; 8 | 9 | public static void main(String[] args) { 10 | logger.setLevel(Level.INFO); 11 | ConnectionConfiguration config = 12 | new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); 13 | 14 | XMPPConnection connection = new XMPPConnection(config); 15 | 16 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 17 | 18 | try { 19 | System.out.print("Username: "); 20 | String username = in.readLine(); 21 | 22 | System.out.print("Password: " ); 23 | String password = in.readLine(); 24 | 25 | connection.connect(); 26 | connection.login(username, password); 27 | 28 | Presence presence = new Presence(Presence.Type.available); 29 | connection.sendPacket(presence); 30 | } catch (XMPPException ex) { 31 | logger.severe("Connection failed: " + ex); 32 | } catch (IOException ex) { 33 | logger.severe("Failed to get credentials: " + ex); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /java/xmpp/lib/smack.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmpp/lib/smack.jar -------------------------------------------------------------------------------- /java/xmpp/lib/smackx-debug.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmpp/lib/smackx-debug.jar -------------------------------------------------------------------------------- /java/xmpp/lib/smackx-jingle.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmpp/lib/smackx-jingle.jar -------------------------------------------------------------------------------- /java/xmpp/lib/smackx.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/java/xmpp/lib/smackx.jar -------------------------------------------------------------------------------- /java/xmpp/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -x 2 | 3 | java -cp lib/smack.jar:lib/smackx.jar:. SmackTest 4 | -------------------------------------------------------------------------------- /js/deno_test.js: -------------------------------------------------------------------------------- 1 | import { add } from "./denolib.ts"; 2 | import { assertEquals } from "https://deno.land/std@0.201.0/assert/mod.ts"; 3 | 4 | Deno.test("adder test", () => { 5 | assertEquals(add(1, 2), 3); 6 | }) -------------------------------------------------------------------------------- /js/denolib.ts: -------------------------------------------------------------------------------- 1 | export function add(a: number, b: number): number { 2 | return a + b; 3 | } 4 | -------------------------------------------------------------------------------- /js/denorun.ts: -------------------------------------------------------------------------------- 1 | import { add } from "./denolib.ts"; 2 | import chalk from "npm:chalk@5.3"; 3 | 4 | // deno run --allow-all denorun.ts 5 | 6 | // deno run --allow-net="deno.com" ... 7 | async function _dumpSite(site: string) { 8 | const res = await fetch(site); // https://deno.com 9 | const body = await res.text(); 10 | 11 | console.log(body); 12 | } 13 | 14 | function adder() { 15 | console.log(add(1, 2)); 16 | } 17 | 18 | // deno run --allow-env ... 19 | function env() { 20 | console.log(Deno.env.get("HOME")); 21 | } 22 | 23 | // deno run --allow-all ... 24 | function hello_color() { 25 | // Seems like you need --allow-all for terminal colors to work 26 | console.log(chalk.green("Hello"), chalk.blue("World!")); 27 | } 28 | 29 | adder(); 30 | env(); 31 | hello_color(); 32 | -------------------------------------------------------------------------------- /js/glyphnames.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/js/glyphnames.js.gz -------------------------------------------------------------------------------- /js/glyphnames2.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/js/glyphnames2.js.gz -------------------------------------------------------------------------------- /js/greasemonkey/helloworld.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Hello World 3 | // @namespace http://muthanna.com/greasemonkey 4 | // @include * 5 | // @exclude http://muthanna.com/* 6 | // @exclude http://diveintogreasemonkey.org/* 7 | // ==/UserScript== 8 | 9 | GM_log('Running on ' + window.location.href); 10 | -------------------------------------------------------------------------------- /js/greasemonkey/renamer.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Renamer 3 | // @namespace http://muthanna.com/greasemonkey 4 | // @include http://diveintogreasemonkey.org/* 5 | // @include http://www.diveintogreasemonkey.org/* 6 | // ==/UserScript== 7 | 8 | GM_log('Running on ' + window.location.href); 9 | 10 | var myDiv = document.getElementById('intro'); 11 | 12 | var link = myDiv.childNodes[1].childNodes[1].childNodes[1].childNodes[1]; 13 | 14 | link.innerHTML = "You've Been Owned"; 15 | -------------------------------------------------------------------------------- /js/greasemonkey/yoogle.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Renamer 3 | // @namespace http://muthanna.com/greasemonkey 4 | // @include http://google.com/* 5 | // @include http://www.google.com/* 6 | // ==/UserScript== 7 | 8 | var center = document.evaluate('//center', 9 | document, 10 | null, 11 | XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, 12 | null); 13 | 14 | image = center.snapshotItem(0).childNodes[1]; 15 | 16 | image.width = 232 17 | image.height = 44 18 | image.src = "http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif" 19 | -------------------------------------------------------------------------------- /js/notify.js: -------------------------------------------------------------------------------- 1 | // Requires jQuery 2 | 3 | function Notifier() {} 4 | 5 | // Request permission for this page to send notifications. If allowed, 6 | // calls function "cb" with true. 7 | Notifier.prototype.RequestPermission = function(cb) { 8 | window.webkitNotifications.requestPermission(function() { 9 | if (window.webkitNotifications.checkPermission() == 0) { 10 | return true; 11 | } 12 | }); 13 | } 14 | 15 | // Popup a notification with icon, title, and body. Returns false if 16 | // permission was not granted. 17 | Notifier.prototype.Notify = function(icon, title, body) { 18 | if (window.webkitNotifications.checkPermission() == 0) { 19 | var popup = window.webkitNotifications.createNotification( 20 | icon, title, body); 21 | popup.show(); 22 | 23 | return true; 24 | } 25 | 26 | return false; 27 | } 28 | -------------------------------------------------------------------------------- /js/v8/README: -------------------------------------------------------------------------------- 1 | To build the v8 libraries, see: 2 | 3 | http://code.google.com/apis/v8/build.html 4 | 5 | To build the code here: 6 | 7 | $ scons 8 | 9 | To clean: 10 | 11 | $ scons -c 12 | -------------------------------------------------------------------------------- /js/v8/SConstruct: -------------------------------------------------------------------------------- 1 | env = Environment( 2 | CPPPATH="/opt/dev/v8/include", 3 | LIBPATH="/opt/dev/v8") 4 | 5 | env.Program("test.cc", LIBS = "v8_g") 6 | -------------------------------------------------------------------------------- /js/v8/test.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace v8; 5 | 6 | int main(int argc, char* argv[]) { 7 | 8 | // Create a stack-allocated handle scope. 9 | HandleScope handle_scope; 10 | 11 | // Create a new context. 12 | Persistent context = Context::New(); 13 | 14 | // Enter the created context for compiling and 15 | // running the hello world script. 16 | Context::Scope context_scope(context); 17 | 18 | // Create a string containing the JavaScript source code. 19 | Handle source = String::New("'Hello' + ', World!'"); 20 | 21 | // Compile the source code. 22 | Handle 8 | 10 | 12 | 14 | 16 | 17 | 19 | 21 | 22 | {% block head %}{% end %} 23 | {% block title %}Vex Title{% end %} 24 | 25 | 26 | 27 |
28 | {% block wrapper %} 29 | {% end %} 30 |
31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /python/webapp/templates/frontpage.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | App 4 | 6 | 7 | 8 | 9 |

10 | 11 | {{ _("Current user:") }} {{ escape(user) }} 12 | 13 |

14 | 15 | {{ _("Received Action:") }} {{ escape(action) }} 16 | 17 |

18 | 19 |

20 | {% for error in errors %} 21 | {{ error }} 22 | {% end %} 23 |
24 | 25 |

26 | 27 | 28 | 29 |

30 | 31 | 32 | -------------------------------------------------------------------------------- /python/webapp/vexweb/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/python/webapp/vexweb/__init__.py -------------------------------------------------------------------------------- /r/waves.rscript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env Rscript 2 | # 3 | # Quick test to see how zero-phase sine and cosine waves 4 | # correlate. 5 | # 6 | # Ans: They don't. 7 | 8 | waves <- function() { 9 | l <- 4 * pi 10 | 11 | # Create plot window of 2 rows by 2 columns 12 | par(mfrow=c(2,2)) 13 | 14 | a <- sin(seq(0, l, length=1000)) 15 | b <- cos(seq(0, l, length=1000)) 16 | 17 | c <- a * b 18 | 19 | plot(a, type="l") 20 | plot(b, type="l") 21 | plot(c, type="l") 22 | 23 | cat("Correlation: ", sum(c), "\n") # Displays a near-zero number 24 | } 25 | 26 | waves() 27 | -------------------------------------------------------------------------------- /ruby/README.md: -------------------------------------------------------------------------------- 1 | # Various Ruby Thingies 2 | 3 | ## The Ruby Refresher 4 | 5 | Moved to: http://github.com/0xfe/rubyrefresher 6 | 7 | * Get Markdown 8 | 9 | curl -O http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip 10 | 11 | * Unzip 12 | 13 | unzip Markdown_1.0.1.zip 14 | cp Markdown_1.0.1/Markdown.pl ~/c/bin/markdown.pl 15 | 16 | * Go! 17 | 18 | markdown.pl refresher.md >refresher.html 19 | 20 | ## Binary Heap / Priority Queue 21 | 22 | Moved to http://github/0xfe/vexruby_heap 23 | -------------------------------------------------------------------------------- /ruby/gencsv.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Generate a CSV: 100 lines of 10 random numbers per-line 3 | 100.times { puts ((1..10).map {rand(200)}).join(", ") } 4 | -------------------------------------------------------------------------------- /ruby/midi/README.md: -------------------------------------------------------------------------------- 1 | Build MIDI file: 2 | 3 | $ gem install midilib 4 | $ ./midigen 5 | 6 | Convert to WAV: 7 | $ brew install fluidsynth 8 | $ fluidsynth -a coreaudio ~/w/audio/octave/FluidR3_GM.sf2 from_scratch.mid -F test.ra 9 | 10 | $ brew install sox 11 | $ sox -t raw -r 44100 -e signed -b 16 -c 2 test.raw ~/Downloads/test1.wav 12 | 13 | 14 | -------------------------------------------------------------------------------- /ruby/nc.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # ./nc.rb localhost 22 4 | 5 | require 'socket' 6 | 7 | host, port = ARGV 8 | 9 | s = TCPSocket.open(host, port) 10 | 11 | total_bytes = 0 12 | 13 | while !s.eof? 14 | data = s.readline 15 | total_bytes += data.length 16 | puts data 17 | end 18 | 19 | s.close 20 | puts "\n\nRead #{data.length} bytes." 21 | -------------------------------------------------------------------------------- /ruby/parsecsv.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # Calculate mean of 4th column 4 | 5 | sum = 0 6 | num = 0 7 | 8 | ARGF.each do |line| 9 | line.chomp! 10 | sum += line.split(/\s*,\s*/)[4].to_i 11 | num += 1 12 | end 13 | 14 | puts(sum / num) 15 | 16 | -------------------------------------------------------------------------------- /ruby/push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ./markdown.pl refresher.md >../www/rubyrefresher/index.html 4 | cp refresher.css ../www/rubyrefresher/refresher.css 5 | -------------------------------------------------------------------------------- /ruby/refresher.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: white; 3 | font-family: 'Inika', Arial; 4 | font-size: 12pt; 5 | color: #222222; 6 | margin: auto 20px; 7 | width: 90%; 8 | } 9 | 10 | a { text-decoration: none; color: black; padding-bottom: 3px;} 11 | a:link {text-decoration: none; color: black; 12 | border-bottom: dotted black 2px } 13 | a:visited {text-decoration: none; color: black; 14 | border-bottom: dotted black 2px } 15 | a:active {text-decoration: none; color: black; 16 | border-bottom: dotted red 2px } 17 | a:hover {text-decoration: none; color: black; 18 | border-bottom: dotted red 2px } 19 | 20 | h1 { 21 | color: black; 22 | font-size: 36px; 23 | margin-bottom: 2px; 24 | margin-top: 2px; 25 | } 26 | 27 | pre { 28 | padding: 10px; 29 | padding-left: 20px; 30 | border-left: solid 4px #ccc; 31 | background: #eee; 32 | } 33 | 34 | code { 35 | font-size: 12pt; 36 | font-family: 'Inconsolata', Courier; 37 | } 38 | -------------------------------------------------------------------------------- /ruby/urlencode/u.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require 'cgi' 4 | 5 | # Encode all parameters 6 | str = CGI.escape(ARGV.join("")) 7 | puts str 8 | -------------------------------------------------------------------------------- /ruby/wget.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # ./wget.rb www.google.com / 4 | 5 | require 'socket' 6 | 7 | host, path = ARGV 8 | port = 80 9 | 10 | s = TCPSocket.open(host, port) 11 | 12 | s.puts "GET #{path}" 13 | 14 | total_bytes = 0 15 | 16 | while !s.eof? 17 | data = s.readline 18 | total_bytes += data.length 19 | puts data 20 | end 21 | 22 | s.close 23 | puts "\n\nRead #{data.length} bytes." 24 | -------------------------------------------------------------------------------- /rust/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /rust/btree/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "btree" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /rust/btree/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "btree" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /rust/echo/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "echo" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | tokio = {version = "1", features = ["full"]} 10 | -------------------------------------------------------------------------------- /rust/hello/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rust/hello/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | threadpool = "1.8.1" 10 | serde = { version = "1.0", features = ["derive"] } 11 | serde_json = "1.0" 12 | futures = "0.3" 13 | async-std = "1.12" 14 | reqwest = "0.11" 15 | -------------------------------------------------------------------------------- /rust/hello/README.md: -------------------------------------------------------------------------------- 1 | # Rust Experiments 2 | 3 | This directory consists of a bunch of random rust code written while learning Rust. 4 | 5 | ## To run 6 | 7 | ``` 8 | cargo run (print|generics|lifetimes|threads|...) 9 | ``` 10 | 11 | ## Install Rust 12 | 13 | Install via official management tool. 14 | 15 | ``` 16 | $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 17 | $ source $HOME/.cargo/env 18 | ``` 19 | 20 | Add `source $HOME/.cargo/env` to end of .zshrc 21 | 22 | ## API Docs 23 | 24 | https://doc.rust-lang.org/std/fmt/ 25 | 26 | (Use `S` to search.) 27 | 28 | ## New project 29 | 30 | Follow instructions: https://www.rust-lang.org/learn/get-started 31 | 32 | ``` 33 | $ cargo new hello-rust 34 | $ cargo run 35 | ``` 36 | 37 | You can also: 38 | 39 | ``` 40 | $ rustc main.rs 41 | $ ./main 42 | ``` 43 | 44 | Build for production: 45 | 46 | ``` 47 | $ cargo build --release 48 | ``` 49 | 50 | ## VSCode 51 | 52 | Install rust extension. Then cmd-shift-p --> restart rust server, will prompt to install if not found. 53 | -------------------------------------------------------------------------------- /rust/hello/src/args.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | pub fn run() { 4 | let args: Vec = env::args().collect(); 5 | 6 | println!("Args: {:?}", args); 7 | 8 | let target = args[0].clone(); 9 | println!("$0 = {}", target); 10 | 11 | #[derive(Debug, Clone)] 12 | struct MoStruct { 13 | i: i64, 14 | f: f64, 15 | } 16 | 17 | let mo = MoStruct{i: 4, f: 4.4}; 18 | println!("mo {:?}", mo); 19 | 20 | let boo = mo.clone(); 21 | println!("boo {:?}", boo); 22 | 23 | println!("{}, {}", boo.i, boo.f); 24 | } -------------------------------------------------------------------------------- /rust/hello/src/asyncawait.rs: -------------------------------------------------------------------------------- 1 | use async_std::task; 2 | use futures::executor::block_on; 3 | use std::time; 4 | 5 | async fn part1() -> usize { 6 | for n in 1..10 { 7 | // Notice this is async_std::task::sleep and not thread::sleep. Also 8 | // notice the await. You need to use async-aware blocking methods wherever 9 | // possible. 10 | task::sleep(time::Duration::from_millis(100)).await; 11 | println!("a - {}", n); 12 | } 13 | 14 | 1 15 | } 16 | 17 | async fn part2() -> usize { 18 | for n in 1..10 { 19 | task::sleep(time::Duration::from_millis(50)).await; 20 | println!("b - {}", n); 21 | } 22 | 23 | 2 24 | } 25 | 26 | async fn go() { 27 | let (a, b) = futures::join!(part1(), part2()); 28 | println!("a: {}, b: {}", a, b); 29 | } 30 | 31 | async fn fetch() { 32 | /* 33 | // Needs Tokio to work. 34 | use reqwest; 35 | 36 | let body = reqwest::get("http://www.rust-lang.org") 37 | .await 38 | .unwrap() 39 | .text() 40 | .await 41 | .unwrap(); 42 | println!("Rust body:\n{}", body) 43 | */ 44 | } 45 | 46 | pub fn run() { 47 | block_on(go()); 48 | block_on(fetch()); 49 | } 50 | -------------------------------------------------------------------------------- /rust/hello/src/dynamic.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | struct Point(i32, i32); 3 | 4 | #[derive(Debug)] 5 | struct Rect { 6 | tl: Point, 7 | br: Point, 8 | } 9 | 10 | #[derive(Debug)] 11 | struct Circle { 12 | center: Point, 13 | radius: u32, 14 | } 15 | 16 | pub trait Draw { 17 | fn draw(&self); 18 | } 19 | 20 | impl Draw for Rect { 21 | fn draw(&self) { 22 | println!("Drawing rectangle: {:?}", self); 23 | println!("br: {:?} tl: {:?}", self.br, self.tl); 24 | } 25 | } 26 | 27 | impl Draw for Circle { 28 | fn draw(&self) { 29 | println!("Drawing circle: {:?}", self); 30 | println!("center: {:?} radius: {:?}", self.center, self.radius); 31 | } 32 | } 33 | 34 | pub fn draw_all(shapes: &Vec>) { 35 | for shape in shapes { 36 | shape.draw(); 37 | } 38 | } 39 | 40 | pub fn run() { 41 | let circle = Box::new(Circle { 42 | center: Point(100, 100), 43 | radius: 10, 44 | }); 45 | 46 | let rect = Box::new(Rect { 47 | tl: Point(0, 0), 48 | br: Point(100, 100), 49 | }); 50 | 51 | let shapes: Vec> = vec![circle, rect]; 52 | 53 | draw_all(&shapes); 54 | } 55 | -------------------------------------------------------------------------------- /rust/hello/src/functions.rs: -------------------------------------------------------------------------------- 1 | fn greet(text: &str, name: &str) { 2 | println!("{}, {}!", text, name); 3 | } 4 | 5 | fn add(a: i32, b: i32) -> i32 { 6 | a + b 7 | } 8 | 9 | pub fn run() { 10 | println!("TEST: functions.rs"); 11 | greet("Hello", "Mo"); 12 | 13 | println!("Sum: {}", add(4,5)); 14 | 15 | let adder = |a: i32, b: i32| a + b; 16 | println!("Adder: {}", adder(4,5)); 17 | } -------------------------------------------------------------------------------- /rust/hello/src/generics.rs: -------------------------------------------------------------------------------- 1 | // You can use "where" to remove the generic type clutter form the 2 | // function signature 3 | fn add(a: T, b: T) -> T 4 | where T: std::ops::Add + std::fmt::Debug 5 | { 6 | // The debug trait lets you do this 7 | println!("{:?} + {:?}", a, b); 8 | // The Add trait lets you do this 9 | return a + b 10 | } 11 | 12 | pub fn run() { 13 | add(4, 5); 14 | } -------------------------------------------------------------------------------- /rust/hello/src/iterators.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | 3 | fn iterate() -> Vec { 4 | let v = vec![5, 4, 2, 1]; 5 | 6 | for i in &v { 7 | println!("v {i}"); 8 | } 9 | 10 | let mut total: i32 = v.iter().sum(); 11 | println!("sum: {total}"); 12 | 13 | // map() creates a new iterator, and because iterators are lazily evaluated, 14 | // you need to call collect() on it to iterate through and create a new vector. 15 | let n = 3; 16 | let v2: Vec<_> = v.iter().map(|x| x * n).collect(); 17 | 18 | total = v2.iter().sum(); 19 | println!("v2 sum: {total}"); 20 | 21 | let v3: Vec<_> = v.into_iter().filter(|x| *x > 3).collect(); 22 | total = v3.iter().sum(); 23 | println!("v3 {:?} sum: {total}", v3); 24 | v3 25 | } 26 | 27 | fn show_values(iter: impl Iterator) { 28 | let values: Vec<_> = iter.collect(); 29 | println!("{}", values.join(", ")); 30 | } 31 | 32 | fn arguments() { 33 | show_values(env::args()) 34 | } 35 | 36 | pub fn run() { 37 | iterate(); 38 | arguments(); 39 | } 40 | 41 | #[cfg(test)] 42 | mod tests { 43 | use super::*; 44 | 45 | #[test] 46 | fn iterate_test() { 47 | let v3 = iterate(); 48 | assert_eq!(v3, vec![5, 4]) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rust/hello/src/lifetimes.rs: -------------------------------------------------------------------------------- 1 | fn gt<'a>(a: &'a str, b: &'a str) -> &'a str { 2 | if a > b { 3 | a 4 | } else { 5 | b 6 | } 7 | } 8 | 9 | pub fn run() { 10 | // Stack allocated int 11 | let a = 5; 12 | 13 | // Copy 14 | let b = a; 15 | 16 | // This is fine 17 | println!("{} {}", a, b); 18 | 19 | // Heap allocated int 20 | let a = Box::new(5); 21 | 22 | // This changes ownership of the int from a to b 23 | let b = a; 24 | 25 | // This won't complile because a is invalid. 26 | // println!("{} {}", a, b); 27 | 28 | // You can clone it instead. (Note b is still the owner, so clone from b) 29 | let c = b.clone(); 30 | 31 | // This is fine 32 | println!("{} {}", b, c); 33 | 34 | println!("gt {}", gt("foo", "bar")) 35 | 36 | // b and c are destroyed when they go out of scope 37 | } -------------------------------------------------------------------------------- /rust/hello/src/pointers.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Debug; 2 | use std::ops::Deref; 3 | 4 | #[derive(Debug)] 5 | struct MyBox(T); 6 | 7 | impl MyBox { 8 | fn new(t: T) -> MyBox { 9 | return MyBox(t); 10 | } 11 | } 12 | 13 | impl Deref for MyBox { 14 | type Target = T; 15 | 16 | fn deref(&self) -> &Self::Target { 17 | return &self.0; 18 | } 19 | } 20 | 21 | impl Drop for MyBox { 22 | fn drop(&mut self) { 23 | println!("goodbye {:?}!", *self) 24 | } 25 | } 26 | 27 | pub fn run() { 28 | let i = MyBox::new(25); 29 | println!("i = {}", *i); 30 | 31 | let j = MyBox::new(30); 32 | drop(j); 33 | } 34 | -------------------------------------------------------------------------------- /rust/hello/src/print.rs: -------------------------------------------------------------------------------- 1 | pub fn run() { 2 | let a = format!("blah"); 3 | println!("{}", a); 4 | 5 | let pi = 3.14159; 6 | println!("{:1.3}", pi); 7 | 8 | #[derive(Debug)] 9 | struct MyType(i32); 10 | 11 | // Use debug print {:?} 12 | let b = MyType(4); 13 | println!("{:?}", b); 14 | 15 | println!("{} is from {}", "Mo", "Canada"); 16 | println!("{0:b} {0:x}", 16233); 17 | } 18 | -------------------------------------------------------------------------------- /rust/hello/src/strings.rs: -------------------------------------------------------------------------------- 1 | pub fn run() { 2 | let mut s = String::from("heyoooo "); 3 | 4 | s.push_str("foo!"); 5 | 6 | println!("{} {}", s, s.len()); 7 | 8 | if s.is_empty() { 9 | println!("empty!") 10 | } else { 11 | println!("not empty!") 12 | } 13 | 14 | // Immutable primitive string type 15 | let imm_s : &str = "boo"; 16 | println!("Immutable: {}", imm_s); 17 | } 18 | -------------------------------------------------------------------------------- /rust/hello/src/structs.rs: -------------------------------------------------------------------------------- 1 | struct Color { 2 | r: u8, 3 | g: u8, 4 | b: u8 5 | } 6 | 7 | impl Color { 8 | fn new(r: u8, g: u8, b: u8) -> Color { 9 | Color{r: r, g: g, b: b} 10 | } 11 | 12 | fn css(&self) -> String { 13 | format!("#{:02x}{:02x}{:02x}", self.r, self.g, self.b) 14 | } 15 | 16 | fn set_r(&mut self, v: u8) { 17 | self.r = v; 18 | } 19 | } 20 | 21 | pub fn run() { 22 | let c = Color{r: 5, g: 6, b: 7}; 23 | println!("{} {} {}", c.r, c.g, c.b); 24 | 25 | // Tuple Struct 26 | struct OtherColor(u8, u8, u8); 27 | let uc = OtherColor(4, 5, 6); 28 | println!("{} {} {}", uc.0, uc.1, uc.1); 29 | 30 | let mut mycolor = Color::new(25, 68, 230); 31 | println!("{}", mycolor.css()); 32 | 33 | mycolor.set_r(200); 34 | println!("{}", mycolor.css()); 35 | } -------------------------------------------------------------------------------- /rust/hello/src/threadpool.rs: -------------------------------------------------------------------------------- 1 | pub struct ThreadPool { 2 | size: usize, 3 | } 4 | 5 | impl ThreadPool { 6 | fn new(size: usize) -> ThreadPool { 7 | assert!(size > 0); 8 | ThreadPool { size } 9 | } 10 | 11 | fn size(&self) -> usize { 12 | return self.size; 13 | } 14 | } 15 | 16 | pub fn run() { 17 | println!("running threadpool"); 18 | let tp = ThreadPool::new(10); 19 | println!("size: {}", tp.size()); 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests { 24 | use super::*; 25 | 26 | #[test] 27 | fn new_pool() { 28 | let tp = ThreadPool::new(5); 29 | assert_eq!(tp.size(), 5); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rust/hello/src/tuples.rs: -------------------------------------------------------------------------------- 1 | pub fn run() { 2 | let tup: (&str, &str, i32) = ("mo", "by", 42); 3 | 4 | println!("{} {} {}", tup.0, tup.1, tup.2); 5 | } -------------------------------------------------------------------------------- /rust/hello/src/types.rs: -------------------------------------------------------------------------------- 1 | pub fn run() { 2 | let i: i64 = 4; 3 | 4 | println!("Max i64: {} i {}", std::i64::MAX, i); 5 | 6 | let is_active = true; 7 | let expr: char = 'x'; 8 | 9 | println!("bool: {}, char: {}", is_active, expr); 10 | } 11 | -------------------------------------------------------------------------------- /rust/hello/src/vars.rs: -------------------------------------------------------------------------------- 1 | pub fn run() { 2 | let mut blah = "foo"; 3 | println!("{}", blah); 4 | blah = "bar"; 5 | println!("{}", blah); 6 | 7 | // Constants should have explicit types 8 | const ID: i32 = 001; 9 | println!("{}", ID); 10 | 11 | let (foo, bar) = ("hi", "bye"); 12 | println!("{} and {}", foo, bar); 13 | } 14 | -------------------------------------------------------------------------------- /rust/hype/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hype" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | name = "hype" 8 | path = "src/lib.rs" 9 | 10 | [[bin]] 11 | name = "main" 12 | path = "src/main.rs" 13 | 14 | [dependencies] 15 | tokio = { version = "1", features = ["full"] } 16 | lazy_static = "1.4" 17 | 18 | -------------------------------------------------------------------------------- /rust/hype/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate lazy_static; 3 | 4 | pub mod parser; 5 | pub mod response; 6 | pub mod server; 7 | pub mod status; 8 | 9 | pub fn add(left: usize, right: usize) -> usize { 10 | left + right 11 | } 12 | 13 | #[cfg(test)] 14 | mod tests { 15 | use super::*; 16 | 17 | #[test] 18 | fn it_works() { 19 | let result = add(2, 2); 20 | assert_eq!(result, 4); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rust/hype/src/main.rs: -------------------------------------------------------------------------------- 1 | use hype::server::Server; 2 | 3 | #[tokio::main] 4 | async fn main() { 5 | let server = Server::new("127.0.0.1".into(), 4000); 6 | server.start().await.unwrap(); 7 | } 8 | -------------------------------------------------------------------------------- /rust/hype/src/status.rs: -------------------------------------------------------------------------------- 1 | type Code<'a> = (u16, &'a str); 2 | 3 | pub const OK: Code = (200, "OK"); 4 | pub const NOT_FOUND: Code = (404, "NOT FOUND"); 5 | pub const SERVER_ERROR: Code = (500, "SERVER ERROR"); 6 | 7 | #[derive(Debug, Clone, Eq, PartialEq)] 8 | pub struct Status<'a> { 9 | pub code: u16, 10 | pub text: &'a str, 11 | } 12 | 13 | pub fn from(c: Code) -> Status { 14 | Status { 15 | code: c.0, 16 | text: c.1, 17 | } 18 | } 19 | 20 | #[cfg(test)] 21 | mod tests { 22 | use super::*; 23 | 24 | #[test] 25 | fn it_works() { 26 | assert_eq!(from(OK).code, 200); 27 | assert_eq!(from(OK).text, "OK"); 28 | } 29 | 30 | #[test] 31 | fn it_works_with_var() { 32 | let code = from(NOT_FOUND); 33 | assert_eq!(code.code, 404); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /rust/leetcode/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "leetcode" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /rust/leetcode/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "leetcode" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /rust/leetcode/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod add_two_numbers; 2 | pub mod longest_palindromic_substring; 3 | pub mod longest_substring_without_repeating_characters; 4 | pub mod median_of_two_sorted_arrays; 5 | pub mod reverse_integer; 6 | pub mod two_sum; 7 | pub mod zigzag_conversion; 8 | -------------------------------------------------------------------------------- /rust/leetcode/src/string_to_integer_atoi.rs: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/string-to-integer-atoi/ 2 | -------------------------------------------------------------------------------- /rust/stack/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "stack" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /rust/stack/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "stack" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /rust/stack/src/main.rs: -------------------------------------------------------------------------------- 1 | mod stack; 2 | 3 | fn main() { 4 | println!("Hello, world!"); 5 | 6 | let mut s = stack::MoStack::new(); 7 | s.push(String::from("boo")); 8 | s.push(String::from("foo")); 9 | 10 | println!("pop {}", s.pop().unwrap()); 11 | println!("pop {}", s.pop().unwrap()); 12 | println!("pop {}", s.pop().unwrap()); 13 | } 14 | -------------------------------------------------------------------------------- /rust/stack/src/stack.rs: -------------------------------------------------------------------------------- 1 | pub struct MoStack { 2 | items: Vec, 3 | pos: u32, 4 | } 5 | 6 | impl MoStack { 7 | pub fn new() -> MoStack { 8 | MoStack { 9 | items: vec![], 10 | pos: 0, 11 | } 12 | } 13 | 14 | pub fn push(&mut self, item: T) { 15 | self.items.push(item); 16 | self.pos += 1 17 | } 18 | 19 | pub fn pop(&mut self) -> Option { 20 | self.items.pop() 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /rust/threads/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "threads" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | rand = "0.8.5" 10 | -------------------------------------------------------------------------------- /rust/threads/src/main.rs: -------------------------------------------------------------------------------- 1 | mod atomics; 2 | mod locks; 3 | mod thread; 4 | 5 | fn main() { 6 | thread::run1(); 7 | thread::run2(); 8 | thread::run3(); 9 | thread::run4(); 10 | thread::run5(); 11 | thread::run6(); 12 | 13 | atomics::run(); 14 | locks::run(); 15 | } 16 | -------------------------------------------------------------------------------- /scala/Args.scala: -------------------------------------------------------------------------------- 1 | /* 2 | $ scalac-2.8 Args.scala 3 | $ scala-2.8 Args a b c 4 | A 5 | B 6 | C 7 | */ 8 | 9 | object Args { 10 | def main(args: Array[String]) { 11 | args.foreach(x => println(x toUpperCase)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /scala/AsteriskClient/Client.scala: -------------------------------------------------------------------------------- 1 | package asterisk.ami 2 | 3 | import java.io._; 4 | import java.net._; 5 | import java.util.Random; 6 | import scala.collection.mutable.Map; 7 | import scala.io.Source; 8 | import scala.util.logging._; 9 | import scala.util.matching.Regex; 10 | 11 | case class ResponseError(val response: Response) extends Exception 12 | class Client(val conn: BaseConnection) { 13 | // Send AMI command to server, and return the response. This will wait 14 | // for the response with the same ActionID as the command. 15 | def sendCommand(command: Command) : Response = { 16 | conn.write(command.mkString) 17 | 18 | var response = Response(conn.readResponse) 19 | while (response.actionid != command.actionid) { 20 | response = Response(conn.readResponse) 21 | } 22 | 23 | response 24 | } 25 | 26 | // Same as sendCommand, except that a ResponseError exception is thrown 27 | // upon error. 28 | def tryCommand(cmd: Command) : Response = { 29 | val resp = sendCommand(cmd) 30 | resp match { 31 | case ami.response.Error(_) => throw ResponseError(resp) 32 | case _ => resp 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /scala/AsteriskClient/README: -------------------------------------------------------------------------------- 1 | To run: 2 | 3 | $ scala asterisk.tools.TestCall 4 | 5 | 6 | -------------------------------------------------------------------------------- /scala/AsteriskClient/TestCall.scala: -------------------------------------------------------------------------------- 1 | package asterisk.tools; 2 | 3 | import scala.util.logging._; 4 | import asterisk.ami; 5 | import asterisk.ami.command; 6 | import scala.collection.mutable.Map; 7 | 8 | object TestCall { 9 | def main(args: Array[String]) { 10 | val conn = new ami.Connection("localhost", 5038) with ConsoleLogger 11 | val client = new ami.Client(conn) 12 | 13 | try { 14 | // Connect to AMI server. 15 | conn.connect() 16 | 17 | // Login to gateway. 18 | client.tryCommand(command.Login("phone", "ph0ne")) 19 | 20 | // Originate phone call. 21 | client.tryCommand( 22 | command.Originate( 23 | "SIP/12125656156@google_ame", 24 | "googletest", 25 | "s", 26 | "12125656156", 27 | 30000).setVariables(Map("A" -> "B", 28 | "C" -> "D"))) 29 | 30 | } catch { 31 | case e: ami.ConnectionException => println("Not connected.") 32 | case e: ami.ResponseError => println( 33 | "Command error: " + e.response.message) 34 | } finally { 35 | conn.disconnect 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /scala/ForEach.scala: -------------------------------------------------------------------------------- 1 | package com.muthanna.playground.scala 2 | 3 | object ForEach { 4 | def main(args: Array[String]) { 5 | args.foreach(arg => println(arg)); 6 | args.foreach(println(_)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /scala/HelloWorld.scala: -------------------------------------------------------------------------------- 1 | package com.muthanna.playground.scala 2 | 3 | object HelloWorld { 4 | def main(args: Array[String]) { 5 | println("Hello, world!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /scala/JettyHello.scala: -------------------------------------------------------------------------------- 1 | package com.muthanna.playground.scala 2 | 3 | import org.eclipse.jetty.server.Server 4 | import org.eclipse.jetty.server.handler.DefaultHandler 5 | 6 | // This is written for Jetty 7 7 | 8 | object JettyHello { 9 | def main(args: Array[String]) { 10 | var server = new Server(8080) 11 | var handler = new DefaultHandler() 12 | 13 | handler.setServer(server) 14 | 15 | server.start() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scala/MapTest.scala: -------------------------------------------------------------------------------- 1 | package com.muthanna.playground.scala 2 | 3 | import java.lang.Integer; 4 | import java.util.Map; 5 | import java.util.HashMap; 6 | 7 | object MapTest { 8 | def main(args: Array[String]) { 9 | var aMap = new HashMap[Integer, String] 10 | println("boo"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/AMIConnection.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * AMIConnection.scala 3 | * 4 | * To change this template, choose Tools | Template Manager 5 | * and open the template in the editor. 6 | */ 7 | 8 | package 9 | 10 | class AMIConnection { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/dist/AsteriskClient.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/scala/NetBeansProjects/AsteriskClient/dist/AsteriskClient.jar -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | X-COMMENT: Main-Class will be added automatically by build 3 | 4 | -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=93c66e97 2 | build.xml.script.CRC32=c7f8f588 3 | build.xml.stylesheet.CRC32=ca9d572e@1.3.0 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=93c66e97 7 | nbproject/build-impl.xml.script.CRC32=7afdae68 8 | nbproject/build-impl.xml.stylesheet.CRC32=bc42a706@1.3.0 9 | -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/nbproject/private/config.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/scala/NetBeansProjects/AsteriskClient/nbproject/private/config.properties -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/nbproject/private/private.properties: -------------------------------------------------------------------------------- 1 | compile.on.save=false 2 | do.depend=false 3 | do.jar=true 4 | javac.debug=true 5 | javadoc.preview=true 6 | user.properties.file=/Users/mmuthanna/.netbeans/6.7/build.properties 7 | -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/nbproject/private/private.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.scala.project 4 | 5 | 6 | AsteriskClient 7 | 1.6.5 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /scala/NetBeansProjects/AsteriskClient/src/asteriskclient/Main.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Main.scala 3 | * 4 | * To change this template, choose Tools | Template Manager 5 | * and open the template in the editor. 6 | */ 7 | 8 | package asteriskclient 9 | 10 | import scala.util.logging._; 11 | 12 | object Main { 13 | def main(args: Array[String]) { 14 | val conn = new AMIConnection("localhost", 7777) with ConsoleLogger 15 | val gateway = new AMIClient(conn) 16 | 17 | try { 18 | conn.connect 19 | val response = gateway.login("mohit", "password") 20 | println(response.toString) 21 | } catch { 22 | case e: AMIConnectionException => println("Not connected.") 23 | } finally { 24 | conn.disconnect 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /scala/Privacy.scala: -------------------------------------------------------------------------------- 1 | package com.muthanna.playground.scala 2 | 3 | class PrivacyT(visible: Int) 4 | 5 | 6 | object Privacy { 7 | def main(args: Array[String]) { 8 | var p = new PrivacyT(5) 9 | println(p.visible) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /scala/README: -------------------------------------------------------------------------------- 1 | Compiling 2 | 3 | $ scalac HelloWorld.scala 4 | $ fsc HelloWorld.scala (Faster) 5 | 6 | Running 7 | 8 | $ scala -cp . com.muthanna.playground.scala.HelloWorld 9 | 10 | Jetty Compiling (Jetty 7) 11 | 12 | $ fsc -cp '/opt/local/temp/jetty-distribution-7.0.0.RC4/lib/*' JettyHello.scala 13 | 14 | Jetty Runing (Remember to add . to classpath) 15 | 16 | $ scala -cp '/opt/local/temp/jetty-distribution-7.0.0.RC4/lib/*:.' com.muthanna.playground.scala.JettyHello 17 | 18 | Note that all the servlet stuff is Jetty 6 19 | 20 | YAML 21 | 22 | SnakeYAML: http://code.google.com/p/snakeyaml 23 | -------------------------------------------------------------------------------- /scala/Timer.scala: -------------------------------------------------------------------------------- 1 | package com.muthanna.playground.scala 2 | 3 | object Timer { 4 | def oncePerSecond(callback: () => Unit) { 5 | while (true) { callback(); Thread sleep 1000 } 6 | } 7 | 8 | def main(args: Array[String]) { 9 | oncePerSecond(() => 10 | println("Hello, world!")); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /scala/YamlReader.scala: -------------------------------------------------------------------------------- 1 | package com.muthanna.playground.scala 2 | 3 | import org.yaml.snakeyaml._ 4 | import java.util.{Map => JavaMap} 5 | import java.util.{HashMap => JavaHashMap} 6 | 7 | // To build and run: 8 | // 9 | // $ fsc -cp support/snakeyaml/* YamlReader.scala 10 | // $ scala -cp support/snakeyaml/*:. com.muthanna.playground.YamlReader 11 | 12 | object Converter { 13 | def toJavaHashMap[T, U](map: Map[T,U]): JavaHashMap[T,U] = { 14 | var javamap = new JavaHashMap[T,U] 15 | for ((k, v) <- map) { 16 | javamap.put(k, v) 17 | } 18 | 19 | javamap 20 | } 21 | 22 | def toJavaMap[M[K, V] <: JavaMap[K, V], K, V]( 23 | map: Map[K,V], javamap: M[K, V]): M[K, V] = { 24 | for ((k, v) <- map) { 25 | javamap.put(k, v) 26 | } 27 | 28 | javamap 29 | } 30 | } 31 | 32 | object YamlReader { 33 | def main(args: Array[String]) { 34 | var yaml = new Yaml 35 | var data = yaml.load("a: 1\nb: 2\n") 36 | 37 | println(data) 38 | 39 | var map: Map[String, Int] = Map("a" -> 1, "b" -> 5) 40 | println(yaml.dump(Converter.toJavaHashMap(map))) 41 | 42 | // var javamap: JavaHashMap[String, Int] = new JavaHashMap 43 | // println(yaml.dump(Converter.toJavaMap(map, javamap))) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /scala/hello.rb: -------------------------------------------------------------------------------- 1 | print "Hello Ruby" 2 | -------------------------------------------------------------------------------- /scala/script.scala: -------------------------------------------------------------------------------- 1 | println("Hello scriptish world") 2 | -------------------------------------------------------------------------------- /stats/README.md: -------------------------------------------------------------------------------- 1 | # Start Jupyter in Docker on Mac 2 | 3 | ```bash 4 | $ brew cask install docker 5 | # Run Applications -> Docker 6 | $ docker run -it --rm -p 8888:8888 -v `pwd`:/home/jovyan/work jupyter/tensorflow-notebook 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /stats/hellotf.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | from tensorflow import keras 4 | 5 | model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])]) 6 | model.compile(optimizer='sgd', loss='mean_squared_error') 7 | 8 | xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float) 9 | ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float) 10 | 11 | model.fit(xs, ys, epochs=500) 12 | print(model.predict([10.0])) 13 | -------------------------------------------------------------------------------- /stats/tstf/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/env", 4 | "@babel/typescript" 5 | ], 6 | "plugins": [ 7 | "@babel/proposal-class-properties", 8 | "@babel/proposal-object-rest-spread", 9 | "@babel/plugin-transform-runtime", 10 | ] 11 | } -------------------------------------------------------------------------------- /stats/tstf/.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | -------------------------------------------------------------------------------- /stats/tstf/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "browser": true, 5 | "jquery": true, 6 | "es6": true, 7 | "mocha": true, 8 | }, 9 | "parserOptions": { 10 | "sourceType": "module", 11 | "ecmaVersion": 6, 12 | }, 13 | "rules": { 14 | "max-len": [1, 180, 2, { ignoreComments: true }], 15 | "prefer-destructuring": "off", 16 | }, 17 | "extends": ["airbnb-base"] 18 | }; 19 | -------------------------------------------------------------------------------- /stats/tstf/postcss.config.js: -------------------------------------------------------------------------------- 1 | /* eslint import/no-extraneous-dependencies: "off" */ 2 | 3 | const tailwindcss = require('tailwindcss'); 4 | const autoprefixer = require('autoprefixer'); 5 | 6 | module.exports = { 7 | plugins: [ 8 | tailwindcss('./tailwind.config.js'), 9 | autoprefixer, 10 | ], 11 | }; 12 | -------------------------------------------------------------------------------- /stats/tstf/stylelint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['stylelint-config-recommended'], 3 | rules: { 4 | 'at-rule-no-unknown': [true, { 5 | ignoreAtRules: [ 6 | 'tailwind', 7 | 'apply', 8 | 'variants', 9 | 'responsive', 10 | 'screen', 11 | ], 12 | }], 13 | 'declaration-block-trailing-semicolon': null, 14 | 'no-descending-specificity': null, 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /stats/tstf/tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | theme: { 3 | extend: {}, 4 | }, 5 | variants: {}, 6 | plugins: [], 7 | }; 8 | -------------------------------------------------------------------------------- /www/README: -------------------------------------------------------------------------------- 1 | This URL: 2 | 3 | 0xfe.muthanna.com 4 | 5 | Configured in LightHTTPD: 6 | 7 | $HTTP["host"] =~ "0xfe\.muthanna\.com" { 8 | server.document-root = "/home/mohit/x/www" 9 | accesslog.filename = "/home/mohit/var/log/access-log" 10 | server.indexfiles = ( "dispatch.fcgi", "index.html", "index.htm" ) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_diagonals-small_0_aaaaaa_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_diagonals-small_0_aaaaaa_40x40.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_diagonals-thick_15_444444_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_diagonals-thick_15_444444_40x40.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_diagonals-thick_95_ffdc2e_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_diagonals-thick_95_ffdc2e_40x40.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_glass_55_fbf5d0_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_glass_55_fbf5d0_1x400.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_highlight-hard_30_285c00_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_highlight-hard_30_285c00_1x100.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_highlight-soft_33_3a8104_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_highlight-soft_33_3a8104_1x100.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_highlight-soft_50_4eb305_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_highlight-soft_50_4eb305_1x100.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_highlight-soft_60_4ca20b_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_highlight-soft_60_4ca20b_1x100.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-bg_inset-soft_10_285c00_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-bg_inset-soft_10_285c00_1x100.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-icons_4eb305_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-icons_4eb305_256x240.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-icons_72b42d_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-icons_72b42d_256x240.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /www/analyzer/css/le-frog/images/ui-icons_ffffff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/analyzer/css/le-frog/images/ui-icons_ffffff_256x240.png -------------------------------------------------------------------------------- /www/audio/snare.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/audio/snare.wav -------------------------------------------------------------------------------- /www/draggable.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 14 | 15 | 16 |

17 | DRAG THIS 18 |
19 | 20 | -------------------------------------------------------------------------------- /www/filter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 31 | 32 | 33 | 34 |

Boo

35 | 36 | Play Sine Wave 37 | 38 | 39 | -------------------------------------------------------------------------------- /www/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Web Audio Tone Generator 5 | 7 | 8 | 9 | 10 | 11 |
12 |
13 |

0xFE

14 | home 15 |     16 | blog 17 |     18 | code 19 |     20 | plus 21 |
22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /www/jstest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /www/maps.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 23 | 24 | 25 |

Air Quality for UAE

26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /www/mjk/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 |
9 | 10 |
11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /www/mjk/mjk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/mjk/mjk.jpg -------------------------------------------------------------------------------- /www/rubyrefresher/refresher.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: white; 3 | font-family: 'Inika', Arial; 4 | font-size: 12pt; 5 | color: #222222; 6 | margin: auto 20px; 7 | width: 90%; 8 | } 9 | 10 | a { text-decoration: none; color: black; padding-bottom: 3px;} 11 | a:link {text-decoration: none; color: black; 12 | border-bottom: dotted black 2px } 13 | a:visited {text-decoration: none; color: black; 14 | border-bottom: dotted black 2px } 15 | a:active {text-decoration: none; color: black; 16 | border-bottom: dotted red 2px } 17 | a:hover {text-decoration: none; color: black; 18 | border-bottom: dotted red 2px } 19 | 20 | h1 { 21 | color: black; 22 | font-size: 36px; 23 | margin-bottom: 2px; 24 | margin-top: 2px; 25 | } 26 | 27 | pre { 28 | padding: 10px; 29 | padding-left: 20px; 30 | border-left: solid 4px #ccc; 31 | background: #eee; 32 | } 33 | 34 | code { 35 | font-size: 12pt; 36 | font-family: 'Inconsolata', Courier; 37 | } 38 | -------------------------------------------------------------------------------- /www/something.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /www/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: black; 3 | font-family: 'Marvel', sans-serif; 4 | font-size: 18px; 5 | color: #00cc00; 6 | margin: auto 0px; 7 | } 8 | 9 | a { padding: 3px; 10 | text-decoration: none; color: green; border-bottom: solid #005500 2px } 11 | a:link {text-decoration: none; color: green} 12 | a:visited {text-decoration: none; color: green} 13 | a:active {text-decoration: none; color: #00ff00} 14 | a:hover {text-decoration: none; color: #00ff00} 15 | 16 | #wrapper { 17 | font-size: 18px; 18 | margin-left: auto; 19 | margin-right: auto; 20 | margin-top: 130px; 21 | display: block; 22 | padding: 20px; 23 | width: 90%; 24 | } 25 | 26 | h1 { font-family: "Geostar Fill", cursive; font-size: 36px;} 27 | p { padding: 10px; } 28 | -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_diagonals-small_0_aaaaaa_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_diagonals-small_0_aaaaaa_40x40.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_diagonals-thick_15_444444_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_diagonals-thick_15_444444_40x40.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_diagonals-thick_95_ffdc2e_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_diagonals-thick_95_ffdc2e_40x40.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_glass_55_fbf5d0_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_glass_55_fbf5d0_1x400.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_highlight-hard_30_285c00_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_highlight-hard_30_285c00_1x100.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_highlight-soft_33_3a8104_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_highlight-soft_33_3a8104_1x100.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_highlight-soft_50_4eb305_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_highlight-soft_50_4eb305_1x100.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_highlight-soft_60_4ca20b_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_highlight-soft_60_4ca20b_1x100.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-bg_inset-soft_10_285c00_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-bg_inset-soft_10_285c00_1x100.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-icons_4eb305_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-icons_4eb305_256x240.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-icons_72b42d_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-icons_72b42d_256x240.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-icons_cd0a0a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-icons_cd0a0a_256x240.png -------------------------------------------------------------------------------- /www/tone/css/le-frog/images/ui-icons_ffffff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/tone/css/le-frog/images/ui-icons_ffffff_256x240.png -------------------------------------------------------------------------------- /www/tone/css/tone.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: black; 3 | font-family: 'Marvel', sans-serif; 4 | font-size: 18px; 5 | color: #00cc00; 6 | margin: auto 0px; 7 | } 8 | 9 | a { text-decoration: none; color: green; border-bottom: solid green 2px } 10 | a:link {text-decoration: none; color: green} 11 | a:visited {text-decoration: none; color: green} 12 | a:active {text-decoration: none; color: #369} 13 | a:hover {text-decoration: none; color: #369} 14 | 15 | #wrapper { 16 | font-size: 18px; 17 | margin-left: auto; 18 | margin-right: auto; 19 | margin-top: 0px; 20 | display: block; 21 | padding: 20px; 22 | width: 90%; 23 | } 24 | 25 | h1 { font-family: "Geostar Fill", cursive; font-size: 36px;} 26 | 27 | a#sinewave { 28 | font-family: "Geostar Fill", cursive; 29 | font-size: 26px; background: #105510; color: #00ff00; padding: 10px; 30 | } 31 | div.sinebox { width: 600px; padding: 20px; } 32 | div.logbox { width: 400px; background: black; color: #00ff00; padding: 5px; } 33 | 34 | p { padding: 10px; } 35 | .ui-button { font-family: "Marvel", cursive; font-size: 10px; padding: 0px; } 36 | 37 | -------------------------------------------------------------------------------- /www/wavebox/audio/track.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xfe/experiments/7f957a1cb3b0b041079f30bf1527cfb0498ee527/www/wavebox/audio/track.mp3 -------------------------------------------------------------------------------- /www/wavebox/js/remoteaudioplayer.js: -------------------------------------------------------------------------------- 1 | /* 2 | RemoteAudioPlayer - Loads a remote audio resource into a Web Audio buffer. 3 | Mohit Muthanna Cheppudira - http://0xfe.blogspot.com 4 | */ 5 | RemoteAudioPlayer = function(context, url) { 6 | this.url = url; 7 | this.source = context.createBufferSource(); 8 | this.buffer = 0; 9 | this.context = context; 10 | } 11 | 12 | RemoteAudioPlayer.prototype.getSource = function() { 13 | return this.source; 14 | } 15 | 16 | RemoteAudioPlayer.prototype.load = function(callback) { 17 | var request = new XMLHttpRequest(); 18 | var that = this; 19 | request.open("GET", this.url, true); 20 | request.responseType = "arraybuffer"; 21 | request.onload = function() { 22 | that.buffer = that.context.createBuffer(request.response, true); 23 | that.reload(); 24 | callback(request.response); 25 | } 26 | 27 | request.send(); 28 | } 29 | 30 | RemoteAudioPlayer.prototype.reload = function(callback) { 31 | this.source.buffer = this.buffer; 32 | } 33 | --------------------------------------------------------------------------------