Archiving a bunch of old stuff
This commit is contained in:
13
oldstuff/activeresource-aspen/README
Normal file
13
oldstuff/activeresource-aspen/README
Normal file
@@ -0,0 +1,13 @@
|
||||
_______________________________________
|
||||
/ This started out with just some \
|
||||
| ActiveResource bits and then roped in |
|
||||
\ Aspen and then Redis. Gads. /
|
||||
---------------------------------------
|
||||
\ \
|
||||
\ \
|
||||
\ _\^
|
||||
\ _- oo\
|
||||
\---- \______
|
||||
\ )\
|
||||
||-----|| \
|
||||
|| ||
|
23
oldstuff/activeresource-aspen/client.rb
Normal file
23
oldstuff/activeresource-aspen/client.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
require 'active_resource'
|
||||
|
||||
SITE = 'http://localhost:9282' unless defined?(SITE)
|
||||
|
||||
class Person < ActiveResource::Base
|
||||
self.site = SITE
|
||||
|
||||
def family
|
||||
Family.find(self.surname.downcase)
|
||||
end
|
||||
|
||||
def family=(family_surname)
|
||||
self.surname = family_surname
|
||||
Family.find(family_surname)
|
||||
rescue StandardError => e
|
||||
STDERR.puts("#{e.class.name}:#{e.message}\n#{e.backtrace.join("\n")}")
|
||||
Family.create(surname: family_surname.downcase)
|
||||
end
|
||||
end
|
||||
|
||||
class Family < ActiveResource::Base
|
||||
self.site = SITE
|
||||
end
|
2
oldstuff/activeresource-aspen/run-client-shell
Executable file
2
oldstuff/activeresource-aspen/run-client-shell
Executable file
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
exec irb -I. -rclient -rawesome_print --simple-prompt --readline "$@"
|
9
oldstuff/activeresource-aspen/run-server
Executable file
9
oldstuff/activeresource-aspen/run-server
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
which aspen >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "You need to 'pip install aspen'"
|
||||
exit 1
|
||||
fi
|
||||
cd $(dirname $(readlink -f $0))
|
||||
export PYTHONPATH="$PWD:$PYTHONPATH"
|
||||
exec aspen --changes_reload=yes -w ./www -a '0.0.0.0:9282'
|
15
oldstuff/activeresource-aspen/server/__init__.py
Normal file
15
oldstuff/activeresource-aspen/server/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import redis
|
||||
|
||||
_MEMCACHE = {'pool': None}
|
||||
|
||||
|
||||
def get_pool():
|
||||
if not _MEMCACHE['pool']:
|
||||
_MEMCACHE['pool'] = \
|
||||
redis.ConnectionPool(host='localhost', port=6379, db=0)
|
||||
return _MEMCACHE['pool']
|
||||
|
||||
|
||||
def get_redis_conn():
|
||||
return redis.Redis(connection_pool=get_pool())
|
||||
|
12
oldstuff/activeresource-aspen/server/families.py
Normal file
12
oldstuff/activeresource-aspen/server/families.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from server.resource import Resource
|
||||
|
||||
|
||||
class Families(Resource):
|
||||
__collection__ = 'families'
|
||||
__required_keys__ = ('surname',)
|
||||
|
||||
def get_by_surname(self, surname):
|
||||
for family in self.getall():
|
||||
if family['surname'] == surname:
|
||||
return family
|
||||
return None
|
5
oldstuff/activeresource-aspen/server/helpers.py
Normal file
5
oldstuff/activeresource-aspen/server/helpers.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import json
|
||||
|
||||
def json_loads_from_request(request):
|
||||
raw = request.body.s_iter.read(int(request.headers['Content-Length']))
|
||||
return json.loads(raw)
|
6
oldstuff/activeresource-aspen/server/people.py
Normal file
6
oldstuff/activeresource-aspen/server/people.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from server.resource import Resource
|
||||
|
||||
|
||||
class People(Resource):
|
||||
__collection__ = 'people'
|
||||
__required_keys__ = ('name', 'surname', 'age')
|
46
oldstuff/activeresource-aspen/server/resource.py
Normal file
46
oldstuff/activeresource-aspen/server/resource.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import json
|
||||
|
||||
from server import get_redis_conn
|
||||
|
||||
|
||||
class Resource(object):
|
||||
__collection__ = 'generic'
|
||||
__required_keys__ = ()
|
||||
|
||||
def __init__(self):
|
||||
self._db = get_redis_conn()
|
||||
|
||||
def getall(self):
|
||||
ret = []
|
||||
|
||||
for resource in self._db.hgetall(self.__collection__).itervalues():
|
||||
try:
|
||||
ret.append(json.loads(resource))
|
||||
except ValueError, exc:
|
||||
print_exc()
|
||||
|
||||
return ret
|
||||
|
||||
def get(self, resource_id):
|
||||
raw_resource = self._db.hget(self.__collection__, resource_id)
|
||||
|
||||
if not raw_resource:
|
||||
return None
|
||||
|
||||
resource = json.loads(raw_resource)
|
||||
return resource
|
||||
|
||||
def add(self, resource_dict):
|
||||
if None in (resource_dict.get(k) for k in self.__required_keys__):
|
||||
raise ValueError(
|
||||
'Missing required fields!: {}'.format(resource_dict)
|
||||
)
|
||||
|
||||
resource_dict['id'] = self._db.incr(self.__collection__ + '_ids')
|
||||
success = self._db.hset(
|
||||
self.__collection__, resource_dict['id'], json.dumps(resource_dict)
|
||||
)
|
||||
assert success, 'Failed to save!'
|
||||
|
||||
return resource_dict['id']
|
||||
|
18
oldstuff/activeresource-aspen/www/families.json
Normal file
18
oldstuff/activeresource-aspen/www/families.json
Normal file
@@ -0,0 +1,18 @@
|
||||
from server.families import Families
|
||||
from server.helpers import json_loads_from_request
|
||||
|
||||
__families__ = Families()
|
||||
|
||||
|
||||
|
||||
if GET:
|
||||
response.body = __families__.getall()
|
||||
elif POST:
|
||||
family = json_loads_from_request(request)['family']
|
||||
family_id = __families__.add(family)
|
||||
response.headers['Location'] = '/families/{}.json'.format(family_id)
|
||||
family['id'] = family_id
|
||||
response.body = family
|
||||
response.code = 201
|
||||
|
||||
# vim:filetype=python
|
10
oldstuff/activeresource-aspen/www/families/%surname.json
Normal file
10
oldstuff/activeresource-aspen/www/families/%surname.json
Normal file
@@ -0,0 +1,10 @@
|
||||
from server.families import Families
|
||||
__families__ = Families()
|
||||
|
||||
family = __families__.get_by_surname(path['surname'])
|
||||
if family:
|
||||
response.body = {'family': family}
|
||||
else:
|
||||
response.code = 404
|
||||
|
||||
# vim:filetype=python
|
18
oldstuff/activeresource-aspen/www/people.json
Normal file
18
oldstuff/activeresource-aspen/www/people.json
Normal file
@@ -0,0 +1,18 @@
|
||||
from server.people import People
|
||||
from server.helpers import json_loads_from_request
|
||||
|
||||
__people__ = People()
|
||||
|
||||
|
||||
|
||||
if GET:
|
||||
response.body = __people__.getall()
|
||||
elif POST:
|
||||
person = json_loads_from_request(request)['person']
|
||||
person_id = __people__.add(person)
|
||||
response.headers['Location'] = '/people/{}.json'.format(person_id)
|
||||
person['id'] = person_id
|
||||
response.body = person
|
||||
response.code = 201
|
||||
|
||||
# vim:filetype=python
|
11
oldstuff/activeresource-aspen/www/people/%id.json
Normal file
11
oldstuff/activeresource-aspen/www/people/%id.json
Normal file
@@ -0,0 +1,11 @@
|
||||
from server.people import People
|
||||
__people__ = People()
|
||||
|
||||
|
||||
person = __people__.get(int(path['id']))
|
||||
if person:
|
||||
response.body = {'person': person}
|
||||
else:
|
||||
response.code = 404
|
||||
|
||||
# vim:filetype=python
|
1
oldstuff/algs4/.example.env
Normal file
1
oldstuff/algs4/.example.env
Normal file
@@ -0,0 +1 @@
|
||||
export PATH="$HOME/src/box-o-sand/src/algs4/bin:$PATH"
|
69
oldstuff/algs4/.gitignore
vendored
Normal file
69
oldstuff/algs4/.gitignore
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/.env
|
||||
/algs4.jar
|
||||
/bin/
|
||||
/checkstyle-5.5/
|
||||
/checkstyle.zip
|
||||
/drjava.jar
|
||||
/findbugs-2.0.1/
|
||||
/findbugs.zip
|
||||
/stdlib.jar
|
||||
|
||||
16Kints.txt
|
||||
1Kints.txt
|
||||
1Mints.txt
|
||||
2Kints.txt
|
||||
32Kints.txt
|
||||
4Kints.txt
|
||||
8Kints.txt
|
||||
abra.txt
|
||||
cards.txt
|
||||
ex1.txt
|
||||
ex2.txt
|
||||
ex3.txt
|
||||
ex4.txt
|
||||
jobs.txt
|
||||
jobsPC.txt
|
||||
largeEWD.txt
|
||||
largeEWG.txt
|
||||
largeT.txt
|
||||
largeUF.txt
|
||||
largeW.txt
|
||||
leipzig100K.txt
|
||||
leipzig1M.txt
|
||||
leipzig300K.txt
|
||||
list.txt
|
||||
mediumEWD.txt
|
||||
mediumEWDnc.txt
|
||||
mediumEWG.txt
|
||||
mediumUF.txt
|
||||
mobydick.txt
|
||||
movies.txt
|
||||
rates.txt
|
||||
routes.txt
|
||||
tale.txt
|
||||
tiny.txt
|
||||
tinyBatch.txt
|
||||
tinyCG.txt
|
||||
tinyDAG.txt
|
||||
tinyDG.txt
|
||||
tinyEWD.txt
|
||||
tinyEWDAG.txt
|
||||
tinyEWDn.txt
|
||||
tinyEWG.txt
|
||||
tinyG.txt
|
||||
tinyL.txt
|
||||
tinyST.txt
|
||||
tinyT.txt
|
||||
tinyTale.txt
|
||||
tinyUF.txt
|
||||
tinyW.txt
|
||||
tinytinyTale.txt
|
||||
tnyTale.txt
|
||||
tobe.txt
|
||||
words3.txt
|
||||
|
||||
Binomial.java
|
||||
RightTriangle.java
|
||||
Scale.java
|
||||
Tone.java
|
||||
Wget.java
|
21
oldstuff/algs4/download-others
Executable file
21
oldstuff/algs4/download-others
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
OTHERS="$(cat others.txt)"
|
||||
|
||||
cd src/java
|
||||
|
||||
for other in $OTHERS
|
||||
do
|
||||
if [ ! -f "$other" ]
|
||||
then
|
||||
dn=$(dirname "$other")
|
||||
mkdir -p "$dn"
|
||||
pushd "$dn"
|
||||
curl -O "http://algs4.cs.princeton.edu/${other}"
|
||||
chmod 444 "$(basename "$other")"
|
||||
popd
|
||||
fi
|
||||
done
|
13
oldstuff/algs4/extract-jars
Executable file
13
oldstuff/algs4/extract-jars
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
cd src/java
|
||||
set +e
|
||||
chmod 644 *.java *.class 2>/dev/null
|
||||
set -e
|
||||
jar xf ../../algs4.jar
|
||||
jar xf ../../stdlib.jar
|
||||
rm stdlib.jar
|
||||
chmod 444 *.java *.class
|
76
oldstuff/algs4/others.txt
Normal file
76
oldstuff/algs4/others.txt
Normal file
@@ -0,0 +1,76 @@
|
||||
11model/Binomial.java
|
||||
11model/RightTriangle.java
|
||||
11model/Scale.java
|
||||
11model/Tone.java
|
||||
11model/Wget.java
|
||||
11model/cards.txt
|
||||
11model/largeT.txt
|
||||
11model/largeW.txt
|
||||
11model/tinyT.txt
|
||||
11model/tinyW.txt
|
||||
13stacks/tobe.txt
|
||||
14analysis/16Kints.txt
|
||||
14analysis/16Kints.txt
|
||||
14analysis/1Kints.txt
|
||||
14analysis/1Kints.txt
|
||||
14analysis/1Mints.txt
|
||||
14analysis/1Mints.txt
|
||||
14analysis/2Kints.txt
|
||||
14analysis/2Kints.txt
|
||||
14analysis/32Kints.txt
|
||||
14analysis/32Kints.txt
|
||||
14analysis/4Kints.txt
|
||||
14analysis/4Kints.txt
|
||||
14analysis/8Kints.txt
|
||||
14analysis/8Kints.txt
|
||||
15uf/largeUF.txt
|
||||
15uf/mediumUF.txt
|
||||
15uf/tinyUF.txt
|
||||
21sort/tiny.txt
|
||||
21sort/words3.txt
|
||||
22mergesort/tiny.txt
|
||||
22mergesort/words3.txt
|
||||
23quicksort/tiny.txt
|
||||
23quicksort/words3.txt
|
||||
24pq/tiny.txt
|
||||
24pq/tinyBatch.txt
|
||||
24pq/words3.txt
|
||||
31elementary/leipzig100K.txt
|
||||
31elementary/leipzig1M.txt
|
||||
31elementary/leipzig300K.txt
|
||||
31elementary/tale.txt
|
||||
31elementary/tinyST.txt
|
||||
31elementary/tnyTale.txt
|
||||
32bst/tinyST.txt
|
||||
33balanced/tinyST.txt
|
||||
35applications/ex1.txt
|
||||
35applications/ex2.txt
|
||||
35applications/ex3.txt
|
||||
35applications/ex4.txt
|
||||
35applications/list.txt
|
||||
35applications/movies.txt
|
||||
35applications/tinyTale.txt
|
||||
41undirected/movies.txt
|
||||
41undirected/routes.txt
|
||||
41undirected/tinyCG.txt
|
||||
41undirected/tinyG.txt
|
||||
42directed/jobs.txt
|
||||
42directed/tinyDAG.txt
|
||||
42directed/tinyDG.txt
|
||||
43mst/largeEWG.txt
|
||||
43mst/mediumEWG.txt
|
||||
43mst/tinyEWG.txt
|
||||
44sp/jobsPC.txt
|
||||
44sp/largeEWD.txt
|
||||
44sp/mediumEWD.txt
|
||||
44sp/mediumEWDnc.txt
|
||||
44sp/rates.txt
|
||||
44sp/tinyEWD.txt
|
||||
44sp/tinyEWDAG.txt
|
||||
44sp/tinyEWDn.txt
|
||||
54regexp/tinyL.txt
|
||||
55compression/abra.txt
|
||||
55compression/tinytinyTale.txt
|
||||
63suffix/mobydick.txt
|
||||
63suffix/tale.txt
|
||||
63suffix/tinyTale.txt
|
9
oldstuff/algs4/setup
Executable file
9
oldstuff/algs4/setup
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
mkdir -p bin
|
||||
./setup-algs4-stuff
|
||||
./extract-jars
|
||||
./download-others
|
51
oldstuff/algs4/setup-algs4-stuff
Executable file
51
oldstuff/algs4/setup-algs4-stuff
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
test -f drjava.jar || wget http://algs4.cs.princeton.edu/linux/drjava.jar
|
||||
if [ ! -f bin/drjava ]
|
||||
then
|
||||
wget http://algs4.cs.princeton.edu/linux/drjava
|
||||
chmod 700 drjava
|
||||
mv drjava bin/
|
||||
fi
|
||||
test -f stdlib.jar || wget http://algs4.cs.princeton.edu/code/stdlib.jar
|
||||
test -f algs4.jar || wget http://algs4.cs.princeton.edu/code/algs4.jar
|
||||
if [ ! -d checkstyle-5.4 ]
|
||||
then
|
||||
wget http://algs4.cs.princeton.edu/linux/checkstyle.zip
|
||||
unzip checkstyle.zip
|
||||
fi
|
||||
if [ ! -d findbugs-1.3.9 ]
|
||||
then
|
||||
wget http://algs4.cs.princeton.edu/linux/findbugs.zip
|
||||
unzip findbugs.zip
|
||||
fi
|
||||
if [ ! -f checkstyle-5.4/checkstyle.xml ]
|
||||
then
|
||||
wget http://algs4.cs.princeton.edu/linux/checkstyle.xml
|
||||
mv checkstyle.xml checkstyle-5.4
|
||||
fi
|
||||
if [ ! -f findbugs-1.3.9/findbugs.xml ]
|
||||
then
|
||||
wget http://algs4.cs.princeton.edu/linux/findbugs.xml
|
||||
mv findbugs.xml findbugs-1.3.9
|
||||
fi
|
||||
if [ ! -f bin/checkstyle ]
|
||||
then
|
||||
wget http://algs4.cs.princeton.edu/linux/checkstyle
|
||||
chmod 700 checkstyle
|
||||
mv checkstyle bin
|
||||
fi
|
||||
if [ ! -f bin/findbugs ]
|
||||
then
|
||||
wget http://algs4.cs.princeton.edu/linux/findbugs
|
||||
chmod 700 findbugs
|
||||
mv findbugs bin
|
||||
fi
|
||||
if [ ! -f bin/config.sh ]
|
||||
then
|
||||
wget http://algs4.cs.princeton.edu/linux/config.sh
|
||||
mv config.sh bin
|
||||
fi
|
164
oldstuff/algs4/src/java/.gitignore
vendored
Normal file
164
oldstuff/algs4/src/java/.gitignore
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
/AcyclicLP.java
|
||||
/AcyclicSP.java
|
||||
/Alphabet.java
|
||||
/Arbitrage.java
|
||||
/AssignmentProblem.java
|
||||
/Average.java
|
||||
/Bag.java
|
||||
/BellmanFordSP.java
|
||||
/BinaryDump.java
|
||||
/BinarySearch.java
|
||||
/BinarySearchST.java
|
||||
/Bipartite.java
|
||||
/BipartiteMatching.java
|
||||
/BlackFilter.java
|
||||
/BoruvkaMST.java
|
||||
/BoyerMoore.java
|
||||
/BreadthFirstDirectedPaths.java
|
||||
/BreadthFirstPaths.java
|
||||
/BST.java
|
||||
/BTree.java
|
||||
/Cat.java
|
||||
/CC.java
|
||||
/ClosestPair.java
|
||||
/CollisionSystem.java
|
||||
/Complex.java
|
||||
/Counter.java
|
||||
/Count.java
|
||||
/CPM.java
|
||||
/Cycle.java
|
||||
/Date.java
|
||||
/DeDup.java
|
||||
/DegreesOfSeparation.java
|
||||
/DepthFirstDirectedPaths.java
|
||||
/DepthFirstOrder.java
|
||||
/DepthFirstPaths.java
|
||||
/DepthFirstSearch.java
|
||||
/Digraph.java
|
||||
/DigraphGenerator.java
|
||||
/DijkstraAllPairsSP.java
|
||||
/DijkstraSP.java
|
||||
/DirectedCycle.java
|
||||
/DirectedDFS.java
|
||||
/DirectedEdge.java
|
||||
/DoublingRatio.java
|
||||
/DoublingTest.java
|
||||
/Edge.java
|
||||
/EdgeWeightedDigraph.java
|
||||
/EdgeWeightedDirectedCycle.java
|
||||
/EdgeWeightedGraph.java
|
||||
/FarthestPair.java
|
||||
/FFT.java
|
||||
/FileIndex.java
|
||||
/FlowEdge.java
|
||||
/FlowNetwork.java
|
||||
/FordFulkerson.java
|
||||
/FrequencyCounter.java
|
||||
/GaussianElimination.java
|
||||
/Genome.java
|
||||
/GrahamScan.java
|
||||
/Graph.java
|
||||
/GREP.java
|
||||
/Heap.java
|
||||
/HexDump.java
|
||||
/Huffman.java
|
||||
/IndexMaxPQ.java
|
||||
/IndexMinPQ.java
|
||||
/Insertion.java
|
||||
/Interval1D.java
|
||||
/Interval2D.java
|
||||
/KMP.java
|
||||
/KosarajuSharirSCC.java
|
||||
/KruskalMST.java
|
||||
/KWIK.java
|
||||
/LazyPrimMST.java
|
||||
/LinearProbingHashST.java
|
||||
/LookupCSV.java
|
||||
/LookupIndex.java
|
||||
/LRS.java
|
||||
/LSD.java
|
||||
/LZW.java
|
||||
/MaxPQ.java
|
||||
/MergeBU.java
|
||||
/Merge.java
|
||||
/META-INF/MANIFEST.MF
|
||||
/MinPQ.java
|
||||
/MSD.java
|
||||
/Multiway.java
|
||||
/NFA.java
|
||||
/Particle.java
|
||||
/PictureDump.java
|
||||
/Point2D.java
|
||||
/PrimMST.java
|
||||
/Queue.java
|
||||
/Quick3string.java
|
||||
/Quick3way.java
|
||||
/QuickFindUF.java
|
||||
/Quick.java
|
||||
/QuickUnionUF.java
|
||||
/RabinKarp.java
|
||||
/RandomSeq.java
|
||||
/RedBlackBST.java
|
||||
/ResizingArrayQueue.java
|
||||
/ResizingArrayStack.java
|
||||
/RunLength.java
|
||||
/Selection.java
|
||||
/SeparateChainingHashST.java
|
||||
/SequentialSearchST.java
|
||||
/SET.java
|
||||
/Shell.java
|
||||
/Shuffle.java
|
||||
/Simplex.java
|
||||
/SparseVector.java
|
||||
/Stack.java
|
||||
/StaticSETofInts.java
|
||||
/stdlib.jar
|
||||
/ST.java
|
||||
/Stopwatch.java
|
||||
/SuffixArray.java
|
||||
/SymbolDigraph.java
|
||||
/SymbolGraph.java
|
||||
/ThreeSumFast.java
|
||||
/ThreeSum.java
|
||||
/TopM.java
|
||||
/Topological.java
|
||||
/Transaction.java
|
||||
/TransitiveClosure.java
|
||||
/TrieST.java
|
||||
/TST.java
|
||||
/UF.java
|
||||
/Vector.java
|
||||
/WeightedQuickUnionUF.java
|
||||
/WhiteFilter.java
|
||||
/Whitelist.java
|
||||
/BinaryIn.java
|
||||
/BinaryOut.java
|
||||
/BinaryStdIn.java
|
||||
/BinaryStdInTester.java
|
||||
/BinaryStdOut.java
|
||||
/BinaryStdOutTester.java
|
||||
/Copy.java
|
||||
/Draw.java
|
||||
/DrawListener.java
|
||||
/In.java
|
||||
/InTest.txt
|
||||
/Out.java
|
||||
/Picture.java
|
||||
/StdArrayIO.java
|
||||
/StdAudio.java
|
||||
/StdDraw.java
|
||||
/StdDraw3D.java
|
||||
/StdIn.java
|
||||
/StdOut.java
|
||||
/StdRandom.java
|
||||
/StdStats.java
|
||||
/mandrill.jpg
|
||||
/Binomial.java
|
||||
/RightTriangle.java
|
||||
/Scale.java
|
||||
/Tone.java
|
||||
/Wget.java
|
||||
/largeT.txt
|
||||
/largeW.txt
|
||||
/tinyT.txt
|
||||
/tinyW.txt
|
5
oldstuff/algs4/src/java/hello/HelloWorld.java
Normal file
5
oldstuff/algs4/src/java/hello/HelloWorld.java
Normal file
@@ -0,0 +1,5 @@
|
||||
public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World");
|
||||
}
|
||||
}
|
2
oldstuff/andrewmartin/.gitignore
vendored
Normal file
2
oldstuff/andrewmartin/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/bin/
|
||||
/gen/
|
15
oldstuff/andrewmartin/AndroidManifest.xml
Normal file
15
oldstuff/andrewmartin/AndroidManifest.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.meatballhat.andrewmartin"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
|
||||
<activity android:name="AndrewMartin"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
17
oldstuff/andrewmartin/ant.properties
Normal file
17
oldstuff/andrewmartin/ant.properties
Normal file
@@ -0,0 +1,17 @@
|
||||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked into Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
|
||||
# This file is only used by the Ant script.
|
||||
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
92
oldstuff/andrewmartin/build.xml
Normal file
92
oldstuff/andrewmartin/build.xml
Normal file
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="AndrewMartin" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- if sdk.dir was not set from one of the property file, then
|
||||
get it from the ANDROID_HOME env var.
|
||||
This must be done before we load project.properties since
|
||||
the proguard config can use sdk.dir -->
|
||||
<property environment="env" />
|
||||
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
|
||||
<isset property="env.ANDROID_HOME" />
|
||||
</condition>
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true" />
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
10
oldstuff/andrewmartin/local.properties
Normal file
10
oldstuff/andrewmartin/local.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must *NOT* be checked into Version Control Systems,
|
||||
# as it contains information specific to your local configuration.
|
||||
|
||||
# location of the SDK. This is only used by Ant
|
||||
# For customization when using a Version Control System, please read the
|
||||
# header note.
|
||||
sdk.dir=/home/me/opt/adt-bundle-linux/sdk
|
20
oldstuff/andrewmartin/proguard-project.txt
Normal file
20
oldstuff/andrewmartin/proguard-project.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
14
oldstuff/andrewmartin/project.properties
Normal file
14
oldstuff/andrewmartin/project.properties
Normal file
@@ -0,0 +1,14 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=android-17
|
BIN
oldstuff/andrewmartin/res/drawable-hdpi/ic_launcher.png
Normal file
BIN
oldstuff/andrewmartin/res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
oldstuff/andrewmartin/res/drawable-ldpi/ic_launcher.png
Normal file
BIN
oldstuff/andrewmartin/res/drawable-ldpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
oldstuff/andrewmartin/res/drawable-mdpi/ic_launcher.png
Normal file
BIN
oldstuff/andrewmartin/res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
BIN
oldstuff/andrewmartin/res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
oldstuff/andrewmartin/res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
17
oldstuff/andrewmartin/res/layout/main.xml
Normal file
17
oldstuff/andrewmartin/res/layout/main.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<EditText android:id="@+id/edit_message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/edit_message"
|
||||
/>
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/button_send"
|
||||
/>
|
||||
</LinearLayout>
|
6
oldstuff/andrewmartin/res/values/strings.xml
Normal file
6
oldstuff/andrewmartin/res/values/strings.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Andrew Martin</string>
|
||||
<string name="edit_message">Enter a message</string>
|
||||
<string name="button_send">Send</string>
|
||||
</resources>
|
@@ -0,0 +1,15 @@
|
||||
package com.meatballhat.andrewmartin;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class AndrewMartin extends Activity
|
||||
{
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
}
|
||||
}
|
4
oldstuff/arduino/.env
Normal file
4
oldstuff/arduino/.env
Normal file
@@ -0,0 +1,4 @@
|
||||
export ARDUINODIR=/usr/share/arduino
|
||||
export BOARD=uno
|
||||
|
||||
export ARTISTIC_STYLE_OPTIONS='--style=attach -s4'
|
21
oldstuff/arduino/Makefile
Normal file
21
oldstuff/arduino/Makefile
Normal file
@@ -0,0 +1,21 @@
|
||||
EVERYTHING := \
|
||||
arduino.mk \
|
||||
libraries/Bounce/Bounce.h
|
||||
|
||||
.PHONY: all
|
||||
all: $(EVERYTHING)
|
||||
|
||||
.PHONY: all
|
||||
style:
|
||||
astyle -r '*.ino' -n
|
||||
|
||||
arduino.mk:
|
||||
curl -L -o $@ -s http://ed.am/dev/make/arduino-mk/arduino.mk
|
||||
|
||||
libraries/Bounce/Bounce.h: libraries/.raw/Bounce-Arduino-Wiring/Bounce
|
||||
ln -svf $(PWD)/libraries/.raw/Bounce-Arduino-Wiring/Bounce $(PWD)/libraries/Bounce
|
||||
|
||||
libraries/.raw/Bounce-Arduino-Wiring/Bounce:
|
||||
mkdir -p libraries/.raw/Bounce-Arduino-Wiring && \
|
||||
curl -L -s https://github.com/thomasfredericks/Bounce-Arduino-Wiring/archive/8c6fb3b3437b66215c579d23b716916c9b65881b.tar.gz | \
|
||||
tar xzf - -C libraries/.raw/Bounce-Arduino-Wiring --strip-components=1
|
0
oldstuff/arduino/libraries/.gitkeep
Normal file
0
oldstuff/arduino/libraries/.gitkeep
Normal file
@@ -0,0 +1,63 @@
|
||||
const unsigned int LED_PIN = 13;
|
||||
const unsigned int NOTE_MULTIPLIER = 100;
|
||||
|
||||
const unsigned int QUARTER_NOTE = 8;
|
||||
const unsigned int EIGHTH_NOTE = 4;
|
||||
const unsigned int SIXTEENTH_NOTE = 2;
|
||||
const unsigned int THIRTYSECOND_NOTE = 1;
|
||||
|
||||
int measure0[] = {-8, -8, -8, 2, 2, 2, 2, 0};
|
||||
int measure1[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure2[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure3[] = {4, 4, 4, 4, 4, 4, 4, 4, 0};
|
||||
int measure4[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure5[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure6[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
int measure7[] = {4, 4, 4, 4, 4, 4, 4, 4, 0};
|
||||
int measure8[] = {4, 2, 2, 4, 4, 4, -4, 2, 2, 2, 2, 0};
|
||||
|
||||
int measurePop[] = {4, -4, -8, -8, -8, 0};
|
||||
|
||||
void playNote(int note) {
|
||||
if (note > 0) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
delay((NOTE_MULTIPLIER * note) / 2);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
delay((NOTE_MULTIPLIER * note) / 2);
|
||||
} else if (note < 0) {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
delay(NOTE_MULTIPLIER * (-1 * note));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void playMeasure(int measure[]) {
|
||||
for (int i = 0;; i++) {
|
||||
int note = measure[i];
|
||||
if (note == 0) {
|
||||
return;
|
||||
}
|
||||
playNote(note);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// int testMeasure[] = {2, 2, 2, 2, 2, -2, -2, -2, 0};
|
||||
// playMeasure(testMeasure);
|
||||
playMeasure(measure0);
|
||||
playMeasure(measure1);
|
||||
playMeasure(measure2);
|
||||
playMeasure(measure3);
|
||||
playMeasure(measure4);
|
||||
playMeasure(measure5);
|
||||
playMeasure(measure6);
|
||||
playMeasure(measure7);
|
||||
playMeasure(measure8);
|
||||
playMeasure(measurePop);
|
||||
}
|
1
oldstuff/arduino/misc/ConnecticutHalftime/Makefile
Symbolic link
1
oldstuff/arduino/misc/ConnecticutHalftime/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../arduino.mk
|
1
oldstuff/arduino/misc/SerialEcho/Makefile
Symbolic link
1
oldstuff/arduino/misc/SerialEcho/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../arduino.mk
|
28
oldstuff/arduino/misc/SerialEcho/SerialEcho.ino
Normal file
28
oldstuff/arduino/misc/SerialEcho/SerialEcho.ino
Normal file
@@ -0,0 +1,28 @@
|
||||
const unsigned int BAUD_RATE = 9600;
|
||||
unsigned int keys = 0;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(BAUD_RATE);
|
||||
Serial.print("> ");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.write(Serial.read());
|
||||
keys++;
|
||||
|
||||
if (keys == 100) {
|
||||
Serial.println("\nKABOOM!!!");
|
||||
keys = 0;
|
||||
Serial.print("> ");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.print(keys);
|
||||
Serial.println(" keys pressed");
|
||||
Serial.print("> ");
|
||||
}
|
27
oldstuff/arduino/msaqsg/ch01/HelloWorld/HelloWorld.ino
Normal file
27
oldstuff/arduino/msaqsg/ch01/HelloWorld/HelloWorld.ino
Normal file
@@ -0,0 +1,27 @@
|
||||
const unsigned int LED_PIN = 13;
|
||||
const unsigned int PAUSE = 700;
|
||||
const unsigned int FLASH_DURATION = 100;
|
||||
|
||||
|
||||
void flash(int n) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
delay(FLASH_DURATION);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
delay(FLASH_DURATION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
for (int i = 1; i < 4; i++) {
|
||||
flash(i);
|
||||
delay(PAUSE);
|
||||
}
|
||||
delay(PAUSE);
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch01/HelloWorld/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch01/HelloWorld/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
54
oldstuff/arduino/msaqsg/ch02/LEDSwitch/LEDSwitch.ino
Normal file
54
oldstuff/arduino/msaqsg/ch02/LEDSwitch/LEDSwitch.ino
Normal file
@@ -0,0 +1,54 @@
|
||||
const unsigned int LED_PIN = 13;
|
||||
const unsigned int BAUD_RATE = 9600;
|
||||
|
||||
void ledOn() {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
Serial.println("LED on");
|
||||
}
|
||||
|
||||
void ledOff() {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
Serial.println("LED off");
|
||||
}
|
||||
|
||||
void ledBlink() {
|
||||
Serial.println("BLINKY TIME");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ledOn();
|
||||
delay(100);
|
||||
ledOff();
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
void handleInput() {
|
||||
int c = Serial.read();
|
||||
|
||||
switch (c) {
|
||||
case '1':
|
||||
ledOn();
|
||||
break;
|
||||
case '2':
|
||||
ledOff();
|
||||
break;
|
||||
case '3':
|
||||
ledBlink();
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown command: ");
|
||||
Serial.println(c);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
Serial.begin(BAUD_RATE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
handleInput();
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch02/LEDSwitch/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch02/LEDSwitch/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
22
oldstuff/arduino/msaqsg/ch03/BinaryDice/BinaryDice.ino
Normal file
22
oldstuff/arduino/msaqsg/ch03/BinaryDice/BinaryDice.ino
Normal file
@@ -0,0 +1,22 @@
|
||||
const unsigned int LED_BIT0 = 10;
|
||||
const unsigned int LED_BIT1 = 11;
|
||||
const unsigned int LED_BIT2 = 12;
|
||||
|
||||
void outputResult(const long result) {
|
||||
digitalWrite(LED_BIT0, result & B001);
|
||||
digitalWrite(LED_BIT1, result & B010);
|
||||
digitalWrite(LED_BIT2, result & B100);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BIT0, OUTPUT);
|
||||
pinMode(LED_BIT1, OUTPUT);
|
||||
pinMode(LED_BIT2, OUTPUT);
|
||||
|
||||
randomSeed(analogRead(A0));
|
||||
|
||||
outputResult(random(1, 7));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch03/BinaryDice/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch03/BinaryDice/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
@@ -0,0 +1,28 @@
|
||||
const unsigned int BUTTON_PIN = 7;
|
||||
const unsigned int LED_PIN = 13;
|
||||
|
||||
int oldButtonState = LOW;
|
||||
int ledState = LOW;
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
const int CURRENT_BUTTON_STATE = digitalRead(BUTTON_PIN);
|
||||
|
||||
if (CURRENT_BUTTON_STATE != oldButtonState &&
|
||||
CURRENT_BUTTON_STATE == HIGH) {
|
||||
if (ledState == LOW) {
|
||||
ledState = HIGH;
|
||||
} else {
|
||||
ledState = LOW;
|
||||
}
|
||||
|
||||
digitalWrite(LED_PIN, ledState);
|
||||
delay(50);
|
||||
}
|
||||
|
||||
oldButtonState = CURRENT_BUTTON_STATE;
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch03/DebounceButton/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch03/DebounceButton/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
94
oldstuff/arduino/msaqsg/ch03/DiceGame/DiceGame.ino
Normal file
94
oldstuff/arduino/msaqsg/ch03/DiceGame/DiceGame.ino
Normal file
@@ -0,0 +1,94 @@
|
||||
// vim:filetype=arduino
|
||||
#include <Bounce.h>
|
||||
|
||||
const unsigned int LED_BIT0 = 10;
|
||||
const unsigned int LED_BIT1 = 11;
|
||||
const unsigned int LED_BIT2 = 12;
|
||||
const unsigned int START_BUTTON_PIN = 5;
|
||||
const unsigned int GUESS_BUTTON_PIN = 7;
|
||||
const unsigned int BAUD_RATE = 9600;
|
||||
const unsigned int DEBOUNCE_DELAY = 20;
|
||||
const unsigned int HOORAY_FLASHES = 10;
|
||||
const unsigned int HOORAY_FLASH_BATCHES = 3;
|
||||
const unsigned int HOORAY_FLASH_BATCH_PAUSE = 200;
|
||||
const unsigned int HOORAY_FLASH_DURATION = 50;
|
||||
Bounce startButton = Bounce();
|
||||
Bounce guessButton = Bounce();
|
||||
int guess = 0;
|
||||
|
||||
void outputResult(const long result) {
|
||||
digitalWrite(LED_BIT0, result & B001);
|
||||
digitalWrite(LED_BIT1, result & B010);
|
||||
digitalWrite(LED_BIT2, result & B100);
|
||||
}
|
||||
|
||||
void hooray() {
|
||||
for (unsigned int i = 0; i < HOORAY_FLASH_BATCHES; i++) {
|
||||
for (unsigned int i = 0; i < HOORAY_FLASHES; i++) {
|
||||
outputResult(7);
|
||||
delay(HOORAY_FLASH_DURATION);
|
||||
outputResult(0);
|
||||
delay(HOORAY_FLASH_DURATION);
|
||||
}
|
||||
delay(HOORAY_FLASH_BATCH_PAUSE);
|
||||
}
|
||||
}
|
||||
|
||||
void handleGuessButton() {
|
||||
if (!guessButton.update()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (guessButton.read() == HIGH) {
|
||||
guess = (guess % 6) + 1;
|
||||
outputResult(guess);
|
||||
Serial.print("Guess: ");
|
||||
Serial.println(guess);
|
||||
}
|
||||
}
|
||||
|
||||
void handleStartButton() {
|
||||
if (!startButton.update()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (startButton.read() == HIGH) {
|
||||
const int result = random(1, 7);
|
||||
outputResult(result);
|
||||
Serial.print("Result: ");
|
||||
Serial.println(result);
|
||||
|
||||
if (guess > 0) {
|
||||
if (result == guess) {
|
||||
Serial.println("You win!");
|
||||
hooray();
|
||||
} else {
|
||||
Serial.println("You lose!");
|
||||
}
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
guess = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BIT0, OUTPUT);
|
||||
pinMode(LED_BIT1, OUTPUT);
|
||||
pinMode(LED_BIT2, OUTPUT);
|
||||
pinMode(START_BUTTON_PIN, INPUT);
|
||||
pinMode(GUESS_BUTTON_PIN, INPUT);
|
||||
randomSeed(analogRead(A0));
|
||||
Serial.begin(BAUD_RATE);
|
||||
|
||||
startButton.attach(START_BUTTON_PIN);
|
||||
startButton.interval(DEBOUNCE_DELAY);
|
||||
|
||||
guessButton.attach(GUESS_BUTTON_PIN);
|
||||
guessButton.interval(DEBOUNCE_DELAY);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
handleGuessButton();
|
||||
handleStartButton();
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch03/DiceGame/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch03/DiceGame/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
@@ -0,0 +1,32 @@
|
||||
const unsigned int LED_BIT0 = 10;
|
||||
const unsigned int LED_BIT1 = 11;
|
||||
const unsigned int LED_BIT2 = 12;
|
||||
const unsigned int BUTTON_PIN = 7;
|
||||
|
||||
int currentValue = 0;
|
||||
int oldValue = 0;
|
||||
|
||||
void outputResult(const long result) {
|
||||
digitalWrite(LED_BIT0, result & B001);
|
||||
digitalWrite(LED_BIT1, result & B010);
|
||||
digitalWrite(LED_BIT2, result & B100);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BIT0, OUTPUT);
|
||||
pinMode(LED_BIT1, OUTPUT);
|
||||
pinMode(LED_BIT2, OUTPUT);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
randomSeed(analogRead(A0));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
currentValue = digitalRead(BUTTON_PIN);
|
||||
|
||||
if (currentValue != oldValue && currentValue == HIGH) {
|
||||
outputResult(random(1, 7));
|
||||
delay(50);
|
||||
}
|
||||
|
||||
oldValue = currentValue;
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch03/DiceWithButton/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch03/DiceWithButton/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
1
oldstuff/arduino/msaqsg/ch03/MoreReliableSwitch/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch03/MoreReliableSwitch/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
@@ -0,0 +1,27 @@
|
||||
const unsigned int BUTTON_PIN = 7;
|
||||
const unsigned int LED_PIN = 13;
|
||||
|
||||
int oldButtonState = LOW;
|
||||
int ledState = LOW;
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
const int CURRENT_BUTTON_STATE = digitalRead(BUTTON_PIN);
|
||||
|
||||
if (CURRENT_BUTTON_STATE != oldButtonState &&
|
||||
CURRENT_BUTTON_STATE == HIGH) {
|
||||
if (ledState == LOW) {
|
||||
ledState = HIGH;
|
||||
} else {
|
||||
ledState = LOW;
|
||||
}
|
||||
|
||||
digitalWrite(LED_PIN, ledState);
|
||||
}
|
||||
|
||||
oldButtonState = CURRENT_BUTTON_STATE;
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch03/SimpleButton/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch03/SimpleButton/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
17
oldstuff/arduino/msaqsg/ch03/SimpleButton/SimpleButton.ino
Normal file
17
oldstuff/arduino/msaqsg/ch03/SimpleButton/SimpleButton.ino
Normal file
@@ -0,0 +1,17 @@
|
||||
const unsigned int BUTTON_PIN = 7;
|
||||
const unsigned int LED_PIN = 13;
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
const int BUTTON_STATE = digitalRead(BUTTON_PIN);
|
||||
|
||||
if (BUTTON_STATE == HIGH) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
}
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch03/UnreliableSwitch/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch03/UnreliableSwitch/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
@@ -0,0 +1,21 @@
|
||||
const unsigned int BUTTON_PIN = 7;
|
||||
const unsigned int LED_PIN = 13;
|
||||
|
||||
int ledState = LOW;
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
const int CURRENT_BUTTON_STATE = digitalRead(BUTTON_PIN);
|
||||
|
||||
if (CURRENT_BUTTON_STATE == HIGH) {
|
||||
ledState = HIGH;
|
||||
} else {
|
||||
ledState = LOW;
|
||||
}
|
||||
|
||||
digitalWrite(LED_PIN, ledState);
|
||||
}
|
1
oldstuff/arduino/msaqsg/ch04/Telegraph/Makefile
Symbolic link
1
oldstuff/arduino/msaqsg/ch04/Telegraph/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../arduino.mk
|
5
oldstuff/arduino/msaqsg/ch04/Telegraph/Telegraph.ino
Normal file
5
oldstuff/arduino/msaqsg/ch04/Telegraph/Telegraph.ino
Normal file
@@ -0,0 +1,5 @@
|
||||
void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
105
oldstuff/arduino/msaqsg/ch04/Telegraph/telegraph.cpp
Normal file
105
oldstuff/arduino/msaqsg/ch04/Telegraph/telegraph.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
// vim:filetype=arduino
|
||||
#include <ctype.h>
|
||||
#include <Arduino.h>
|
||||
#include "telegraph.h"
|
||||
|
||||
const char* LETTERS[] = {
|
||||
".-", // A
|
||||
"-...", // B
|
||||
"-.-.", // C
|
||||
"-..", // D
|
||||
".", // E
|
||||
"..-.", // F
|
||||
"--.", // G
|
||||
"....", // H
|
||||
"..", // I
|
||||
".---", // J
|
||||
"-.-", // K
|
||||
".-..", // L
|
||||
"--", // M
|
||||
"-.", // N
|
||||
"---", // O
|
||||
".--.", // P
|
||||
"--.-", // Q
|
||||
".-.", // R
|
||||
"...", // S
|
||||
"-", // T
|
||||
"..-", // U
|
||||
"...-", // V
|
||||
".--", // W
|
||||
"-..-", // X
|
||||
"-.--", // Y
|
||||
"--.." // Z
|
||||
};
|
||||
|
||||
const char* DIGITS[] = {
|
||||
"-----", // 0
|
||||
".----", // 1
|
||||
"..---", // 2
|
||||
"...--", // 3
|
||||
"....-", // 4
|
||||
".....", // 5
|
||||
"-....", // 6
|
||||
"--...", // 7
|
||||
"---..", // 8
|
||||
"----.", // 9
|
||||
};
|
||||
|
||||
Telegraph::Telegraph(const int output_pin, const int dit_length) {
|
||||
_output_pin = output_pin;
|
||||
_dit_length = dit_length;
|
||||
_dah_length = dit_length * 3;
|
||||
pinMode(_output_pin, OUTPUT);
|
||||
}
|
||||
|
||||
void Telegraph::output_code(const char* code) {
|
||||
const unsigned int code_length = strlen(code);
|
||||
|
||||
for (unsigned int i = 0; i < code_length; i++) {
|
||||
if (code[i] == '.') {
|
||||
dit();
|
||||
} else {
|
||||
dah();
|
||||
}
|
||||
|
||||
if (i != code_length - 1) {
|
||||
delay(_dit_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Telegraph::dit() {
|
||||
Serial.print(".");
|
||||
output_symbol(_dit_length);
|
||||
}
|
||||
|
||||
void Telegraph::dah() {
|
||||
Serial.print("-");
|
||||
output_symbol(_dah_length);
|
||||
}
|
||||
|
||||
void Telegraph::output_symbol(const int length) {
|
||||
digitalWrite(_output_pin, HIGH);
|
||||
delay(length);
|
||||
digitalWrite(_output_pin, LOW);
|
||||
}
|
||||
|
||||
void Telegraph::send_message(const char* message) {
|
||||
unsigned int message_length = (unsigned int)strlen(message);
|
||||
for (unsigned int i = 0; i < message_length; i++) {
|
||||
const char current_char = toupper(message[i]);
|
||||
|
||||
if (isalpha(current_char)) {
|
||||
output_code(LETTERS[current_char - 'A']);
|
||||
delay(_dah_length);
|
||||
} else if (isdigit(current_char)) {
|
||||
output_code(DIGITS[current_char - '0']);
|
||||
delay(_dah_length);
|
||||
} else if (current_char == ' ') {
|
||||
Serial.print(" ");
|
||||
delay(_dit_length * 7);
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
18
oldstuff/arduino/msaqsg/ch04/Telegraph/telegraph.h
Normal file
18
oldstuff/arduino/msaqsg/ch04/Telegraph/telegraph.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __TELEGRAPH_H__
|
||||
#define __TELEGRAPH_H__
|
||||
|
||||
class Telegraph {
|
||||
public:
|
||||
Telegraph(const int output_pin, const int dit_length);
|
||||
void send_message(const char* message);
|
||||
private:
|
||||
void dit();
|
||||
void dah();
|
||||
void output_code(const char* code);
|
||||
void output_symbol(const int length);
|
||||
|
||||
int _output_pin;
|
||||
int _dit_length;
|
||||
int _dah_length;
|
||||
};
|
||||
#endif
|
1
oldstuff/d/prog-lang-book/.gitignore
vendored
Normal file
1
oldstuff/d/prog-lang-book/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/bin/*
|
9
oldstuff/d/prog-lang-book/Makefile
Normal file
9
oldstuff/d/prog-lang-book/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
ALL_SOURCES := $(shell find src -name '*.d')
|
||||
ALL_TARGETS := $(patsubst src/%.d,bin/%,$(ALL_SOURCES))
|
||||
|
||||
bin/%: src/%.d
|
||||
dmd $^ -of$@
|
||||
|
||||
all: $(ALL_TARGETS)
|
||||
|
||||
.PHONY: all
|
0
oldstuff/d/prog-lang-book/bin/.gitkeep
Normal file
0
oldstuff/d/prog-lang-book/bin/.gitkeep
Normal file
19
oldstuff/d/prog-lang-book/src/height_conversions.d
Normal file
19
oldstuff/d/prog-lang-book/src/height_conversions.d
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
Compute heights in centimeters for a range of heights
|
||||
expressed in feet and inches
|
||||
*/
|
||||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
// Values unlikely to change soon
|
||||
immutable inchesPerFoot = 12;
|
||||
immutable cmPerInch = 2.54;
|
||||
|
||||
// Loop'n write
|
||||
foreach (feet; 5 .. 7) {
|
||||
foreach (inches; 0 .. inchesPerFoot) {
|
||||
writefln("%s'%s''\t%s", feet, inches,
|
||||
(feet * inchesPerFoot + inches) * cmPerInch);
|
||||
}
|
||||
}
|
||||
}
|
5
oldstuff/d/prog-lang-book/src/hello.d
Executable file
5
oldstuff/d/prog-lang-book/src/hello.d
Executable file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env rdmd
|
||||
import std.stdio;
|
||||
void main() {
|
||||
writeln("Hello, world!");
|
||||
}
|
3
oldstuff/gnu-c/.gitignore
vendored
Normal file
3
oldstuff/gnu-c/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/temperatures
|
||||
/qsort-example
|
||||
/getopt-example
|
6
oldstuff/gnu-c/Makefile
Normal file
6
oldstuff/gnu-c/Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
TARGETS := $(patsubst %.c,%,$(wildcard *.c))
|
||||
CFLAGS += -g -Wall -Wextra -pedantic -pedantic-errors
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
.PHONY: all
|
54
oldstuff/gnu-c/getopt-example.c
Normal file
54
oldstuff/gnu-c/getopt-example.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Example getopt usage mostly from getopt(3)
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
|
||||
|
||||
void die_usage(char *prog, char *msg) {
|
||||
fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", prog);
|
||||
if (msg != NULL) {
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *prog;
|
||||
int flags, opt;
|
||||
int nsecs, tfnd;
|
||||
|
||||
nsecs = 0;
|
||||
tfnd = 0;
|
||||
flags = 0;
|
||||
prog = basename(argv[0]);
|
||||
|
||||
while ((opt = getopt(argc, argv, "hnt:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'n':
|
||||
flags = 1;
|
||||
break;
|
||||
case 't':
|
||||
nsecs = atoi(optarg);
|
||||
tfnd = 1;
|
||||
break;
|
||||
case 'h':
|
||||
default: /* '?' */
|
||||
die_usage(prog, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind);
|
||||
|
||||
if (optind >= argc) {
|
||||
die_usage(prog, "Expected argument after options");
|
||||
}
|
||||
|
||||
printf("name argument = %s\n", argv[optind]);
|
||||
printf("nsecs = %d\n", nsecs);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
34
oldstuff/gnu-c/qsort-example.c
Normal file
34
oldstuff/gnu-c/qsort-example.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* C Sorting example mostly from qsort(3)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
|
||||
static int cmpstringp(const void *p1, const void *p2) {
|
||||
/* The actual arguments to this function are "pointers to
|
||||
pointers to char", but strcmp(3) arguments are "pointers
|
||||
to char", hence the following cast plus dereference */
|
||||
|
||||
return strcmp(*(char * const *)p1, *(char * const *)p2);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int j;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s <string>...\n", basename(argv[0]));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
qsort(&argv[1], argc - 1, sizeof(argv[1]), cmpstringp);
|
||||
|
||||
for (j = 1; j < argc; j++) {
|
||||
puts(argv[j]);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
68
oldstuff/gnu-c/temperatures.c
Normal file
68
oldstuff/gnu-c/temperatures.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libgen.h>
|
||||
|
||||
|
||||
double c2f(double celsius) {
|
||||
return ((9.0 / 5.0) * celsius) + 32.0;
|
||||
}
|
||||
|
||||
|
||||
double f2c(double fahrenheit) {
|
||||
return (5.0 / 9.0) * (fahrenheit - 32.0);
|
||||
}
|
||||
|
||||
|
||||
void die_usage(const char *prog, const char *msg) {
|
||||
fprintf(stderr, "Usage: %s <temp>[FC]\n", prog);
|
||||
if (msg != NULL) {
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
const char * prog = basename(argv[0]);
|
||||
int ret;
|
||||
char msg[255];
|
||||
double temp;
|
||||
char scale = '\0';
|
||||
const char *in_fmt = "%lf%c";
|
||||
const char *out_fmt = "%.2lf%c\n";
|
||||
const char *temp_string;
|
||||
|
||||
if (argc < 2) {
|
||||
die_usage(prog, NULL);
|
||||
}
|
||||
|
||||
if (((int)strlen(argv[1]) == 1) && (argv[1][0] == '-')) {
|
||||
ret = fscanf(stdin, in_fmt, &temp, &scale);
|
||||
} else {
|
||||
temp_string = argv[1];
|
||||
ret = sscanf(temp_string, in_fmt, &temp, &scale);
|
||||
}
|
||||
|
||||
if ((ret == 0) || (ret == EOF)) {
|
||||
die_usage(prog, "No temperature provided!");
|
||||
}
|
||||
|
||||
if (ret == 1) {
|
||||
die_usage(prog, "No scale provided!");
|
||||
}
|
||||
|
||||
switch (scale) {
|
||||
case 'C':
|
||||
printf(out_fmt, c2f(temp), 'F');
|
||||
break;
|
||||
case 'F':
|
||||
printf(out_fmt, f2c(temp), 'C');
|
||||
break;
|
||||
default:
|
||||
sprintf(msg, "Unknown scale: '%c'", scale);
|
||||
die_usage(prog, msg);
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
4
oldstuff/gotime/.gitignore
vendored
Normal file
4
oldstuff/gotime/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/bin/
|
||||
/.env
|
||||
/.installation/go/
|
||||
/src/github.com/
|
5
oldstuff/gotime/.installation/Makefile
Normal file
5
oldstuff/gotime/.installation/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
go/src/all.bash:
|
||||
hg clone -u release https://code.google.com/p/go
|
||||
|
||||
go/bin/go: go/src/all.bash
|
||||
cd go/src && ./all.bash
|
34
oldstuff/gotime/Makefile
Normal file
34
oldstuff/gotime/Makefile
Normal file
@@ -0,0 +1,34 @@
|
||||
TARGETS = \
|
||||
github.com/meatballhat/box-o-sand/gotime/amqpfun \
|
||||
github.com/meatballhat/box-o-sand/gotime/amqpfun-runner \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/buffered-channels \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/channels \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-fibonacci-closure \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-http-handlers \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-maps \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-rot13-reader \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-slices \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/exercise-sqrt \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/generic-maps \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/goroutines \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/hello-web \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/maps \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/ranges \
|
||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/selects \
|
||||
github.com/meatballhat/box-o-sand/gotime/junkdrawer/greppish \
|
||||
github.com/meatballhat/box-o-sand/gotime/junkdrawer/reflectish \
|
||||
github.com/meatballhat/box-o-sand/gotime/junkdrawer/randimg
|
||||
|
||||
test: build
|
||||
go test -x -v $(TARGETS)
|
||||
|
||||
build: deps
|
||||
go install -x $(TARGETS)
|
||||
|
||||
deps:
|
||||
go get -n -x $(TARGETS)
|
||||
|
||||
clean:
|
||||
go clean -x -i $(TARGETS)
|
||||
|
||||
.PHONY: test build clean fmt
|
24
oldstuff/gotime/amqpfun-runner/main.go
Normal file
24
oldstuff/gotime/amqpfun-runner/main.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/meatballhat/box-o-sand/gotime/amqpfun"
|
||||
)
|
||||
|
||||
const USAGE = "Usage: amqpfun-runner (publish|consume)"
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println(USAGE)
|
||||
os.Exit(1)
|
||||
}
|
||||
if os.Args[1] == "publish" {
|
||||
amqpfun.Publish()
|
||||
} else if os.Args[1] == "consume" {
|
||||
amqpfun.Consume()
|
||||
}
|
||||
}
|
185
oldstuff/gotime/amqpfun/workers.go
Normal file
185
oldstuff/gotime/amqpfun/workers.go
Normal file
@@ -0,0 +1,185 @@
|
||||
package amqpfun
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
import (
|
||||
"github.com/streadway/amqp"
|
||||
)
|
||||
|
||||
func Publish() {
|
||||
// Connects opens an AMQP connection from the credentials in the URL.
|
||||
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
|
||||
if err != nil {
|
||||
log.Fatalf("connection.open: %s", err)
|
||||
}
|
||||
|
||||
// This waits for a server acknowledgment which means the sockets will have
|
||||
// flushed all outbound publishings prior to returning. It's important to
|
||||
// block on Close to not lose any publishings.
|
||||
defer conn.Close()
|
||||
|
||||
c, err := conn.Channel()
|
||||
if err != nil {
|
||||
log.Fatalf("channel.open: %s", err)
|
||||
}
|
||||
|
||||
// We declare our topology on both the publisher and consumer to ensure they
|
||||
// are the same. This is part of AMQP being a programmable messaging model.
|
||||
//
|
||||
// See the Channel.Consume example for the complimentary declare.
|
||||
err = c.ExchangeDeclare("logs", "topic", true, false, false, false, nil)
|
||||
if err != nil {
|
||||
log.Fatal("exchange.declare: %s", err)
|
||||
}
|
||||
|
||||
// Prepare this message to be persistent. Your publishing requirements may
|
||||
// be different.
|
||||
msg := amqp.Publishing{
|
||||
DeliveryMode: amqp.Persistent,
|
||||
Timestamp: time.Now(),
|
||||
ContentType: "text/plain",
|
||||
Body: []byte("Go Go AMQP!"),
|
||||
}
|
||||
|
||||
// This is not a mandatory delivery, so it will be dropped if there are no
|
||||
// queues bound to the logs exchange.
|
||||
err = c.Publish("logs", "info", false, false, msg)
|
||||
if err != nil {
|
||||
// Since publish is asynchronous this can happen if the network connection
|
||||
// is reset or if the server has run out of resources.
|
||||
log.Fatal("basic.publish: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Consume() {
|
||||
// Connects opens an AMQP connection from the credentials in the URL.
|
||||
conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
|
||||
if err != nil {
|
||||
log.Fatalf("connection.open: %s", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
c, err := conn.Channel()
|
||||
if err != nil {
|
||||
log.Fatalf("channel.open: %s", err)
|
||||
}
|
||||
|
||||
// We declare our topology on both the publisher and consumer to ensure they
|
||||
// are the same. This is part of AMQP being a programmable messaging model.
|
||||
//
|
||||
// See the Channel.Publish example for the complimentary declare.
|
||||
err = c.ExchangeDeclare("logs", "topic", true, false, false, false, nil)
|
||||
if err != nil {
|
||||
log.Fatal("exchange.declare: %s", err)
|
||||
}
|
||||
|
||||
// Establish our queue topologies that we are responsible for
|
||||
type bind struct {
|
||||
queue string
|
||||
key string
|
||||
}
|
||||
|
||||
bindings := []bind{
|
||||
bind{"page", "alert"},
|
||||
bind{"email", "info"},
|
||||
bind{"firehose", "#"},
|
||||
}
|
||||
|
||||
for _, b := range bindings {
|
||||
_, err = c.QueueDeclare(b.queue, true, false, false, false, nil)
|
||||
if err != nil {
|
||||
log.Fatal("queue.declare: %s", err)
|
||||
}
|
||||
|
||||
err = c.QueueBind(b.queue, b.key, "logs", false, nil)
|
||||
if err != nil {
|
||||
log.Fatal("queue.bind: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Set our quality of service. Since we're sharing 3 consumers on the same
|
||||
// channel, we want at least 3 messages in flight.
|
||||
err = c.Qos(3, 0, false)
|
||||
if err != nil {
|
||||
log.Fatal("basic.qos: %s", err)
|
||||
}
|
||||
|
||||
// Establish our consumers that have different responsibilities. Our first
|
||||
// two queues do not ack the messages on the server, so require to be acked
|
||||
// on the client.
|
||||
|
||||
pages, err := c.Consume("page", "pager", false, false, false, false, nil)
|
||||
if err != nil {
|
||||
log.Fatal("basic.consume: %s", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for page := range pages {
|
||||
// ... this consumer is responsible for sending pages per log
|
||||
log.Printf("Processing page: %+v\n", page)
|
||||
page.Ack(false)
|
||||
}
|
||||
}()
|
||||
|
||||
// Notice how the concern for which messages arrive here are in the AMQP
|
||||
// topology and not in the queue. We let the server pick a consumer tag this
|
||||
// time.
|
||||
|
||||
emails, err := c.Consume("email", "", false, false, false, false, nil)
|
||||
if err != nil {
|
||||
log.Fatal("basic.consume: %s", err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for email := range emails {
|
||||
// ... this consumer is responsible for sending emails per log
|
||||
log.Printf("Processing email: %+v\n", email)
|
||||
email.Ack(false)
|
||||
}
|
||||
}()
|
||||
|
||||
// This consumer requests that every message is acknowledged as soon as it's
|
||||
// delivered.
|
||||
|
||||
firehose, err := c.Consume("firehose", "", true, false, false, false, nil)
|
||||
if err != nil {
|
||||
log.Fatal("basic.consume: %s", err)
|
||||
}
|
||||
|
||||
// To show how to process the items in parallel, we'll use a work pool.
|
||||
for i := 0; i < runtime.NumCPU(); i++ {
|
||||
go func(work <-chan amqp.Delivery) {
|
||||
for drop := range work {
|
||||
// ... this consumer pulls from the firehose and doesn't need to acknowledge
|
||||
log.Printf("Processing firehose drop: %+v\n", drop)
|
||||
}
|
||||
}(firehose)
|
||||
}
|
||||
|
||||
// // Wait until you're ready to finish, could be a signal handler here.
|
||||
// time.Sleep(10 * time.Second)
|
||||
q := make(chan os.Signal)
|
||||
signal.Notify(q, os.Interrupt)
|
||||
|
||||
log.Println("Waiting...")
|
||||
<-q
|
||||
log.Println("Shutting down...")
|
||||
|
||||
// Cancelling a consumer by name will finish the range and gracefully end the
|
||||
// goroutine
|
||||
err = c.Cancel("pager", false)
|
||||
if err != nil {
|
||||
log.Fatal("basic.cancel: %s", err)
|
||||
}
|
||||
|
||||
// deferred closing the Connection will also finish the consumer's ranges of
|
||||
// their delivery chans. If you need every delivery to be processed, make
|
||||
// sure to wait for all consumers goroutines to finish before exiting your
|
||||
// process.
|
||||
}
|
29
oldstuff/gotime/gotour-artifacts/buffered-channels/main.go
Normal file
29
oldstuff/gotime/gotour-artifacts/buffered-channels/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c := make(chan int, 2)
|
||||
q := make(chan bool)
|
||||
|
||||
go func(c chan int) {
|
||||
for i := range c {
|
||||
fmt.Println("\t", i, "<- popped")
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
}
|
||||
}(c)
|
||||
|
||||
go func(c chan int) {
|
||||
i := 0
|
||||
for {
|
||||
c <- i
|
||||
fmt.Println("pushed ->", i)
|
||||
i += 1
|
||||
}
|
||||
}(c)
|
||||
|
||||
<-q
|
||||
}
|
31
oldstuff/gotime/gotour-artifacts/channels/main.go
Normal file
31
oldstuff/gotime/gotour-artifacts/channels/main.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
func sum(a []int, c chan int) {
|
||||
sum := 0
|
||||
for _, v := range a {
|
||||
sum += v
|
||||
}
|
||||
to_sleep := time.Duration(100*math.Abs(float64(sum))) * time.Millisecond
|
||||
fmt.Printf("Sleeping %s...\n", to_sleep)
|
||||
time.Sleep(to_sleep)
|
||||
c <- sum
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := []int{7, 2, 8, -9, 4, 0}
|
||||
|
||||
c := make(chan int)
|
||||
go sum(a[:len(a)/2], c)
|
||||
go sum(a[len(a)/2:], c)
|
||||
x := <-c
|
||||
fmt.Printf("x = %d\n", x)
|
||||
y := <-c
|
||||
fmt.Printf("y = %d\n", y)
|
||||
fmt.Println(x, y, x+y)
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// fibonacci is a function that returns
|
||||
// a function that returns an int.
|
||||
func fibonacci() func() int {
|
||||
prev := 0
|
||||
cur := 1
|
||||
return func() int {
|
||||
old_cur := cur
|
||||
cur = prev + cur
|
||||
prev = old_cur
|
||||
return cur
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
f := fibonacci()
|
||||
for i := 0; i < 10; i++ {
|
||||
fmt.Println(f())
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type String string
|
||||
|
||||
type Struct struct {
|
||||
Greeting string
|
||||
Punct string
|
||||
Who string
|
||||
}
|
||||
|
||||
func (s String) ServeHTTP(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request) {
|
||||
fmt.Fprintf(w, "%s\n", s)
|
||||
}
|
||||
|
||||
func (s Struct) ServeHTTP(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request) {
|
||||
fmt.Fprintf(w, "%s%s %s", s.Greeting, s.Punct, s.Who)
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.Handle("/string", String("I'm a frayed knot."))
|
||||
http.Handle("/struct", &Struct{"Hello", ":", "Gophers!"})
|
||||
http.ListenAndServe("localhost:4000", nil)
|
||||
}
|
19
oldstuff/gotime/gotour-artifacts/exercise-maps/main.go
Normal file
19
oldstuff/gotime/gotour-artifacts/exercise-maps/main.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/go-tour/wc"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func WordCount(s string) map[string]int {
|
||||
counts := make(map[string]int)
|
||||
words := strings.Fields(s)
|
||||
for _, word := range words {
|
||||
counts[word]++
|
||||
}
|
||||
return counts
|
||||
}
|
||||
|
||||
func main() {
|
||||
wc.Test(WordCount)
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var lookupTable = map[byte]byte{
|
||||
'A': 'N',
|
||||
'B': 'O',
|
||||
'C': 'P',
|
||||
'D': 'Q',
|
||||
'E': 'R',
|
||||
'F': 'S',
|
||||
'G': 'T',
|
||||
'H': 'U',
|
||||
'I': 'V',
|
||||
'J': 'W',
|
||||
'K': 'X',
|
||||
'L': 'Y',
|
||||
'M': 'Z',
|
||||
'N': 'A',
|
||||
'O': 'B',
|
||||
'P': 'C',
|
||||
'Q': 'D',
|
||||
'R': 'E',
|
||||
'S': 'F',
|
||||
'T': 'G',
|
||||
'U': 'H',
|
||||
'V': 'I',
|
||||
'W': 'J',
|
||||
'X': 'K',
|
||||
'Y': 'L',
|
||||
'Z': 'M',
|
||||
'a': 'n',
|
||||
'b': 'o',
|
||||
'c': 'p',
|
||||
'd': 'q',
|
||||
'e': 'r',
|
||||
'f': 's',
|
||||
'g': 't',
|
||||
'h': 'u',
|
||||
'i': 'v',
|
||||
'j': 'w',
|
||||
'k': 'x',
|
||||
'l': 'y',
|
||||
'm': 'z',
|
||||
'n': 'a',
|
||||
'o': 'b',
|
||||
'p': 'c',
|
||||
'q': 'd',
|
||||
'r': 'e',
|
||||
's': 'f',
|
||||
't': 'g',
|
||||
'u': 'h',
|
||||
'v': 'i',
|
||||
'w': 'j',
|
||||
'x': 'k',
|
||||
'y': 'l',
|
||||
'z': 'm',
|
||||
}
|
||||
|
||||
type rot13Reader struct {
|
||||
reader io.Reader
|
||||
}
|
||||
|
||||
func (rot *rot13Reader) Read(p []byte) (i int, err error) {
|
||||
if len(p) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
buf := make([]byte, len(p))
|
||||
i, err = rot.reader.Read(buf)
|
||||
|
||||
var (
|
||||
b, c byte
|
||||
found bool
|
||||
)
|
||||
for i := range buf {
|
||||
b = buf[i]
|
||||
c, found = lookupTable[b]
|
||||
if found {
|
||||
p[i] = c
|
||||
} else {
|
||||
p[i] = b
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := strings.NewReader("Lbh penpxrq gur pbqr!")
|
||||
r := rot13Reader{s}
|
||||
io.Copy(os.Stdout, &r)
|
||||
fmt.Println("")
|
||||
}
|
20
oldstuff/gotime/gotour-artifacts/exercise-slices/main.go
Normal file
20
oldstuff/gotime/gotour-artifacts/exercise-slices/main.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/go-tour/pic"
|
||||
)
|
||||
|
||||
func Pic(dx, dy int) [][]uint8 {
|
||||
cols := make([][]uint8, dy)
|
||||
for i := range cols {
|
||||
cols[i] = make([]uint8, dx)
|
||||
for j := range cols[i] {
|
||||
cols[i][j] = uint8(j ^ i)
|
||||
}
|
||||
}
|
||||
return cols
|
||||
}
|
||||
|
||||
func main() {
|
||||
pic.Show(Pic)
|
||||
}
|
25
oldstuff/gotime/gotour-artifacts/exercise-sqrt/main.go
Normal file
25
oldstuff/gotime/gotour-artifacts/exercise-sqrt/main.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// using Newton's method
|
||||
func Sqrt(x float64) float64 {
|
||||
z := x - (x * 0.1)
|
||||
for i := 0; i < 1000; i++ {
|
||||
newZ := z - (((z * z) - x) / 2 * z)
|
||||
diff := math.Abs(newZ) - math.Abs(z)
|
||||
if math.Abs(diff) < 0.01 {
|
||||
return newZ
|
||||
}
|
||||
z = newZ
|
||||
}
|
||||
return z
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf("stdlib -> %f\n", math.Sqrt(2))
|
||||
fmt.Printf("newton -> %f\n", Sqrt(2))
|
||||
}
|
37
oldstuff/gotime/gotour-artifacts/generic-maps/main.go
Normal file
37
oldstuff/gotime/gotour-artifacts/generic-maps/main.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Shoe struct {
|
||||
Hamsters uint8
|
||||
Tacos []string
|
||||
}
|
||||
|
||||
type Cheese struct {
|
||||
Holes float64
|
||||
Flavors map[string]string
|
||||
ShelfLife time.Time
|
||||
}
|
||||
|
||||
func main() {
|
||||
v := make(map[string]interface{})
|
||||
v["loafer"] = &Shoe{
|
||||
Hamsters: uint8(49),
|
||||
Tacos: []string{"spicy", "crunchy"},
|
||||
}
|
||||
flavors := make(map[string]string)
|
||||
flavors["fruit01"] = "grape"
|
||||
flavors["fruit02"] = "apple"
|
||||
v["cheddar"] = &Cheese{
|
||||
Holes: float64(9.2),
|
||||
Flavors: flavors,
|
||||
ShelfLife: time.Date(1999, time.Month(8), 12, 7, 15, 22, 0, time.UTC),
|
||||
}
|
||||
|
||||
fmt.Printf("v = %+v\n", v)
|
||||
fmt.Printf("v[\"loafer\"] = %+v\n", v["loafer"])
|
||||
fmt.Printf("v[\"cheddar\"] = %+v\n", v["cheddar"])
|
||||
}
|
18
oldstuff/gotime/gotour-artifacts/goroutines/main.go
Normal file
18
oldstuff/gotime/gotour-artifacts/goroutines/main.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func say(s string) {
|
||||
for i := 0; i < 5; i++ {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
fmt.Println(s)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
go say("world")
|
||||
say("hello")
|
||||
}
|
19
oldstuff/gotime/gotour-artifacts/hello-web/main.go
Normal file
19
oldstuff/gotime/gotour-artifacts/hello-web/main.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Hello struct{}
|
||||
|
||||
func (h Hello) ServeHTTP(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request) {
|
||||
fmt.Fprint(w, "Hello!\n")
|
||||
}
|
||||
|
||||
func main() {
|
||||
var h Hello
|
||||
http.ListenAndServe("localhost:4000", h)
|
||||
}
|
18
oldstuff/gotime/gotour-artifacts/maps/main.go
Normal file
18
oldstuff/gotime/gotour-artifacts/maps/main.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// From go-tour #28
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Vertex struct {
|
||||
Lat, Long float64
|
||||
}
|
||||
|
||||
var m map[string]Vertex
|
||||
|
||||
func main() {
|
||||
m = make(map[string]Vertex)
|
||||
m["Bell Labs"] = Vertex{
|
||||
40.68433, 74.39967,
|
||||
}
|
||||
fmt.Println(m["Bell Labs"])
|
||||
}
|
13
oldstuff/gotime/gotour-artifacts/ranges/main.go
Normal file
13
oldstuff/gotime/gotour-artifacts/ranges/main.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
pow := make([]int, 10)
|
||||
for i := range pow {
|
||||
pow[i] = 1 << uint(i)
|
||||
}
|
||||
for _, value := range pow {
|
||||
fmt.Printf("%d\n", value)
|
||||
}
|
||||
}
|
39
oldstuff/gotime/gotour-artifacts/selects/main.go
Normal file
39
oldstuff/gotime/gotour-artifacts/selects/main.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func fibonacci(c, quit chan int) {
|
||||
x, y := 0, 1
|
||||
for {
|
||||
select {
|
||||
case c <- x:
|
||||
x, y = y, x + y
|
||||
case <- quit:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
count := 10
|
||||
if len(os.Args) > 1 {
|
||||
var err error
|
||||
if count, err = strconv.Atoi(os.Args[1]); err != nil {
|
||||
fmt.Fprintln(os.Stderr, os.Args[1], "is not an int!")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
c := make(chan int)
|
||||
quit := make(chan int)
|
||||
go func(count int) {
|
||||
for i := 0; i < count; i++ {
|
||||
fmt.Println(<-c)
|
||||
}
|
||||
quit <- 0
|
||||
}(count)
|
||||
fibonacci(c, quit)
|
||||
}
|
51
oldstuff/gotime/junkdrawer/greppish/main.go
Normal file
51
oldstuff/gotime/junkdrawer/greppish/main.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const USAGE = `Usage: greppish <regex> [filename]
|
||||
|
||||
Prints lines matching <regex> in [filename] or standard input.`
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println(USAGE)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
regMatch, err := regexp.Compile(os.Args[1])
|
||||
if err != nil {
|
||||
log.Fatal("Problem compiling regex: ", err)
|
||||
}
|
||||
|
||||
inbuf := bufio.NewReader(os.Stdin)
|
||||
|
||||
if len(os.Args) > 2 {
|
||||
infile, err := os.Open(os.Args[2])
|
||||
if err != nil {
|
||||
log.Fatal("Problem opening input file: ", err)
|
||||
}
|
||||
inbuf = bufio.NewReader(infile)
|
||||
}
|
||||
|
||||
var line string
|
||||
|
||||
for {
|
||||
line, err = inbuf.ReadString('\n')
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
os.Exit(0)
|
||||
}
|
||||
log.Fatal("Problem reading input: ", err)
|
||||
}
|
||||
if regMatch.MatchString(line) {
|
||||
fmt.Printf(line)
|
||||
}
|
||||
}
|
||||
}
|
52
oldstuff/gotime/junkdrawer/randimg/main.go
Normal file
52
oldstuff/gotime/junkdrawer/randimg/main.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"flag"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"math/rand"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
outfile = flag.String("o", "randimg.png", "Output PNG file name")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
out, err := os.Create(*outfile)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
imgRect := image.Rect(0, 0, 200, 200)
|
||||
img := image.NewGray(imgRect)
|
||||
draw.Draw(img, img.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)
|
||||
|
||||
for y := 0; y < 200; y += 10 {
|
||||
for x := 0; x < 200; x += 10 {
|
||||
fill := &image.Uniform{color.Black}
|
||||
if rand.Intn(10) % 2 == 0 {
|
||||
fill = &image.Uniform{color.White}
|
||||
}
|
||||
|
||||
draw.Draw(img, image.Rect(x, y, x+10, y+10), fill, image.ZP, draw.Src)
|
||||
}
|
||||
}
|
||||
|
||||
err = png.Encode(out, img)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
fmt.Printf("Wrote random image to \"%s\"\n", *outfile)
|
||||
os.Exit(0)
|
||||
}
|
41
oldstuff/gotime/junkdrawer/reflectish/main.go
Normal file
41
oldstuff/gotime/junkdrawer/reflectish/main.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type Fooer interface {
|
||||
Foo(int) int
|
||||
}
|
||||
|
||||
type Bar struct {
|
||||
SomeField int
|
||||
}
|
||||
|
||||
func (this *Bar) Foo(x int) int {
|
||||
return x
|
||||
}
|
||||
|
||||
type Baz struct {
|
||||
SomeField int
|
||||
}
|
||||
|
||||
func (this Baz) Foo(x int) int {
|
||||
return x
|
||||
}
|
||||
|
||||
func main() {
|
||||
var bar, baz Fooer
|
||||
|
||||
bar = &Bar{
|
||||
SomeField: 5,
|
||||
}
|
||||
|
||||
baz = Baz{
|
||||
SomeField: 5,
|
||||
}
|
||||
|
||||
fmt.Println(reflect.ValueOf(baz).FieldByName("SomeField"))
|
||||
fmt.Println(reflect.Indirect(reflect.ValueOf(bar)).FieldByName("SomeField"))
|
||||
}
|
102
oldstuff/html5/canvas/mdn-tutorial.html
Normal file
102
oldstuff/html5/canvas/mdn-tutorial.html
Normal file
@@ -0,0 +1,102 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>MDN Canvas Tutorial</title>
|
||||
<style type="text/css">
|
||||
canvas {
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="tut0" width="150" height="150"></canvas>
|
||||
<canvas id="tut1" width="150" height="150"></canvas>
|
||||
<canvas id="tut2" width="150" height="150"></canvas>
|
||||
<canvas id="tut3" width="150" height="150"></canvas>
|
||||
<canvas id="tut4" width="150" height="200"></canvas>
|
||||
|
||||
<script type="text/javascript">
|
||||
var drawings = {};
|
||||
|
||||
drawings.draw0 = function () {
|
||||
var ctx = document.getElementById('tut0').getContext('2d');
|
||||
|
||||
ctx.fillStyle = 'rgb(200, 0, 0)';
|
||||
ctx.fillRect(10, 10, 55, 50);
|
||||
|
||||
ctx.fillStyle = 'rgba(0, 0, 200, 0.5)';
|
||||
ctx.fillRect(30, 30, 55, 50);
|
||||
};
|
||||
|
||||
drawings.draw1 = function() {
|
||||
var ctx = document.getElementById('tut1').getContext('2d');
|
||||
|
||||
ctx.fillRect(25, 25, 100, 100);
|
||||
ctx.clearRect(45, 45, 60, 60);
|
||||
ctx.strokeRect(50, 50, 50, 50);
|
||||
};
|
||||
|
||||
drawings.draw2 = function() {
|
||||
var ctx = document.getElementById('tut2').getContext('2d');
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.arc(75, 75, 50, 0, Math.PI*2, true);
|
||||
ctx.moveTo(110, 75);
|
||||
ctx.arc(75, 75, 35, 0, Math.PI, false);
|
||||
ctx.moveTo(65, 65);
|
||||
ctx.arc(60, 65, 5, 0, Math.PI*2, true);
|
||||
ctx.moveTo(95, 65);
|
||||
ctx.arc(90, 65, 5, 0, Math.PI*2, true);
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
drawings.draw3 = function() {
|
||||
var ctx = document.getElementById('tut3').getContext('2d');
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(25, 25);
|
||||
ctx.lineTo(105, 25);
|
||||
ctx.lineTo(25, 105);
|
||||
ctx.fill();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(125, 125);
|
||||
ctx.lineTo(125, 45);
|
||||
ctx.lineTo(45, 125);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
drawings.draw4 = function() {
|
||||
var ctx = document.getElementById('tut4').getContext('2d');
|
||||
|
||||
for(var i=0; i<4; i++) {
|
||||
for(var j=0; j<3; j++) {
|
||||
ctx.beginPath();
|
||||
var x = 25+j*50,
|
||||
y = 25+i*50,
|
||||
radius = 20,
|
||||
startAngle = 0,
|
||||
endAngle = Math.PI+(Math.PI*j)/2,
|
||||
anticlockwise = i%2==0 ? false : true;
|
||||
|
||||
ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise);
|
||||
|
||||
if (i > 1) {
|
||||
ctx.fill();
|
||||
} else {
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
for(funcname in drawings) {
|
||||
console.log("Calling %s", funcname);
|
||||
drawings[funcname]();
|
||||
}
|
||||
}, false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
22
oldstuff/html5/server.go
Normal file
22
oldstuff/html5/server.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// I wanted to practice, plus maaaaaybe I'll want something dynamic on the
|
||||
// server side (???)
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var (
|
||||
docroot = flag.String("d", ".", "docroot for server")
|
||||
addr = flag.String("a", ":8990", "address on which to listen")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(*docroot)))
|
||||
fmt.Printf("Serving %q on %v\n", *docroot, *addr)
|
||||
http.ListenAndServe(*addr, nil)
|
||||
}
|
19
oldstuff/intro-to-algorithms/README
Normal file
19
oldstuff/intro-to-algorithms/README
Normal file
@@ -0,0 +1,19 @@
|
||||
_________________________________________
|
||||
/ Finally reading through the Cormen \
|
||||
| Leiserson Rivest Stein algorithms book, |
|
||||
\ mannn. /
|
||||
-----------------------------------------
|
||||
\ . .
|
||||
\ / `. .' "
|
||||
\ .---. < > < > .---.
|
||||
\ | \ \ - ~ ~ - / / |
|
||||
_____ ..-~ ~-..-~
|
||||
| | \~~~\.' `./~~~/
|
||||
--------- \__/ \__/
|
||||
.' O \ / / \ "
|
||||
(_____, `._.' | } \/~~~/
|
||||
`----. / } | / \__/
|
||||
`-. | / | / `. ,~~|
|
||||
~-.__| /_ - ~ ^| /- _ `..-'
|
||||
| / | / ~-. `-. _ _ _
|
||||
|_____| |_____| ~ - . _ _ _ _ _>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user