Skip to content

Instantly share code, notes, and snippets.

View avalanche123's full-sized avatar

Bulat Shakirzyanov avalanche123

View GitHub Profile
@avalanche123
avalanche123 / action.sh
Created December 9, 2014 19:38
TextMate2 CopyWithStyle action
#!/bin/bash
source "$TM_SUPPORT_PATH/lib/bash_init.sh" # might not be necessary
read -r -d '' code <<-'EOF'
require "jcode" if RUBY_VERSION < '1.9'
app_path = ENV["TM_SUPPORT_PATH"]
require "#{app_path}/../../../TextMate.tmbundle/Support/lib/doctohtml.rb"
require "#{app_path}/lib/progress.rb"
unit = ENV.has_key?('TM_SELECTED_TEXT') ? 'selection' : 'document'
@avalanche123
avalanche123 / background.md
Last active May 16, 2018 15:56
uv_promise_t proposal

Introduction

I'm working on a C library that features a background io thread and I think that libuv is a great choice for this task. The io thread will be responsible for handling a pool of tcp connections. The library will be used to write higher-level language bindings and will expose both tradition and asynchronous apis.

I know that a proper way to communicate with a libuv event loop from a different thread is by using uv_async_t object. However, there is, as far as I can tell, no primitive for communication with some other thread(s) from the event loop thread. For this exact reason, I propose a new primitiv - uv_promise_t. And I've included description of its api in this gist.

The goal is to make building apis like Cassandra Java Driver on top of libuv a breeze.

@avalanche123
avalanche123 / crawler.go
Created November 21, 2012 19:53
A Tour of Go. Exercise: Web Crawler
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
@avalanche123
avalanche123 / timeout.php
Created July 10, 2012 19:12
timeouts in php
<?php
class TimeoutException extends RuntimeException {}
class Timeout
{
private $active;
public function set($seconds)
{
@avalanche123
avalanche123 / gist:2879188
Created June 6, 2012 00:55
Common Daemon Interface
# Common Daemon Interface is a emerging standard, its only purpose is to define portable daemon specifications understandable and interchangeable between
# various service and process managers. Primary targets are launchd, upstart and systemd and the ones known to be widely used and fairly similar.
# Feedback welcome.
# required settings
SERVICE_NAME="my_cool_service" # alphanumeric string, underscores and dots are allowed
DAEMON_INTERFACE="CDI/1.0" # daemon interface version
SERVICE_TYPE="daemon" # (task|daemon) wether process is a one-time job or background daemon
require 'ffi'
module UV
extend FFI::Library
FFI::DEBUG = 10
libc = ffi_lib(FFI::Library::LIBC).first
begin
# bias the library discovery to a path inside the gem first, then
# to the usual system paths
inside_gem = File.join(File.dirname(__FILE__), '..', 'ext')
@avalanche123
avalanche123 / greenlet.rb
Created March 9, 2012 05:34
Python's greenlets in Ruby using fibers, implementing example from greenlet documentation at http://greenlet.readthedocs.org/en/latest/index.html
class String
def start_with?(little_string)
!self.match(/^#{Regexp.escape(little_string)}/).nil?
end
def end_with?(little_string)
!self.match(/#{Regexp.escape(little_string)}$/).nil?
end
<?php
$image = $imagine->open('/path/to/image.jpg');
$image
->resize($image->getSize()->widen(200))
->save('/path/to/resized/image.jpg')
;
@avalanche123
avalanche123 / Makefile
Created October 18, 2011 23:39
new PHP project Makefile
# Makefile for php project setup
#
# You can set these variables from the command line.
AUTHOR = Author
PROJECT = Project
BUILDFILE = project.phar
SRCDIR = src
TESTDIR = tests
PHPUNITCONFIG = phpunit.xml.dist
@avalanche123
avalanche123 / ReflectionFilter.php
Created October 13, 2011 08:26
Reflection filter in Imagine
<?php
class ReflectionFilter implements Imagine\Filter\FilterInterface
{
private $imagine;
public function __construct(Imagine\Image\ImagineInterface $imagine)
{
$this->imagine = $imagine;
}