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
@petersirka
petersirka / assign.js
Last active Aug 29, 2015
Assign value by path.
View assign.js
function assign(obj, path, fn) {
if (obj === null || typeof(obj) === 'undefined')
return obj;
var arr = path.split('.');
var model = obj[arr[0]];
for (var i = 1; i < arr.length - 1; i++)
model = model[arr[i]];
View onename
Verifying that +petersirka is my blockchain ID. https://onename.com/petersirka
View sqlagent-insert-identity.js
function doWorker(arr, callback) {
var responses = {};
arr.wait(function(name, next) {
var worker = F.worker(name, name);
worker.on('message', function(obj) {
// Save the message
responses[name] = obj;
// We have a result, continue ...
@petersirka
petersirka / total.js
Last active Mar 30, 2016
A full total.js application
View total.js
var app = 'https://totaljs.com/packages/example.package';
require('http').get('http://modules.totaljs.com/beta/total.js', function(res) {
var buf = [];
res.on('data', (b) => buf.push(b.toString('utf8')));
res.on('end', () => { eval(buf.join('')); F.on('ready', () => INSTALL('package', app)).http('debug'); });
});
View update.js
COMPONENT('comments', function() {
var self = this;
self.readonly();
self.rebuild = function() {
AJAX('GET .....', function(response, err) {
if (err)
return;
@petersirka
petersirka / generators.js
Created May 29, 2016
Total.js Generators and Promisies
View generators.js
const Fs = require('fs');
require('total.js');
async(function*() {
var a = yield readFile('run.sh');
var b = yield readFile('run.sh');
var c = yield readFile('run.sh');
// var a = yield sync(Fs.readFile)('run.sh');
// var b = yield sync(Fs.readFile)('run.sh');
// var c = yield sync(Fs.readFile)('run.sh');
View middleware.js
exports.install = function() {
F.route('/', view_a, ['#A']);
F.route('/*', view_b, ['#B']);
}
F.middleware('A', function(req, res, next, options, controller) {
console.log('A');
next();
});
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);
}));
});
@petersirka
petersirka / singlelibrary.js
Last active Jul 3, 2016
How to run Total.js without installation?
View singlelibrary.js
function main() {
F.route('/', function() {
this.plain('HOMEPAGE');
});
// debug (development mode), release (production mode), test (testing mode)
F.http('debug');
}
View jcomponent.js
COMPONENT('mycomponent', function() {
var self = this;
self.setter = function(value) {
if (value == null)
value = '';
self.html(value);
};
});
You can’t perform that action at this time.