I've been trying to understand how to setup systems from
the ground up on Ubuntu. I just installed redis
onto
the box and here's how I did it and some things to look
out for.
To install:
sudo kill $(sudo lsof -t -i:9001) | |
sudo kill `sudo lsof -t -i:9001` |
var i64 = require('img-to-64'); | |
i64.getImageStrings({ | |
files: ['./1.jpg'], | |
css: true | |
}, function(err, b64strings) { | |
if (err) { | |
console.log(err); | |
return; | |
} |
<script> | |
function h(e) { | |
$(e).css({'height':'auto','overflow-y':'hidden'}).height(e.scrollHeight); | |
} | |
$('textarea').each(function () { | |
h(this); | |
}).on('input', function () { | |
h(this); | |
}); |
One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.
Most workflows make the following compromises:
Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure
flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.
Use production SSL certificates locally. This is annoying
http://stackoverflow.com/questions/13133071/express-next-function-what-is-it-really-for | |
So what does next do? Simple, it tells your app to run the next middleware. But what happens when you pass something to next? Express will abort the current stack and will run all the middleware that has 4 parameters. | |
function (err, req, res, next) {} | |
This middleware is used to process any errors. I like to do the following: | |
next({ type: 'database', error: 'datacenter blew up' }); |
1. GET with json/xml | |
curl -i -H 'Accept: application/xml' http://tobi:ferret@127.0.0.1:3000/api/entries | |
2. POST with form | |
curl --data-urlencode "entry[title]=Hello Fucking World" --data-urlencode "entry[body]=This Is Awesome" http://baotrungtn:123123@localhost:9000/api/entry |
Only a piece of cookie (as a string of char) is stored on client. | |
Everything else will be stored on Server. | |
Therefore, every time a client send its cookie (passport) to server, server will retrieve | |
corresponding data (session). | |
This data can be stored on RAM or pesisted (Redis). | |
Ex: | |
req.session.uid |
tinnhiem.vn |
private class OpenWeather extends Thread { | |
private String cityID = ""; | |
public OpenWeather(String cityID) { | |
this.cityID = cityID; | |
} | |
public void run() { | |
// create HttpClient |