Skip to content

Instantly share code, notes, and snippets.

Avatar
🏚️
Work From Home

Thiên Toán toanalien

🏚️
Work From Home
View GitHub Profile
View 1433401511.cpp
#include <iostream>
#include <string>
using namespace std;
class Ve
{
protected:
string MaVe, HoTen;
int NamSinh, SoTroChoi;
@toanalien
toanalien / 1433385849.cpp
Last active Aug 29, 2015
constructor & deconstrutor
View 1433385849.cpp
#include <iostream>
using namespace std;
class PhanSo
{
private:
int ts, ms;
public:
PhanSo (int ts = 0, int ms = 1);
PhanSo operator +(PhanSo);
@toanalien
toanalien / 1433429254.js
Created Jun 4, 2015
Manipulating file paths
View 1433429254.js
/**
* 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 / 1433440766.js
Last active Aug 29, 2015
Creating and controlling external processes
View 1433440766.js
/**
* 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 / 1433417188.js
Last active Aug 29, 2015
Emitting Events
View 1433417188.js
var util = require('util'),
EventEmitter = require('events').EventEmitter;
var Ticker = function(){
var self = this;
setInterval(function(){
self.emit('tick');
},1000);
};
util.inherits(Ticker,EventEmitter);
View 1433437872.js
/**
* 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 / 1433419040.js
Last active Aug 29, 2015
Scheduling the Execution of Functions Using Timers
View 1433419040.js
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 / 1433442827.js
Last active Aug 29, 2015
Spawning child processes
View 1433442827.js
/**
* 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 Jun 4, 2015
Took phrases from the dictionary file
View 1433442827.cpp
/**
* 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];
View 1433442827.cpp
/**
* 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