Skip to content

Instantly share code, notes, and snippets.

View waj's full-sized avatar

Juan Wajnerman waj

  • NoRedInk
  • Buenos Aires, Argentina
View GitHub Profile
@waj
waj / init.lua
Created April 25, 2021 02:54
Hammerspoon directional focus
function directionalFocus(selector)
local current = hs.window.focusedWindow()
local currentFrame = current:frame()
local others = hs.window.orderedWindows()
for i, win in pairs(others) do
local otherFrame = win:frame()
local intersect = otherFrame:intersect(currentFrame)
if intersect.area == 0 and selector(currentFrame, otherFrame, intersect) then
win:focus()
break
@waj
waj / io_logger.cr
Created June 4, 2020 14:56
IO wrapper to log all data passing through to a file
class IOLogger < IO
@@log_index = 0
def initialize(@io : IO)
@@log_index += 1
@log = File.new("log#{@@log_index}.txt", "w")
@mode = :waiting
end
def read(slice : Bytes)
@waj
waj / docker-compose.yml
Last active March 14, 2019 20:49
Launch Rancher server with Docker Compose
version: '2'
volumes:
cattle:
mysql-log:
nginx-certs:
nginx-dhparam:
nginx-vhost:
nginx-html:
services:
@waj
waj / concurrency-in-go.md
Last active September 17, 2015 14:53 — forked from kachayev/concurrency-in-go.md
Channels Are Not Enough or Why Pipelining Is Not That Easy

Keybase proof

I hereby claim:

  • I am waj on github.
  • I am waj (https://keybase.io/waj) on keybase.
  • I have a public key whose fingerprint is 3283 EE30 8BF1 946D B1E8 8491 4267 1ACE EF2C AA86

To claim this, I am signing this object:

@waj
waj / ecr-macros.cr
Created December 18, 2014 21:47
Crystal Layouts with ECR
macro embed_ecr(filename, io_name)
\{{ run("ecr/process", {{filename}}, {{io_name}}) }}
end
macro ecr_file(filename)
def to_s(__io__, section = nil)
embed_ecr {{filename}}, "__io__"
end
def to_s(__io__, &block)
@waj
waj / taillogs.sh
Created August 13, 2014 16:45
Tail logs in MySQL table
#!/bin/sh
MYSQL="mysql -u root nuntium -s -N -e"
LASTID=`$MYSQL 'SELECT max(id) from logs'`
while true; do
$MYSQL "SELECT * FROM logs WHERE id > $LASTID"
LASTID=`$MYSQL 'SELECT max(id) from logs'`
sleep 1
done
@waj
waj / readlogs.cr
Last active August 29, 2015 14:05
Parse rails logs and output json ready for logstash
require "json"
class Request
property timestamp
property method
property path
property ip
property pid
property controller
property action
@waj
waj / chef.cr
Created July 29, 2014 22:05
SSL Server
require "net/ssl"
require "net/http"
server = HTTP::Server.new(8443) do |request|
# request.to_io(STDOUT)
# puts
HTTP::Response.not_found
end
server.ssl = SSLContext.new.tap do |ssl_ctx|
@waj
waj / pcl_and_gc.c
Created January 28, 2014 20:28
Segfault using GC and PCL
#include <gc/gc.h>
#include <pcl.h>
#include <stdio.h>
void coroutine(void *arg)
{
int i;
for (i = 0; i < 1000; ++i)
{
printf("%d\n", i);