Skip to content

Instantly share code, notes, and snippets.

@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.:
@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 / 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 / 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 / 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 / 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 / index.html
Created January 29, 2017 11:58
rjYgPe
<div>
Helloz
</div>
@cereal-s
cereal-s / gist:c4c07138aded7c6cf17bb4da5aa3c1cc
Created May 22, 2017 12:26
[BASH] Watch specific process
watch -n 2 'ps -opid,pri,%cpu,%mem,user,args -p `pgrep php`'
@cereal-s
cereal-s / format_size.php
Last active April 21, 2018 16:27
Format bytes to KiB, MiB, GiB and TiB.
<?php
if( ! function_exists('_format_size'))
{
/**
* Return formatted bytes.
*
* @see http://www.iec.ch/si/binary.htm
* @param integer $bytes
* @param integer $kilo 1000, 1024
@cereal-s
cereal-s / gist:3ec7c45353e8e259ec16cf10ea2ad1a7
Last active August 24, 2019 14:09 — forked from codler/gist:3906826
Support HTTP Header Range, mp4, php.php/mp4.mp4
<?php
# Nginx doesn't have PATH_INFO
if (!isset($_SERVER['PATH_INFO'])) {
$_SERVER['PATH_INFO'] = substr($_SERVER["ORIG_SCRIPT_FILENAME"], strlen($_SERVER["SCRIPT_FILENAME"]));
}
$request = substr($_SERVER['PATH_INFO'], 1);
$file = $request;
$fp = @fopen($file, 'rb');