Skip to content

Instantly share code, notes, and snippets.

@jsaak
jsaak / websockify.c
Created October 18, 2016 10:35
buggy implementation of websocket to tcp gateway, do not use it unless you correct the errors
#include <uv.h>
#include "libwebsockets.h"
struct lws_context *context;
uv_loop_t loop;
static int callback_gateway(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
static int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
#define MAX_BUFFER_COUNT 16
@jsaak
jsaak / sdl2_net_udp_echo_server.c
Last active March 4, 2022 16:37
SDL2_net example udp echo server
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include "SDL_net.h"
main(int argc, char *argv[]) {
IPaddress serverIP;
UDPsocket udpsock;
@jsaak
jsaak / .fonts.conf
Created April 1, 2016 20:04
.fonts.conf for rendering windows fonts with no antialias, and all the rest with antialias under linux
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="font">
<edit mode="assign" name="rgba">
<const>none</const>
</edit>
</match>
<match target="font">
<edit mode="assign" name="hinting">
@jsaak
jsaak / kennylizer-nph-irc.cgi
Created February 1, 2016 09:07
cgi-irc kennylizer
cgi-irc kennylizer
This code converts sentences: the output is like that: "*ll* *ulm* *mmmmmlu* *lmu* *lu* *mmffmm*"
it is unfinished, but usable
How to install: modify nph-irc.cgi (located at /usr/lib/cgi-bin/cgiirc/ on debian systems)
To turn it on: create a file named "kenny" at /etc/cgiirc/ (echo flmufml>/etc/cgiirc/kenny)
To turn it off: remove the file (rm /etc/cgiirc/kenny)
@jsaak
jsaak / recursive_rename_files.rb
Created January 3, 2014 14:53
recursive rename (convert) files in a directory
#!/usr/bin/env ruby
require 'optparse'
def parse_command_line
options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options] encoding path\n" +
"Encoding like UTF8-MAC or ISO-8859-2"
@jsaak
jsaak / monkey-log4r.rb
Created December 5, 2013 13:04
monkey-patch log4r to support colorized log levels in PatternFormatter
require 'log4r'
original_verbosity = $VERBOSE
$VERBOSE = nil
module Log4r
class PatternFormatter
DirectiveTable = {
"c" => 'event.name',
"C" => 'event.fullname',
"d" => 'format_date',
@jsaak
jsaak / modify_timer.rb
Created December 3, 2013 11:49
modify periodic timer frequency at runtime (works with EventMachine and EventMachine::Synchrony too)
require "em-synchrony"
EventMachine.synchrony do
counter = 0
timer = EM::Synchrony.add_periodic_timer(0.2) do
puts counter
counter += 1
if counter > 4
timer.interval = 1
end
@jsaak
jsaak / synchrony_multitask.rb
Created November 26, 2013 08:50
cooperative multitasking using Eventmachine Synchrony and Fibers
require "em-synchrony"
EventMachine.synchrony do
Fiber.new do
while true
EM::Synchrony.sleep(0.5)
puts 'here'
end
end.resume