Skip to content

Instantly share code, notes, and snippets.

View batizhevsky's full-sized avatar

Leonid Batizhevskii batizhevsky

View GitHub Profile
Co-routines are severely under-utilized in Ruby.
There's a truly magical line you can add to the top of a function that yields a bunch of values,
`return to_enum(__callee__) unless block_given?`
which makes the function return an Enumerator enumerating its values if you don't explicitly pass it a block.
As a simple example, consider this,
```ruby
def numbers
return to_enum(__callee__) unless block_given?
yield 1
yield 2
@batizhevsky
batizhevsky / osx_file_limits
Created January 9, 2014 19:20
os x limits
$ sysctl kern.maxfiles
kern.maxfiles: 12288
$ sysctl kern.maxfilesperproc
kern.maxfilesperproc: 10240
$ sudo sysctl -w kern.maxfiles=1048600
kern.maxfiles: 12288 -> 1048600
$ sudo sysctl -w kern.maxfilesperproc=1048576
kern.maxfilesperproc: 10240 -> 1048576
$ ulimit -S -n
256
@batizhevsky
batizhevsky / post.js
Created September 27, 2012 14:28
cross domain post with ajax
function crossDomainPost() {
// Add the iframe with a unique name
var iframe = document.createElement("iframe");
var uniqueString = "CHANGE_THIS_TO_SOME_UNIQUE_STRING";
document.body.appendChild(iframe);
iframe.style.display = "none";
iframe.contentWindow.name = uniqueString;
// construct a form with hidden inputs, targeting the iframe
var form = document.createElement("form");
@batizhevsky
batizhevsky / Gemfile
Created August 24, 2012 09:48
sinatra-test
gem "sinatra", :require => "sinatra/base"
gem "sinatra-contrib"
@batizhevsky
batizhevsky / glut-osx.c
Created May 2, 2012 17:37
Шаблон для приложения opengl+glut+osx
#include <stdlib.h>
#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#define kWindowWidth 640
#define kWindowHeight 480
unsigned int delay= 10;