Skip to content

Instantly share code, notes, and snippets.

@cereal-s
cereal-s / fx.php
Last active January 26, 2017 13:45
Generate a fade to the transparent, into the right side of the given image. Done with a composite gradient.
<?php
/**
* Script usage:
*
* /script.php?fade_width=200&image_url=http://localhost/images/image.jpg
*
* @see http://imagemagick.org/Usage/compose/#copy
* @see http://imagemagick.org/Usage/compose/#dstout
*
@cereal-s
cereal-s / acos.py
Last active January 19, 2017 00:19
Calculate the inverse cosine in degrees.
#!/usr/bin/env python3
'''
Calculate the inverse cosine to
get the angle of the focus plane
in relation with the photographed surface.
Where `adjacent`, `opposite` and `hypotenuse`
are the parts of a right-angled triangle
@cereal-s
cereal-s / recursive_files.php
Created December 24, 2016 13:43
Recursive directory iterator to list all readable files.
<?php
$path = dirname(__DIR__);
$dir_iterator = new RecursiveDirectoryIterator($path
, FilesystemIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($dir_iterator
, RecursiveIteratorIterator::LEAVES_ONLY
, RecursiveIteratorIterator::CATCH_GET_CHILD);
@cereal-s
cereal-s / workspaces.sh
Created December 24, 2016 12:28
Change the number of workspaces in Ubuntu 16.04: usage `./workspaces.sh 3 3` to get 9 workspaces
#!/usr/bin/env sh
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ vsize $1
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ hsize $2
@cereal-s
cereal-s / mysql_dump_backup.php
Last active August 24, 2019 14:26
Dump of MySQL server
<?php
/**
* This script does a full backup of a MySQL server
* it uses `mysqldump` to save:
*
* - full database: create & inserts
* - tables create statements
* - table inserts
* - database routines: functions & stored procedures
@cereal-s
cereal-s / nasa.apod.php
Last active December 21, 2016 10:49
NASA APOD API example with Memcached
<?php
/**
* Example of the NASA APOD API with Memcached
*
* @see https://api.nasa.gov/api.html#apod
* @see http://php.net/manual/en/class.memcached.php
*
* Since it is working with the `DEMO_KEY` rate limits
* are very low, and can be see in the RESPONSE headers, e.g.:
<?php
header('Content-Type: text/csv');
$data[] = ['sent'
, 'success'
, '114661698'
, '709081462'
, '+919900123456'
];
@cereal-s
cereal-s / dict.pwl
Last active December 19, 2016 12:15
hello
world
apple
fruit
banana
yellow
orange
strawberry
cherry
pie
#!/usr/bin/env sh
if LC_ALL=C grep -q '[^[:print:][:space:]]' "/path/to/file.jpg"; then
echo "file contains non-ascii characters"
else
echo "file contains ascii characters only"
fi
<?php
$word = 'scmo';
$pspell_config = pspell_config_create("it");
# Available modes:
#
# PSPELL_FAST
# PSPELL_NORMAL
# PSPELL_BAD_SPELLERS # this will slow down the script