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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/python/pigame.py:
--------------------------------------------------------------------------------
1 | import sys, pygame
2 | pygame.init()
3 |
4 | size = width, height = 320, 240
5 | speed = [2, 2]
6 | black = 0, 0, 0
7 |
8 | screen = pygame.display.set_mode(size)
9 |
10 | ball = pygame.image.load("marilyn.jpg")
11 | ballrect = ball.get_rect()
12 |
13 | while 1:
14 | for event in pygame.event.get():
15 | if event.type == pygame.QUIT: sys.exit()
16 |
17 | ballrect = ballrect.move(speed)
18 |
19 | if ballrect.left < 0 or ballrect.right > width:
20 | speed[0] = -speed[0]
21 |
22 | if ballrect.top < 0 or ballrect.bottom > height:
23 | speed[1] = -speed[1]
24 |
25 | screen.fill(black)
26 | screen.blit(ball, ballrect)
27 | pygame.display.flip()
28 |
--------------------------------------------------------------------------------
/opencv/capture.cc:
--------------------------------------------------------------------------------
1 | #include "highgui.h"
2 |
3 | /*
4 | * Usage:
5 | * capture [video_file]
6 | */
7 |
8 | int main( int argc, char** argv ) {
9 | cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
10 | CvCapture* capture;
11 |
12 | if (argc < 2) {
13 | capture = cvCreateCameraCapture(0);
14 | } else {
15 | capture = cvCreateFileCapture( argv[1] );
16 | }
17 |
18 | IplImage* frame;
19 | while(1) {
20 | frame = cvQueryFrame( capture );
21 | if( !frame ) break;
22 | cvShowImage( "Example2", frame );
23 | char c = cvWaitKey(33);
24 | if( c == 27 ) break;
25 | }
26 | cvReleaseCapture( &capture );
27 | cvDestroyWindow( "Example2" );
28 | }
29 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/python/curses_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import curses
4 | import time
5 |
6 | stdscr = curses.initscr()
7 |
8 | # Allow color
9 | curses.start_color()
10 |
11 | # Disable echoing of input keys
12 | curses.noecho()
13 |
14 | # React to keys without Enter key needed
15 | curses.cbreak()
16 |
17 | # Allow special keys
18 | stdscr.keypad(1)
19 |
20 | # Create a color pair
21 | curses.init_pair(1, curses.COLOR_YELLOW, curses.COLOR_BLACK)
22 |
23 | stdscr.addstr("Hello Curses!\n\n", curses.A_BOLD)
24 | stdscr.addstr("Hit 'q' to quit.", curses.color_pair(1) | curses.A_BOLD)
25 | stdscr.refresh()
26 |
27 | while True:
28 | c = stdscr.getch()
29 | if c == ord('q'): break
30 |
31 | curses.endwin()
32 |
--------------------------------------------------------------------------------
/minikube/dice/dice.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | option go_package = "0xfe/experiments/minikube/dice";
4 |
5 | enum Face {
6 | FACE_HEADS = 0;
7 | FACE_TAILS = 1;
8 | }
9 |
10 | message DiceRoll {
11 | int32 id = 1;
12 | Face face = 2;
13 | }
14 |
15 | message RollTable {
16 | string roller_handle = 1;
17 | repeated DiceRoll rolls = 2;
18 | }
19 |
20 | message RollRequest {
21 | string roller_handle = 1;
22 | }
23 |
24 | message RollResponse {}
25 |
26 | message GetRollsRequest {}
27 |
28 | service RollService {
29 | rpc Roll(RollRequest) returns (RollResponse);
30 |
31 | // Single request, streaming response
32 | rpc GetRolls(GetRollsRequest) returns (stream RollTable);
33 | }
--------------------------------------------------------------------------------
/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 | };
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/cpp/boost/bind.cc:
--------------------------------------------------------------------------------
1 | #include "boost/bind.hpp"
2 | #include
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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Web Audio Tone Generator
5 |
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | };
--------------------------------------------------------------------------------
/python/webapp/models/api.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2.7
2 | #
3 | # Install sqlalchemy with easy_install or ports.
4 |
5 | from sqlalchemy import create_engine
6 | from sqlalchemy.orm import sessionmaker
7 |
8 | from models.metadata import metadata
9 | from models import user
10 |
11 | class APIFactory(object):
12 | log_sql = False
13 |
14 | def __init__(self):
15 | self.initialize_engine()
16 | self.metadata = metadata
17 | self.Session = sessionmaker(bind=self.engine)
18 | self.session = self.Session()
19 |
20 | def initialize_engine(self):
21 | self.engine = create_engine('sqlite:///:memory:', echo=self.log_sql)
22 |
23 | def create_tables(self):
24 | self.metadata.create_all(self.engine)
25 |
26 | def get_user_api(self):
27 | return user.API(self.session)
28 |
--------------------------------------------------------------------------------
/minikube/helm/dice/templates/ingress.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: networking.k8s.io/v1
2 | kind: Ingress
3 | metadata:
4 | name: {{ .Values.app_prefix }}-main-ingress
5 | annotations:
6 | nginx.ingress.kubernetes.io/rewrite-target: /
7 | spec:
8 | rules:
9 | - host: "{{ .Values.ingressHost }}"
10 | http:
11 | paths:
12 | - path: /
13 | pathType: Prefix
14 | backend:
15 | service:
16 | name: {{ .Values.app_prefix }}-main-service
17 | port:
18 | number: {{ .Values.main.port }}
19 | - path: /server
20 | pathType: Prefix
21 | backend:
22 | service:
23 | name: {{ .Values.app_prefix }}-server-service
24 | port:
25 | number: {{ .Values.server.port }}
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/python/challenges/merge_intervals.py:
--------------------------------------------------------------------------------
1 | # https://leetcode.com/problems/merge-intervals/
2 |
3 |
4 | def merge(intervals: list[list[int]]) -> list[list[int]]:
5 | if len(intervals) < 2:
6 | return intervals
7 |
8 | answer = []
9 | intervals.sort(key=lambda v: v[0])
10 |
11 | low, high = intervals[0]
12 | for r in intervals[1:]:
13 | if r[0] > high:
14 | answer.append([low, high])
15 | low, high = r[0], r[1]
16 | elif r[0] >= low and r[1] > high:
17 | high = r[1]
18 |
19 | answer.append([low, high])
20 | return answer
21 |
22 |
23 | assert merge([[1, 3], [2, 6], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]
24 | assert merge([[2, 6], [1, 3], [1, 2], [8, 10], [15, 18]]) == [[1, 6], [8, 10], [15, 18]]
25 | assert merge([[1, 3]]) == ([[1, 3]])
26 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/python/readline_test.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | import readline
4 |
5 | class Completer:
6 | def __init__(self, words):
7 | self.words = words
8 | self.prefix = None
9 |
10 | def complete(self, prefix, index):
11 | if prefix != self.prefix:
12 | self.matching_words = [ w for w in self.words if w.startswith(prefix) ]
13 | self.prefix = prefix
14 | try:
15 | return self.matching_words[index]
16 | except IndexError:
17 | return None
18 |
19 |
20 | words = ["stuff", "others", "me", "monkeys", "othello"]
21 | completer = Completer(words)
22 |
23 | readline.parse_and_bind("tab: complete")
24 | readline.set_completer(completer.complete)
25 |
26 | line = ""
27 |
28 | while line != "q":
29 | line = raw_input("> ")
30 |
31 | if line == "?":
32 | print "q: quit"
33 | else:
34 | print line
35 |
--------------------------------------------------------------------------------
/minikube/client/cmd/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "0xfe/experiments/minikube/client"
5 | "flag"
6 | "fmt"
7 | "log"
8 | )
9 |
10 | var flagTarget = flag.String("target", "localhost:3001", "server address:port")
11 |
12 | func main() {
13 | flag.Parse()
14 | log.Printf("connecting to %s...\n", *flagTarget)
15 |
16 | client := client.NewClient(*flagTarget)
17 | defer client.Close()
18 |
19 | client.Roll("foobar")
20 | client.Roll("foobar")
21 | client.Roll("foobar")
22 | client.Roll("0xfe")
23 | client.Roll("0xfe")
24 |
25 | ch, err := client.GetRolls()
26 | if err != nil {
27 | log.Fatalf("failed: %+v", err)
28 | }
29 |
30 | for rt := range ch {
31 | fmt.Printf("handle: %v\n", rt.RollerHandle)
32 | for i, roll := range rt.Rolls {
33 | fmt.Printf(" roll %d: %v (%d)\n", i+1, roll.Face, roll.Id)
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/python/hellomac.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from Tkinter import *
4 |
5 | class Application(Frame):
6 | def say_hi(self):
7 | print "hi there, everyone!"
8 |
9 | def createWidgets(self):
10 | self.QUIT = Button(self)
11 | self.QUIT["text"] = "QUIT"
12 | self.QUIT["fg"] = "red"
13 | self.QUIT["command"] = self.quit
14 |
15 | self.QUIT.pack({"side": "left"})
16 |
17 | self.hi_there = Button(self)
18 | self.hi_there["text"] = "Hello",
19 | self.hi_there["command"] = self.say_hi
20 |
21 | self.hi_there.pack({"side": "left"})
22 |
23 | def __init__(self, master=None):
24 | Frame.__init__(self, master)
25 | self.pack()
26 | self.createWidgets()
27 |
28 | root = Tk()
29 | app = Application(master=root)
30 | app.mainloop()
31 | root.destroy()
32 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/python/permute.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 |
3 | from copy import copy
4 |
5 | CHARS = "mohitamrita"
6 |
7 | def perm(length, min, max):
8 | def make_perm(length, num):
9 | perm = []
10 | for i in range(0, length):
11 | perm.append(num)
12 |
13 | return perm
14 |
15 | def permx(length, min, max, state, perms):
16 | if length == 0:
17 | perms.append(copy(state))
18 | return perms
19 |
20 | for c in range(min, max + 1):
21 | state[length-1] = c
22 | permx(length-1, min, max, state, perms)
23 |
24 | return perms
25 |
26 | return permx(length, min, max, make_perm(length, 0), [])
27 |
28 | """
29 | def charperm(chars, perms):
30 | for prm in perms:
31 | char = ""
32 | for p in prm:
33 | char
34 |
35 | for i in range(4, 9):
36 | charperm(CHARS, perm(i, 1, 9))
37 | """
38 |
39 | print perm(3, 1, 9)
40 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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();
--------------------------------------------------------------------------------
/www/maps.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
23 |
24 |
25 | Air Quality for UAE
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/minikube/server.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.19 as builder
2 |
3 | # Create and change to the app directory.
4 | WORKDIR /app
5 |
6 | # Copy go.mod and go.sum, then retrieve application dependencies.
7 | # This allows the container build to reuse cached dependencies.
8 | COPY go.* ./
9 | RUN go mod download
10 |
11 | # Copy local code to the container image.
12 | COPY . ./
13 |
14 | # Build the binary.
15 | WORKDIR /app/server
16 | RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o main
17 |
18 | # Use the official Alpine image for a lean production container.
19 | # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
20 | FROM alpine:latest
21 | RUN apk add --no-cache ca-certificates
22 |
23 | # Copy the binary to the production image from the builder stage.
24 | COPY --from=builder /app/server/main /main
25 |
26 | # Run the web service on container startup.
27 | CMD ["/main"]
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/www/filter.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
31 |
32 |
33 |
34 | Boo
35 |
36 | Play Sine Wave
37 |
38 |
39 |
--------------------------------------------------------------------------------
/minikube/server.arm64.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.19 as builder
2 |
3 | # Create and change to the app directory.
4 | WORKDIR /app
5 |
6 | # Copy go.mod and go.sum, then retrieve application dependencies.
7 | # This allows the container build to reuse cached dependencies.
8 | COPY go.* ./
9 | RUN go mod download
10 |
11 | # Copy local code to the container image.
12 | COPY . ./
13 |
14 | # Build the binary.
15 | WORKDIR /app/server
16 | RUN GOARCH=arm64 CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o main
17 |
18 | # Use the official Alpine image for a lean production container.
19 | # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
20 | FROM alpine:latest
21 | RUN apk add --no-cache ca-certificates
22 |
23 | # Copy the binary to the production image from the builder stage.
24 | COPY --from=builder /app/server/main /main
25 |
26 | # Run the web service on container startup.
27 | CMD ["/main"]
28 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 ( int:
19 | if len(nums) == 1:
20 | return nums[0]
21 |
22 | max_so_far = 0
23 | ans = -100000
24 |
25 | for n in nums:
26 | max_so_far += n
27 |
28 | if n > max_so_far:
29 | max_so_far = n
30 |
31 | if max_so_far > ans:
32 | ans = max_so_far
33 |
34 | print("ans", ans)
35 | return ans
36 |
37 |
38 | def test_maxSubArray():
39 | assert maxSubArray([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6
40 | assert maxSubArray([1]) == 1
41 | assert maxSubArray([5, 4, -1, 7, 8]) == 23
42 | assert maxSubArray([5, 4, -1, 7, -8]) == 15
43 |
44 |
45 | test_maxSubArray()
46 |
--------------------------------------------------------------------------------
/emdr/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Remote EMDR
10 |
12 |
13 |
14 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |