Skip to content

Instantly share code, notes, and snippets.

View skaurus's full-sized avatar

Dmitry Shalashov skaurus

View GitHub Profile
--- lib/http1.js 2010-07-06 07:54:46.000000000 +0000
+++ lib/http.js 2010-07-06 07:53:55.000000000 +0000
@@ -37,7 +37,7 @@
parser.onHeaderField = function (b, start, len) {
var slice = b.toString('ascii', start, start+len).toLowerCase();
- if (parser.value) {
+ if (parser.value != undefined) {
parser.incoming._addHeaderLine(parser.field, parser.value);
parser.field = null;
--- ws.js 2010-07-06 07:23:24.000000000 +0000
+++ ws_my.js 2010-07-07 09:33:39.000000000 +0000
@@ -12,16 +12,26 @@
});
}
-var sys = require("sys"),
- net = require("net"),
- headerExpressions = [
- /^GET (\/[^\s]*) HTTP\/1\.1$/,
--- new3.js 2010-07-07 10:07:46.000000000 +0000
+++ ws_my.js 2010-07-07 10:08:53.000000000 +0000
@@ -52,7 +52,10 @@
policy_file = '<cross-domain-policy><allow-access-from domain="*" to-ports="*" /></cross-domain-policy>';
-exports.createServer = function (websocketListener) {
+exports.createServer = function (websocketListener, options) {
+ if (!options) options = {};
+ if (!options.flashpolicy) options.flashpolicy = policy_file;
#!/bin/sh
#
# chkconfig: 345 85 15
# description: Mojolicious app init.d script
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
@skaurus
skaurus / gist:635395
Created October 19, 2010 23:25
buggy mojo init.d
#!/bin/bash
#
# around Startup script for the around web application
#
# chkconfig: 35 85 15
# description: around
# pidfile: /var/run/around.pid
# Source function library.
. /etc/rc.d/init.d/functions
@skaurus
skaurus / anyevent-proxy.pl
Created September 8, 2011 09:30
AnyEvent HTTP Proxy
#!/usr/bin/perl
# This is HTTP proxy built atop AnyEvent::HTTPD and AnyEvent::HTTP modules.
# I used it to solve some problem but after testing realised that it doesn't solve it entirely.
# So I removed special logic and leave almost plain proxy. With referer forging however :)
#
# Test thoroughly before use!
use strict;
use warnings;
@skaurus
skaurus / gist:1290970
Created October 16, 2011 14:50
Mojo/EV bug part 1
Run server as:
./mojo_ev_test.pl daemon --listen http://localhost:4242 --clients 1
Send requests as:
perl -Mstrict -MAnyEvent::HTTP -MData::Dumper -e 'my $cv = AnyEvent->condvar; http_post("http://localhost:4242/hitme", "", timeout => 10, persistent => 0, sub { my ($b, $h) = @_; warn Dumper $h; $cv->send() }); $cv->recv;'
First request dumps headers fine, consequent requests timeouts.
@skaurus
skaurus / mojo_ev_test.pl
Created October 16, 2011 14:52
Mojo/EV bug part 2
#!/usr/local/bin/perl
use 5.012;
BEGIN { $ENV{MOJO_POLL} = 0; };
use Mojolicious::Lite;
use AnyEvent::HTTP;
# From a fresh install of squeeze
aptitude install ruby rubygems # Need ruby to use fpm
gem1.8 install fpm --no-ri --no-rdoc
aptitude install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev ncurses-dev libyaml-dev
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p385.tar.gz
tar -zxvf ruby-1.9.3-p385.tar.gz
cd ruby-1.9.3-p385
rm -rf /tmp/ruby193
@skaurus
skaurus / hls-fetch-all.pl
Last active April 6, 2016 14:33
Simple perl one-liner to fetch entire HLS stream given master playlist URL
# all files will be fetched to current directory.
# dependencies - curl somewhere in $PATH and URI perl library.
perl -e 'use URI; my $m3u_url = shift or die "provide hls playlist url"; sub get { my $path = shift; my $rel = URI->new($path)->rel($m3u_url); `curl $path --progress-bar --create-dirs -o $rel` // die "getting $path failed!"; return $rel }; sub parse_pls { my ($file, $abs) = @_; open(my $fh, $file); return map { chomp; URI->new_abs($_, $abs) } grep { $_ !~ /^#/ } <$fh> }; my $file = get $m3u_url; my @urls = parse_pls($file, $m3u_url); my %loop; while (my $url = shift @urls) { die "loop detected!" if $loop{$url}++; my $file = get $url; push @urls, parse_pls($file, $url) if ($file =~ /\.m3u8$/) }' 'http://www.streambox.fr/playlists/x36xhzz/x36xhzz.m3u8'