Skip to content

Instantly share code, notes, and snippets.

View gtomitsuka's full-sized avatar

Gabriel Tomitsuka gtomitsuka

View GitHub Profile
@gtomitsuka
gtomitsuka / main.js
Created July 21, 2015 16:52
toLower(str) - Alternative to String.prototype.toLowerCase(), written for a Quora answer.
function toLower(str){
var result = '';
for (var i = 0, len = str.length; i < len; i++) {
var charAtLocation = str.charCodeAt(i);
if(charAtLocation > 64 && charAtLocation < 91) //ASCII for upper-case
result += String.fromCharCode(charAtLocation + 32);
else
result += str[i];
}
return result;
@gtomitsuka
gtomitsuka / test.js
Last active August 29, 2015 14:24
Does this work, too?
function Me(){
this.start = function(){
console.log(this);
}
}
var me = new Me();
var s = me.start.bind(me);
@gtomitsuka
gtomitsuka / util.js
Last active August 29, 2015 14:24
Promisified node-postgres
var pg = require('pg');
var Promise = require('bluebird');
exports.connect = function(config){
return new Promise(function(resolve, reject){
pg.connect(config, function(error, connection, next){
if(error)
throw error;
connection.queryAsync = function(){
@gtomitsuka
gtomitsuka / parseBool.js
Last active August 29, 2015 14:20
parseBool - JS Boolean parsing utility
//by Gabriel Tomitsuka
function parseBool(str){
return str === 'true' || str !== '0'? true : false
}
@gtomitsuka
gtomitsuka / minimumScalarProduct.js
Last active August 29, 2015 14:19
Google Code Jam 2008 - Minimum Scalar Product - JavaScript
/* Copyright (c) 2015 by Gabriel Tomitsuka.
* Node.js code for GCJ's https://code.google.com/codejam/contest/32016/dashboard#s=p0
* Minimum Scalar Product
*/
var readline = require('readline');
var async = require('async');
var rl = readline.createInterface({
input: process.stdin,
@gtomitsuka
gtomitsuka / oratio.md
Last active August 29, 2015 14:16
Oratio - What is it?

Introduction

Oratio is a revolutionary, simple, lightning fast, customizable and intelligent forum hosting service. It can be extended for supporting chats, collaborative to-do lists, file and website hosting with the Montreus CDN, themes and modules(plugins). It is so customizable that you can disable the forum functions and use it only for a website with Node.js server-side scripts.

Why?

As of the moment this was written, there was no significant concurrency aside Vanilla Forums. Our system will include virtual points, a concept already applied to a few forums on the internet, such as StackExchange however not publicy available. Also, Vanilla is way too complicated for the average computer user wanting a forum.

Our System

Our system is based on Node.js and for this is lightning fast. It uses PostgreSQL for persistent storage, and has advantages of safe, relational storage and takes advant

@gtomitsuka
gtomitsuka / hash.js
Last active August 29, 2015 14:16
Node.js SHA-256 Hashing
// Please make sure you have the crypto module installed
//Modules
var crypto = require('crypto');
module.exports = function(value) {
return crypto.createHash('sha256').update(pwd).digest('base64');
};
@gtomitsuka
gtomitsuka / request.js
Created February 28, 2015 01:22
Request.js
//APIs
var http = require('http');
var url = require('url');
module.exports = function(websiteURL, method) {
return new Promise(function (resolve, decline){
var path = url.parse(websiteURL);
var options = {};
options.hostname = path.hostname;
options.port = path.port;
@gtomitsuka
gtomitsuka / ws.js
Last active August 29, 2015 14:15
WebSockets + Express.js Server
/* ws.js
* Simple WebSockets + Express.js code
*/
//APIs
var express = require("express"); //Express.js - Serve pages
var app = express();
var http = require("http").Server(app); //HTTP - Server listen
var ws = require("ws");