Skip to content

Instantly share code, notes, and snippets.

@iarna
iarna / Console_ProgressBar
Created January 24, 2012 19:41
Console_ProgressBar displays a customizable progress bar in the console/terminal.
Console_ProgressBar
Console_ProgressBar displays a customizable progress bar in the console/terminal.
http://pear.php.net/manual/en/package.console.console-progressbar.php
Some progress bar examples
This will display a very simple bar:
=====================================================
if ($racks =~ /\D/) {
print "\n$racks isn't a positive integer at all!\n\n";
exit;
}
for (; $racks >= 2; $racks--) {
&length;
}
@iarna
iarna / gist:3975812
Created October 29, 2012 19:10
Modyllic Dialect Handling and Conversion

ModyllicSQL is our platonic ideal SQL schema, and a moving target as we integrate more interesting features from various databases. It begins life as a full-metadata dialect of MySQL with a few minor extensions already documented.

Dialect specific parsers, eg, when loading directly from a database, generate a dialect specific schema.

Prior to dumping, if the schema is not yet dialect specific, it will be mutated to be so.

<?
/**
* twitterfeed.php
*
* A single file script which serves an authenticated personal Twitter timeline as an Atom feed.
*
* To use:
* 1) Go to https://dev.twitter.com/apps and create a new App
* 2) Use the Authentication button to create the tokens/secrets needed
* 3) Copy the results into the appropriate spots below
// Callback form
"use strict";
var sqldb = require('sqldb');
sqldb.connect('mysql',{dbname:'test',user:'root'},function(e,dbh){
if (e) throw e;
dbh.prepare('SELECT :bar as world',function(e,sth){
if (e) throw e;
sth.param('bar','Hello');
sth.execute(function(e,rows){
@iarna
iarna / gist:8031884
Last active December 31, 2015 19:09
Perl6 optional types
sub test(Int $a) { say $a + 3 }
test(23); # 26
sub test(Int $a) { say $a + 3 }
test("23"); # Calling 'test' will never work with argument types (str) (line 1)
            #    Expected: :(Int $a)
use strict;
use warnings;
use Benchmark;
use List::MoreUtils qw(minmax uniq part);
use Test::More tests => 1;
my @set; push @set, int(rand()*1000) for 1..10_000;
my $pivot_a = 333;
my $pivot_b = 666;
// My Promisable's library provides two forms of use, one looks mostly like typical promises/A+ a'la Q and bluebird.
// The other looks more like callbacks. This gist shows examples of the two that are semantically equivalent.
// In practice, you wouldn't normally chain Promisables in the callback style to connect success and error handlers the way
// you do with the promises with then/catch/finally.
Assuming:
var Promisable = require('promisable');
Then:
.then(function(V){ … })
@iarna
iarna / fail1.js
Created March 3, 2014 21:28
Error domain bug in Node 0.10 (seems fixed in 0.11)
var soon = process.nextTick;
require('domain').create()
.on('error', function(E){ console.log("All is well soon") })
.run(function() {
soon(function(){ throw new Error() })
});
// We expect "All is well soon" to be logged
// Instead we get:
/*
@iarna
iarna / example.js
Last active August 29, 2015 13:58
Round tripping full Gearman protocol transform filters
"use strict";
var streamify = require('stream-array');
var GearmanPacket = require('./gearman-packet');
var through = require('through2');
// Showing off the round tripping
// Below is are the example packets from the Gearman protocol docs, plus an admin command
// Notice how you can intermix these all without any issues
streamify([