Skip to content

Instantly share code, notes, and snippets.

View toanalien's full-sized avatar
🎯
Focusing

Thiên Toán toanalien

🎯
Focusing
View GitHub Profile
@toanalien
toanalien / 1433385849.cpp
Last active August 29, 2015 14:22
constructor & deconstrutor
#include <iostream>
using namespace std;
class PhanSo
{
private:
int ts, ms;
public:
PhanSo (int ts = 0, int ms = 1);
PhanSo operator +(PhanSo);
@toanalien
toanalien / 1433401511.cpp
Created June 4, 2015 07:05
OOP 2rd Term test
#include <iostream>
#include <string>
using namespace std;
class Ve
{
protected:
string MaVe, HoTen;
int NamSinh, SoTroChoi;
@toanalien
toanalien / 1433417188.js
Last active August 29, 2015 14:22
Emitting Events
var util = require('util'),
EventEmitter = require('events').EventEmitter;
var Ticker = function(){
var self = this;
setInterval(function(){
self.emit('tick');
},1000);
};
util.inherits(Ticker,EventEmitter);
@toanalien
toanalien / 1433419040.js
Last active August 29, 2015 14:22
Scheduling the Execution of Functions Using Timers
var oneSecond = 1000 * 1; // one second = 1000 x 1 ms
// setTimeout
setTimeout(function() {
document.write('<p>Hello there.</p>');
}, oneSecond);
// setInterval
var setInteval(function(){
document.write('<p>Hello there.</p>');
@toanalien
toanalien / 1433429254.js
Created June 4, 2015 14:47
Manipulating file paths
/**
* Normalizing paths
* you can use the normalize function present in the path module to normalize path, string, thus taking care of .., ., and //.
*/
var path = require('path');
path.normalize('/foo/bar//baz/asdf/quux/..');
// => '/foo/bar/baz/asdf'
/**
@toanalien
toanalien / 1433437872.js
Created June 4, 2015 17:11
The fs module
/**
* Querying file statistics
* You can query some meta-infomation on a file (or directory) by using the fs.stat function
*/
var fs = require('fs');
fs.stat('/etc/paswwd', function(err, stats){
if (err) { throw err;}
console.log(stats);
});
@toanalien
toanalien / 1433440766.js
Last active August 29, 2015 14:22
Creating and controlling external processes
/**
* Executing external commands
*
* when you need to lauch an external shell command or an executable file, you may do so by using the child_process module.
* You can import module like this
*/
var child_process = require('child_process');
// you can the use the exec function that is defined in the module like thí
@toanalien
toanalien / 1433442827.js
Last active August 29, 2015 14:22
Spawning child processes
/**
* As you have seen, you can use the child_process.exec() function to launch external processes.
* You get your callback invoked when the process ends. This approach is very simple, but it has some drawbacks:
* > except for the command-line arguments and the environment variables, using exec() does not allow you to
* communicate with the child process.
* > the child process output is buffered. As a result, you cannot stream it, and it can consume memory.
*
* Fortunately, Node’s child_process module allows for finer-grained control when launching, stopping,
* and generally interacting with child processes.
* You may launch a new process, called the child process, from your application, which is called the parent process.
@toanalien
toanalien / 1433442827.cpp
Created June 4, 2015 18:50
Took phrases from the dictionary file
/**
* download dictionary file at http://blackberryvietnam.net/threads/du-lieu-tu-dien-cho-ung-dung-ddict.897/
*/
#include <stdio.h>
#include <string.h>
int main()
{
char s[300];
/**
* A part of contact.txt contents like
*
* Last name: nguyen van a
* General phone: 0123456789
*
* First name: nguyen thi b
* General phone: 09999999
*
* First name: tran van c