Skip to content

Instantly share code, notes, and snippets.

🤓
From zero to hero

Peter Širka petersirka

🤓
From zero to hero
Block or report user

Report or block petersirka

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View total-xmlparse.js
require('total.js');
U.download('http://www.w3schools.com/xml/plant_catalog.xml', ['get'], function(err, response) {
response.on('data', U.streamer('<PLANT>', '</PLANT>', function(item, counter) {
// item === a whole element {String}
var obj = item.parseXML();
console.log('--->', obj['PLANT.COMMON'], counter + 1);
}));
});
View jcomponent.js
COMPONENT('mycomponent', function() {
var self = this;
self.setter = function(value) {
if (value == null)
value = '';
self.html(value);
};
});
View miro.html
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.1.0/d3.min.js"></script>
@petersirka
petersirka / nginx.conf
Created Jul 15, 2016
Nginx configuration
View nginx.conf
worker_processes auto;
events {
use epoll;
worker_connections 1024;
multi_accept on;
}
http {
limit_req_zone $binary_remote_addr zone=ddos:10m rate=50r/s;
View cpu.js
const Exec = require('child_process').exec;
var cmd = 'ps aux | grep "mysql" | grep -v "grep" | awk {\'print $2\'}';
Exec(cmd, function(err, response) {
var pid = response.trim();
cmd = 'ps -p {0} -o %cpu,rss,etime'.format(pid);
console.log(cmd);
Exec(cmd, function(err, response) {
console.log('---> POSLAT SIROVI:', arguments);
});
@petersirka
petersirka / controller.js
Created Dec 12, 2016
Total.js: A workflow and controller with implementation of reCAPTCHA.
View controller.js
exports.install = function() {
F.route('/api/signup/', json_signup, ['*SignUp', 'post']);
};
function json_signup() {
var self = this;
self.$async(self.callback(), 1).$workflow('recaptcha').$save().$workflow('notify');
}
View VisualFlow.js
require('total.js').http('debug');
var util = require('util');
var EventEmitter = require('events');
// jen na test
var WSCONTROLLER = {
send: function(data){ console.log(data)}
}
@petersirka
petersirka / parser-transform.js
Created Mar 19, 2017
Parse transform SVG attribute
View parser-transform.js
String.prototype.parseTransform = function() {
var prop = ['translate', 'matrix', 'rotate', 'skewX', 'skewY', 'scale'];
var val = this.match(/(translate|matrix|rotate|skewX|skewY|scale)\(.*?\)/g);
var obj = {};
if (val) {
for (var i = 0, length = val.length; i < length; i++) {
var item = val[i];
var index = item.indexOf('(');
var v = item.substring(index + 1, item.length - 1).split(/\,|\s/);
var n = item.substring(0, index);
@petersirka
petersirka / azure-documentdb-totaljs.js
Last active May 4, 2018
A simple REST implementation of Azure DocumentDB with help of Total.js framework
View azure-documentdb-totaljs.js
const Crypto = require('crypto');
require('total.js');
function DocumentDB(hostname, key) {
this.hostname = hostname;
this.key = key;
this.attempts = 0;
this.expiration = '10 minutes';
}
@petersirka
petersirka / proxy.js
Created May 14, 2018
HTTP agent as a proxy tunel
View proxy.js
function request_proxy(options, callback) {
var proxy = options.proxy;
proxy.path = options.uri.hostname;
proxy.headers = { host: options.uri.hostname };
if (proxy.auth)
proxy.headers['Proxy-Authorization'] = 'Basic ' + U.createBuffer(proxy.auth).toString('base64');
var req = Https.request(proxy);
You can’t perform that action at this time.