Skip to content

Instantly share code, notes, and snippets.

any '/fast-ping' => sub {
my $self = shift;
my $request = $self->req->json || return $self->render_json( { 'status' => 'Request error' } );
my $remote_addr = $self->tx->remote_address;
app->log->info("$remote_addr requested ".Dumper($request));
my $prefix = $request->{'prefix'};
return $self->render_json( { 'status' => 'Have no network prefix in request, nothing to do!' } ) unless $prefix;
@dynax60
dynax60 / arping.pl
Created August 9, 2010 09:04
Non-blocked arping sample using POE
#!/usr/bin/perl
use strict;
use warnings;
use POE qw(Wheel::Run Filter::Reference);
sub MAX_CONCURRENT_TASKS () { 25 }
use Net::Netmask;
use Data::Dumper;
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::ByteStream 'b';
use Mojo::JSON;
use utf8;
...
our $dbh = DBI->connect("dbi:mysql:dbname=cli;host=localhost",
@dynax60
dynax60 / gist:544979
Created August 23, 2010 07:12
Decode bytestream on $dbh->selectall_arrayref result
use Mojo::ByteStream 'b';
...
$rows = $dbh->selectall_arrayref(q{ .. });
# Decode bytestream to string for each item in arrays
grep { grep { $_ = b($_)->decode('UTF-8') } @$_ } grep { $_ } @$rows ;
@dynax60
dynax60 / gist:547379
Created August 24, 2010 11:13
Mysql client charset
#!/usr/bin/perl
use DBI;
our $dbh = DBI->connect("dbi:mysql:dbname=mydb;host=localhost",
'user', 'pass',
{ PrintError => 0, RaiseError => 1, mysql_enable_utf8 => 1 });
for (@{ $dbh->selectall_arrayref(q{
SHOW VARIABLES LIKE 'character\_set\_%' }) } ) {
diff -dur gateway.orig/gw/bb_boxc.c gateway/gw/bb_boxc.c
--- gateway.orig/gw/bb_boxc.c 2015-07-15 12:01:59.993723709 +0000
+++ gateway/gw/bb_boxc.c 2015-07-23 11:38:23.449299990 +0000
@@ -111,6 +111,7 @@
static Dict *smsbox_by_smsc;
static Dict *smsbox_by_receiver;
static Dict *smsbox_by_smsc_receiver;
+static Dict *smsbox_by_sender;
static long smsbox_port;
@dynax60
dynax60 / gist:560251
Created September 1, 2010 05:06
Linux startup script for Mojo daemon_prefork app
#!/bin/bash
#
# Init file for Pinger server daemon
#
# chkconfig: 2345 55 25
# description: Pinger server daemon
#
# processname: pinger
# pidfile: /var/run/pinger.pid
@dynax60
dynax60 / jsonp-service.pl
Created September 3, 2010 08:01
An example of JSONP service (cross-domain) on Mojolicious..
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/mojo/lib";
use Mojolicious::Lite;
@dynax60
dynax60 / jsonp.html
Created September 3, 2010 08:10
An example of JSONP usage (cross-domain) with JQuery.
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<SCRIPT>
$(function() {
$('#clickme').click(function() {
$.getJSON('http://domain.tld/test/?foo=bar&callback=?',
@dynax60
dynax60 / gist:640480
Created October 22, 2010 12:43
Паковка и распаковка IP-адреса
$ perl -MSocket -le 'print unpack("N", inet_aton(shift))' 127.0.0.1
2130706433
$ perl -MSocket -le 'print inet_ntoa(pack("N", shift))' 2130706433
127.0.0.1