Skip to content

Instantly share code, notes, and snippets.

View generate-where-bind.pm
# $self->query_to_where({name => "Bruce"}, {name => "eq"}) => ["name = ?"], ["Bruce"]
# $self->query_to_where({name => "Bruce"}, {name => "like"}) => ["name LIKE '%?%'"], ["Bruce"]
# $self->query_to_where({age => ">=42"}, {age => "num"}) => ["name >= ?"], [42]
sub query_to_where {
my ($self, $q, $rules) = @_;
my (@where, @bind);
for my $col (sort keys %$rules) {
if (!length $q->{$col} // '') {
1; # next
@jberger
jberger / URLQueue.pl
Last active Sep 22, 2017
Modularization of my answer from SO on URL queuing for non-blocking ua
View URLQueue.pl
#!/usr/bin/env perl
package Mojo::URLQueue;
use Mojo::Base 'Mojo::EventEmitter';
use Mojo::UserAgent;
has queue => sub { [] };
has ua => sub { Mojo::UserAgent->new(max_redirects => 5) };
has concurrency => 4;
@caniszczyk
caniszczyk / clone-all-twitter-github-repos.sh
Created Oct 9, 2012
Clone all repos from a GitHub organization
View clone-all-twitter-github-repos.sh
curl -s https://api.github.com/orgs/twitter/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}'
@rsvp
rsvp / noise.sh
Last active Apr 7, 2021
noise : relaxing ambient Brown noise generator (cf. white noise) | Linux bash script using sox | CogSci notes
View noise.sh
#!/usr/bin/env bash
# bash 4.1.5(1) Linux Ubuntu 10.04 Date : 2019-01-02
#
# _______________| noise : ambient Brown noise generator (cf. white noise).
#
# Usage: noise [minutes=59] [band-pass freq center=1786] [wave]
# ^minutes can be any positive integer.
# Command "noise 1" will display peak-level meter.
#
# Dependencies: play (from sox package)