Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/perl
# Usage: upgrade-cpan.pl 5.14.0 | sort -u | cpanm
use strict;
use File::Find::Rule;
use JSON;
my $old = shift;
my @files = File::Find::Rule->file->name('install.json')->in("$ENV{HOME}/perl5/perlbrew/perls/perl-$old/lib/site_perl/$old");
for my $file (@files) {
@kraih
kraih / c10k.pl
Last active March 20, 2021 14:33
#
# Open 10k concurrent WebSocket connections with the client and server running
# in the same process and perform 10k WebSocket message roundtrips
#
# Tested on OS X 10.9.2 (MacBook Air) with Perl 5.18.2 and EV 4.17 (kqueue)
#
# 560.9MB memory usage, 0% CPU usage once roundtrips are finished after 36s
# (with all 20k sockets still open)
#
# Get the latest version of Mojolicious from http://github.com/kraih/mojo
@miracle2k
miracle2k / plugin.js
Created August 18, 2013 13:40
CKEditor 3/4 plugin that adds a new "internal link" option to the Link dialog window. This is an adaption of Henri Medot's Drupal integration plugin (https://drupal.org/project/ckeditor_link) to a custom CMS system. I'm publishing it here because the original code includes no comments, which meant I had to figure out the CKEditor API and what th…
/**
* Add an "CMS internal link" option to the Link plugin.
*
* This was adapted from a similar plugin for Drupal (version 7.x-2.3):
* Written by Henri MEDOT <henri.medot[AT]absyx[DOT]fr>
* http://www.absyx.fr
* https://drupal.org/project/ckeditor_link
*
* Portions of code:
* Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
@razius
razius / chrome-refresh.sh
Last active November 6, 2018 13:50
Watches the folder or files passed as arguments to the script and when detects a change it automatically refreshes the current selected Chrome tab or window.
#!/bin/bash
#
# Watches the folder or files passed as arguments to the script and when it
# detects a change it automatically refreshes the current selected Chrome tab or
# window.
#
# http://razius.com/articles/auto-refreshing-google-chrome-on-file-changes/
#
# Usage:
# ./chrome-refresh.sh /folder/to/watch /some/folder/file_to_watch.html
@furagu
furagu / mojo-websocket-pubapp.pl
Last active April 8, 2022 19:13
Mojolicious websocket redis publish/subscribe example
#!/usr/bin/env perl
# Usage:
# cpanm Mojolicious Mojo::Redis
# ./mojo-websocket-pubapp.pl daemon
use Mojolicious::Lite;
use Mojo::Redis;
websocket '/' => sub {
@dex4er
dex4er / mojo-app.pl
Last active February 12, 2019 11:53
Mojolicious + PAR::Packer without --addfile
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use Mojolicious::Lite;
# Explicit use as a helper for PAR
#!/bin/bash
# For greatest convenience
alias dc='docker-compose'
# Clean up unused containers and images
alias dclean='docker rm $(docker ps -qf "status=exited")'
alias dclean_images='docker rmi $(docker images -qf "dangling=true")'
# Assume dockerized $nginx and $mysql containers...
@janeczku
janeczku / user-data.sh
Last active November 18, 2017 02:32
OVH Public Cloud - Cloud-Init bootstrap Failover IP + Docker
#!/bin/sh
cat > /etc/network/interfaces.d/eth0-0.cfg <<EOF
auto eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
address 178.32.XXX.XXX
netmask 255.255.255.255
broadcast 178.32.XXX.XXX
post-up /sbin/ip route replace default via $(/sbin/ip route | awk '/default/ { print $3 }') dev eth0 src 178.32.XXX.XXX
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@rrdelaney
rrdelaney / create-cluster.sh
Last active September 21, 2018 08:28
RethinkDB Cluster - Docker 1.12 Swarm Mode
docker network create -d overlay skynet
docker service create --name rethink-master --network skynet -p 8080:8080 rethinkdb rethinkdb --bind all
docker service create --name rethink-slave --mode global --mount type=bind,source=/var/lib/rethinkdb,target=/data --network skynet rethinkdb rethinkdb --bind all -j rethink-master