Skip to content

Instantly share code, notes, and snippets.

View ybogdanov's full-sized avatar

Yuriy Bogdanov ybogdanov

View GitHub Profile
@ybogdanov
ybogdanov / olx-previews.user.js
Created June 2, 2015 12:31
Makes OLX (slando) render large image previews
// ==UserScript==
// @name OLX Previews
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description Makes OLX (slando) render large image previews
// @match http://kiev.ko.olx.ua/nedvizhimost*
// @copyright 2015+, Yuriy Bogdanov
// ==/UserScript==
;(function(){
@ybogdanov
ybogdanov / Dockerfile
Last active September 7, 2015 16:59
Example Rockerfile with multiple FROM instructions, see https://github.com/grammarly/rocker
# Build stage: will start from google/golang:1.4 and compile app.go
FROM google/golang:1.4
ADD . /src
WORKDIR /src
# Will result in putting app.o to the working directory /src
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -v -o app.o app.go
# Will make app.o available in the following FROM
EXPORT app.o
# Describe "run" image based on "busybox", weights 4.3MB
@ybogdanov
ybogdanov / nginx.yml
Last active September 11, 2015 10:02
An example of decoupled nginx deployment with the use of rocker-compose. See http://tech.grammarly.com/blog/posts/How-We-Deploy-Containers-at-Grammarly.html
namespace: nginx
containers:
# "shared" is the data volume container that holds nginx config files and static html files for
# the "nginx" container. It is empty from the beginning, but once "configs" container is started
# files are copied to the "shared" container with rsync(1)
#
# This container is designed to be persistent across deploys of both "nginx" and "configs"
# containers.
#
@ybogdanov
ybogdanov / fibers.js
Created March 24, 2011 09:28
fibers integration
/**
* Some existing external lib which you don't want to touch
*/
var SomeModule = {
someAsyncFunction : function(callback)
{
process.nextTick(function(){
callback(null, 'result');
})
@ybogdanov
ybogdanov / seq_vs_sync.js
Created March 25, 2011 10:04
Seq library example VS Sync example
/**
* Seq
*/
var fs = require('fs');
var exec = require('child_process').exec;
var Seq = require('seq');
Seq()
.seq(function () {
exec('whoami', this)
@ybogdanov
ybogdanov / sync_integration.js
Created March 25, 2011 10:21
Example that shows how you can easily integrate node-sync to your app without refactoring
someObject = {
myNewMethod : function(a, b) // <-- no callback
{
console.log(Fiber.current); // Inside of fiber
if (a == 1)
throw "'a' cannot be 1"; // we can use throw here
@ybogdanov
ybogdanov / gist:1010061
Created June 6, 2011 10:44
Using ES6 coroutines for synchronous yielding of asynchronous stuff
function someAsyncFunction(param, callback) {
setTimeout(function(){
callback(null, param); // result
}, 100)
}
Function.prototype.sync = function(param) {
this(param, function(e, result) {
Fiber.run(result); // substitute result instead of yield, resume current Fiber
@ybogdanov
ybogdanov / rimraf-sync.js
Created August 9, 2011 21:51
Rimraf implementation using node-sync (node-fibers abstraction lib)
var path = require('path')
, fs = require('fs')
, Sync = require('sync')
// Return a future which just pauses for a certain amount of time
function realish (p) {
return path.resolve(path.dirname(fs.readlink.sync(fs, p)))
}
@ybogdanov
ybogdanov / getUserSummary_nodejs_async.js
Created August 20, 2011 13:19
nodejs callbackDriven vs node-async vs node-sync
function getUserSummary(userId, callback)
{
async.parallel({
user : function(callback) {
db.users.findUserById(userId, callback)
},
tweets : function(callback) {
db.users.getTweets(userId, callback)
@ybogdanov
ybogdanov / createEdge-async-example.js
Created August 21, 2011 22:51
examples of code which uses node-async vs node-sync with more complex logic
createEdge : function(e, callback)
{
var self = this, tryNum = 0,
isolateRetryAttempts = 20,
isolateRetryInterval = 1000;
callback = callback || function(){};
if (!(e instanceof Edge) || !e.isValid()) {
return callback(new Error("Invalid edge passed"));