Skip to content

Instantly share code, notes, and snippets.

View leefouce's full-sized avatar

leefouce leefouce

View GitHub Profile
#! /bin/bash
date
cat ips.txt | while read output
do
echo 'ping' $output
ping -c 1 "$output" > /dev/null
if [ $? -eq 0 ]; then
echo "node $output is up"
else
echo "node $output is down"
"""
Select database based on URL variable
Inspired by this Django snipped:
https://djangosnippets.org/snippets/2037/
It's assumed that any view in the system with a cfg keyword argument passed to
it from the urlconf may be routed to a separate database. for example:
@leefouce
leefouce / mysql_backup.sh
Last active February 13, 2018 02:59
mysql simple backup shell
#!/bin/bash
mysqlbkdir='/mnt/web/webbackup/mysql/'
sqlfile='www-vuedo-'`date '+%F'`'.sql.gz'
webdir='/var/www/vuedo'
oldsqlfile=$mysqlbkdir'www-vuedo-'`date '+%F' --date='1 days ago'`'.sql.gz'
@leefouce
leefouce / array_orderby.php
Last active December 18, 2017 06:46
the way to sort database-style results
function array_orderby()
{
$args = func_get_args();
$data = array_shift($args);
foreach ($args as $n => $field) {
if (is_string($field)) {
$tmp = array();
foreach ($data as $key => $row)
$tmp[$key] = $row[$field];
$args[$n] = $tmp;
@leefouce
leefouce / array_sort.php
Created December 18, 2017 04:06
php code : sort an array by a specific key
function array_sort($array, $on, $order=SORT_ASC)
{
$new_array = array();
$sortable_array = array();
if (count($array) > 0) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $on) {