It is time to fight back
As a Geek, a gift should include some handwork, except code. Unless yours understand:
while(propose.times < 99) {
huahua.listen(phodal.ask("will")("you")("marry")("me"));
huahua.reply.propose ();
}
huahua.propose("Yes");
var ever = phodal.love(huahua) && huahua.love(phodal);
for(ever){;;;};
We need to build a romantic enviorment, and a gift, so we need:
Attention
: Please replace Programmer Valentine's Day Gift with xx Language.
Website Demo: http://valentine.phodal.com/
Our gift looks like a slide with some words, so prepare:
But, if you want to use picture like this, it will be...
In thinking about this movement in its heyday, and then the computer would be better. If do mobile applications, then the phone can be combined to better hardware.
To find all of my mobile devices, as shown in Figure:
As a Nokia fans, I don't like Microsoft。
Because I don't use Android Phone, iPhone, I don't have Windows 8 + Visual Studio, It means I couldn't do a mobile app.
But, we can we do a web application.
I looking some hardware to help me:
without some old chip:
Finally, we use Raspberry Pi
+ Arduino
.
We find this Star Projector
, also others(ps:it's secret)。
But we alos need:
On the backend,in the first I think about JavaScript
和Python
,Raspberry Pi is good with Python,use Javascript will be more easy。Also Raspberry Pi with Nodejs is easy,but let's use Python.
Compare some Python Framework,I choice flask
。
On the Frontend,before this I would like to use jQuery
+ BackBone
+ Mustache
to build a mobile website (ps: see Github https://github.com/phodal/moqi.mobi),it will cost a lot of data。And then, I create a framework——Lettuce,feel a bit too far。But,it's enough,as a ~6kb framework,include:
(small ads: If you are Interesting join https://github.com/phodal/lettuce)
Also we need to use PySerial.
Finally, we use Flask
+ Lettuce
+ PySerial
。
Process:
What you really need is a serious concern this part.
It's simple, so we list all code in here:
import json
import time
from flask import Flask, request
from flask_restful import Resource, Api
import serial
ser = serial.Serial("/dev/ttyACM0", 9600)
app = Flask(__name__, static_url_path='')
app.secret_key = 'why would I tell you my secret key?'
api = Api(app)
tasks = {}
@app.route('/')
def root():
return app.send_static_file('index.html')
class Task(Resource):
@staticmethod
def post(task_id):
tasks[task_id] = request.data
ser.write(request.data)
time.sleep(6)
return tasks[task_id], 201, {'Access-Control-Allow-Origin': '*'}
api.add_resource(Task, '/<string:task_id>')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
something different will be this:
ser = serial.Serial("/dev/ttyACM0", 9600)
In different platforms,/dev/ttyACM0
is different
Code is also simple:
#include <IRremote.h>
int starPort = 12;
IRsend irsend;
int fullStar = 1;
int irRemote = 2;
void setup() {
Serial.begin(9600);
pinMode(starPort, OUTPUT);
}
int serialData;
void loop() {
String inString = "";
while (Serial.available()> 0)
{
int inChar = Serial.read();
if (isDigit(inChar)) {
inString += (char)inChar;
}
serialData=inString.toInt();
Serial.print(serialData);
}
if(serialData == fullStar){
digitalWrite(starPort, HIGH);
} else
if( serialData == irRemote){
irsend.sendNEC(0xFF906F,32);
delay(1000);
}
}
If recv 1, will be show star. If recv 2, will be do other things.
See the all code in: https://github.com/phodal/valentine/blob/master/static/js/app.js
A sample example page:
var L = new lettuce();
var data = {
rise: "一起看日出",
down: "一起看日落",
yours: "有一天,你出现了",
together: "然后",
rose: "IOU"
};
var rise = function () {
var html = '<div class="rise"><h3>{%=o.rise%}</h3></div>';
var result = L.Template.tmpl(html, data);
document.getElementById("results").innerHTML = result;
};
rise();
a post request:
var L = new lettuce(),
irRemote = "2",
fullStar = "1";
lettuce.post("/serial", fullStar);
a event:
L.Event.on("showLove", showLove);
L.Event.trigger("showLove");
Promise with SetTimeout come true jump:
function show(func, n){
var p = new L.Promise();
var code = function () {
if (func !== undefined) {
func();
L.FX.fadeIn(document.getElementById('results'), {
duration: 3000, complete: function () {
}
});
}
p.done(null, n);
};
setTimeout(code, n);
return p;
}
show(undefined, 3000).then(
function() {
return show(rise, 0)
}
).then(
function() {
return show(down, 3000)
}
)
look like this:
Web Page Demo: http://valentine.phodal.com/
Github: https://github.com/phodal/valentine
Video:http://www.tudou.com/programs/view/ymr5BpHkHYc/
Issue: https://github.com/phodal/valentine/issues
Weibo: http://www.weibo.com/phodal/
(end)
围观我的Github Idea墙, 也许,你会遇到心仪的项目