This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var http = require('http'); | |
| var create = false; | |
| http.createServer(function (req, res) { | |
| res.writeHead(200, {'Content-Type': 'application/json'}); | |
| if (req.url === '/rpc/Cloud/Host/List') { | |
| res.end(JSON.stringify({ Items: [ { StateType: 5 } ] })); | |
| } else if (req.url === '/rpc/Cloud/Injections/CreateRequestWith') { | |
| if (create) { | |
| res.end(JSON.stringify({ Err: 'Request again!' })); | |
| process.exit(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var util = require('util'); | |
| var Transform = require('stream').Transform; | |
| util.inherits(StreamProgress, Transform); | |
| function StreamProgress(options) { | |
| if (!(this instanceof StreamProgress)) | |
| return new StreamProgress(options); | |
| Transform.call(this, options); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // taken from https://github.com/Chatham/node-cloudstack | |
| // adapted by LI, Yu | |
| var http = require('http'); | |
| var crypto = require('crypto'); | |
| var url = require('url'); | |
| module.exports = function cloudstack(options) { | |
| if (!options) { options = {}; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| THISDIR=`pwd` | |
| CMD=$1 | |
| CONFNAME=$2 | |
| function usage { | |
| echo "usage: sudo $0 start/status/stop <conf_name>" | |
| } | |
| function openvpn_start { | |
| #echo "openvpn --daemon --writepid /var/run/openvpn/${CONFNAME}.pid --cd ${THISDIR}/${CONFNAME} --config ${CONFNAME}.ovpn" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #setup XIM environment | |
| export GTK_IM_MODULE=fcitx | |
| export QT_IM_MODULE=fcitx | |
| export XMODIFIERS=@im=fcitx | |
| if [ -z `pidof fcitx` ]; then | |
| fcitx | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| find dir -type f -print0 | xargs -0 md5sum | sort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # learned from http://bneijt.nl/blog/post/show-progress-of-dd-command/ | |
| # open another terminal tab and, | |
| sudo watch -n 30 'pkill -USR1 -n -x dd' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Challenge 2: Hill | |
| Given an array of integer elements | |
| Your task is to | |
| * write a function that finds the minimum value X that makes possible the following: generate a new array that is sorted in strictly ascending order by increasing or decreasing each of the elements of the initial array with integer values in the [0, X] range. | |
| Example: Having the initial array [5, 4, 3, 2, 8] the minimum value for X is 3. Decrease the first element (5) by 3, decrease the second one (4) by 1, increase the third one (3) by 1, increase the forth one (2) by 3 and do nothing to the last one (8). In the end we obtain the array [2, 3, 4, 5, 8] which is sorted in strictly ascending order. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;(function ($, window) { | |
| var intervals = {}; | |
| var removeListener = function(selector) { | |
| if (intervals[selector]) { | |
| window.clearInterval(intervals[selector]); | |
| intervals[selector] = null; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function runCmd(cmd, args, callback) { | |
| var spawn = require('child_process').spawn; | |
| var child = spawn(cmd, args); | |
| var out = ''; | |
| var err = ''; | |
| child.stdout.on('data', function(buffer) { out += buffer.toString(); }); | |
| child.stderr.on('data', function(buffer) { err += buffer.toString(); }); | |
| child.on('close', function(code) { callback(code, out, err); }); | |
| } |