Skip to content

Instantly share code, notes, and snippets.

View riston's full-sized avatar
🇪🇪

Risto Novik riston

🇪🇪
View GitHub Profile
@riston
riston / app.js
Created September 6, 2015 15:38
Reactive RXJS drawing example
var canvas = document.getElementById("container");
var ctx = canvas.getContext("2d");
// The line settings
ctx.lineWidth = 4;
ctx.lineJoin = ctx.lineCap = "round";
var intervalSource = Rx.Observable.interval(2 * 1000, Rx.Scheduler.requestAnimationFrame);
var pauser = new Rx.Subject();
@riston
riston / convert.go
Created July 25, 2015 09:02
Convert map[string]interface{}
var profile OAuthProfile
MapToStruct(result, &profile)
fmt.Println("Extracted", profile)
func MapToStruct(m map[string]interface{}, val interface{}) error {
tmp, err := json.Marshal(m)
@riston
riston / example.go
Created July 6, 2015 21:12
Go concurrency example
s := func(name string) string {
time.Sleep(4 * time.Second)
fmt.Println("Do something", name)
return "Done"
}
results := []string{}
c := make(chan string)
go func() { c <- s("first") }()
@riston
riston / all.js
Created June 19, 2015 12:58
Promise and handling all
var getProviderInfo = function (provider)
{
return new Promise(function (resolve, reject) {
var time = ~~(Math.random() * 2000) + 2000;
// Make request and get the data, simulate request api, no fail in our case
window.setTimeout(function () {
@riston
riston / promise.js
Created May 21, 2015 14:32
Promise example
var p1 = new Promise(function (resolve) {
return resolve(10);
});
var add = function (num) {
return new Promise(function (resolve) {
@riston
riston / gist:9d2fafe3c9869d9ae79d
Last active August 29, 2015 14:18
Transforming object into array
var requests = { docs: [ 'hello' ], boards: [ 'R404' ] };
var fetchResultTransform = function (requests)
{
var resource = [];
Object.keys(requests).forEach(function (colName)
{
requests[colName].forEach(function (docName)
{
@riston
riston / sqs.js
Created March 5, 2015 19:16
SQS recursive polling
var aws = require('aws-sdk');
var util = require('util');
var SQS = new aws.SQS({
accessKeyId: 'xxxx',
secretAccessKey: 'xxx',
region: 'xxx',
sslEnabled: false,
paramValidation: true,
convertResponseTypes: true,
@riston
riston / db-service.js
Created February 19, 2015 17:10
Database service module for Node.js
var config = require("config");
var pg = require("pg");
var PromiseB = require("bluebird");
PromiseB.promisifyAll(pg);
// To prevent data loss handle bigint as string
// https://github.com/brianc/node-postgres/pull/353
pg.defaults.parseInt8 = false;
@riston
riston / sublime-user.json
Created January 22, 2015 07:34
Sublime conf
{
"auto_indent": true,
"bold_folder_labels": false,
"caret_style": "wide",
"color_scheme": "Packages/User/Monokai (SL).tmTheme",
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
"*.pyc",
"*.pyo",
@riston
riston / color.js
Created January 2, 2015 22:27
Colorful developing :D
// Paste in browser developer tools
Array(100).join('.').split('.').map(function (a, index) { return (~~(Math.random()*(1<<24))).toString(16) }).forEach(function(color) { console.log("%c ", "background-color: #" + color) });