Skip to content

Instantly share code, notes, and snippets.

@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)" ¥
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 / gist:834832
Created February 19, 2011 04:51
R and rjson
library("rjson")
# use rjson
map_data <- fromJSON(paste(readLines("http://maps.google.com/maps/api/elevation/json?path=43.0,141.4|26.2,127.7&samples=500&sensor=false"), collapse=""))
# get a data from Google Elevation API
# convert JSON data into R object using fromJSON()
# toJSON(): convert R object into JSON data
elevation_data <- lapply(map_data$result, function(x){x$elevation})
@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.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
@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 / gist:856860
Created March 6, 2011 00:24
copy the source of active tab in Google Chrome
tell application "Google Chrome"
view source of active tab of window 1
repeat while loading of active tab of window 1
delay 0.1
end repeat
select all of active tab of window 1
copy selection of active tab of window 1
delete tab (active tab index of window 1) of window 1
end tell