Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
laclefyoshi / gist:800358
Created January 28, 2011 15:07
Arduino FlexiTimer2
#include <FlexiTimer2.h>
#define LedPin1 10
#define LedPin2 9
void blink1() {
digitalWrite(LedPin1, !digitalRead(LedPin1));
}
void blink2() {
digitalWrite(LedPin2, !digitalRead(LedPin2));
if __name__ == "__main__":
mode = raw_input("mode? ([a]stable or [m]onostable)> ")
if(mode == 'a'):
calcType = raw_input("result? ([f]req or [r]egister]> ")
if(calcType == 'f'):
r1, r2, c = map(float, raw_input("r1? r2? c?> ").split(" "))
aFreqCalculate({"r1": r1, "r2": r2, "c": c})
elif(calcType == 'r'):
(f, d, c) = map(float, raw_input("freq? duty? c?> ").split(" "))
aResisterCalculate({"freq": f, "duty": d, "c": c})
@laclefyoshi
laclefyoshi / mmode_timer555.py
Created February 5, 2011 04:16
Monostable mode of 555 timer
def mTimeCalculate(info):
r1 = info["r1"]
c = info["c"]
print "R1: %d, C: %f¥n¥tTime: %f(sec)¥n" % (r1, c, r1 * c * math.log(3))
# math.log(3) = 1.1
def mResisterCalculate(info):
t = info["time"]
c = info["c"]
@laclefyoshi
laclefyoshi / amode_timer555.py
Created February 5, 2011 04:29
Astable mode of 555 timer
def aFreqCalculate(info):
r1 = info["r1"]
r2 = info["r2"]
c = info["c"]
t1 = math.log(2) * (r1 + r2) * c # Time of HIGH
t2 = math.log(2) * r2 * c # Time of LOW
total = t1 + t2
freq = 1 / total
duty = t1 / total
print "R1: %d, R2: %d, C: %f¥n¥tHIGH:%f + LOW:%f = TOTAL:%f(sec)" ¥
@laclefyoshi
laclefyoshi / ActorTest.scala
Created February 26, 2011 02:16
2 Actors for Scala
/**
* -*- coding: utf-8 -*-
*
* Copyright : (c) SAEKI Yoshiyasu
* License : MIT-style license
* <http://www.opensource.org/licenses/mit-license.php>
**/
import scala.actors.Actor
class Counter(name:String) extends Actor {
@laclefyoshi
laclefyoshi / akka_test.py
Created February 26, 2011 02:26
Jython and Akka
#!/usr/bin/jython
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/02/26
from akka.actor import Actors, UntypedActor
@laclefyoshi
laclefyoshi / akka_remote_test.py
Created February 26, 2011 02:58
Jython and Remote Actor (Akka)
#!/usr/bin/jython
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/02/26
from akka.actor import Actors, UntypedActor
@laclefyoshi
laclefyoshi / akka_stm_test.py
Created February 26, 2011 03:03
Jython and STM/Agent (Akka)
#!/usr/bin/jython
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/02/26
from akka.stm import Atomic, Ref
import time
@laclefyoshi
laclefyoshi / mapreduce_main.py
Created March 5, 2011 04:31
processing MapReduce with Akka/Actor and Jython
import glob
import operator
import time
from mapreduce import *
if __name__ == "__main__":
start_time = time.time()
input_files = glob.glob("Edgar Allan Poe/*.txt")
@laclefyoshi
laclefyoshi / mapreduce.py
Created March 5, 2011 04:28
MapReduce with Akka/Actor and Jython
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/03/04
from akka.actor import Actors, UntypedActor
# from akka.dispatch import Futures
import collections