Skip to content

Instantly share code, notes, and snippets.

View webkader's full-sized avatar

Baris Aydin webkader

View GitHub Profile
@webkader
webkader / ffmpeg-watermark.md
Created July 13, 2015 18:21
FFmpeg add a watermark to video

How to Add a Watermark to Video

FFMPEG filters provide a powerful way to programmatically enhance or alter videos, and it’s fairly simple to add a watermark to a video using the overlay filter. The easiest way to install ffmpeg is to download a pre-built binary for your specific platform. Then you don’t have to worry about including and installing all the right dependencies and codecs you will be using.

Once you have ffmpeg installed, adding a watermark is as easy as passing your existing source through an overlay filter like so:

ffmpeg -i test.mp4 -i watermark.png -filter_complex "overlay=10:10" test1.mp4

Basically, we’re passing in the original video, and an overlay image as inputs, then passing it through the filter, and saving the output as test1.mp4.

@webkader
webkader / isValidInteger.php
Last active August 29, 2015 14:24
Check if a string is a valid positive integer
function isValidInteger($integer)
{
if (filter_var($integer, FILTER_VALIDATE_INT) && $integer > 0) {
return true;
} else {
return false;
}
}
@webkader
webkader / isValidFloat.php
Created July 13, 2015 18:29
Check if a string is a valid float
function isValidFloat($float)
{
if (filter_var($float, FILTER_VALIDATE_FLOAT)) {
return true;
} else {
return false;
}
}
@webkader
webkader / isValidString.php
Created July 13, 2015 18:30
Check if a string is a valid string
function isValidString($string)
{
if (empty($string)) {
return false;
}
if (preg_match("/[\||\'|\<|\>|\[|\]|\"|\!|\?|\$|\@|\/|\\\|\&\~\*\{\+]/", $string)) {
return false;
} else {
return true;
@webkader
webkader / isValidUrl.php
Created July 13, 2015 18:31
Check if a string is a valid url
function isValidUrl($url)
{
if (empty($url)) {
return false;
}
// only ASCII URL
if (filter_var($url, FILTER_VALIDATE_URL)) {
return true;
} else {
@webkader
webkader / isValidEmail.php
Created July 13, 2015 18:32
Check if a string is a valid email
function isValidEmail($email)
{
if (empty($email)) {
return false;
}
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (@count(explode("@", $email)) != 2) {
return false;
} else {
@webkader
webkader / isValidDate.php
Created July 13, 2015 18:41
Check if a string is a valid date
function isValidDate($date, $format = "d-m-Y H:i:s")
{
//since php 5.3
$parsedate = date_parse_from_format($format, $date);
$datetmp = mktime($parsedate['hour'], $parsedate['minute'], $parsedate['second'], $parsedate['month'], $parsedate['day'], $parsedate['year']);
return (strtotime($date) == $datetmp) ? true : false;
}
@webkader
webkader / isValidTax.php
Last active August 29, 2015 14:24
Check if a string is a valid tax number
function isValidTax($vatid)
{
$vatid = str_replace(array(
' ',
'.',
'-',
',',
', '), '', trim($vatid));
$prefix = substr($vatid, 0, 2);
$number = substr($vatid, 2);
@webkader
webkader / compareFloatValues.php
Last active August 29, 2015 14:24
Comparing float values
// look into http://php.net/manual/en/language.types.float.php
function compareFloatValues($a, $b, $operator = '==')
{
// This value is known as the machine epsilon, or unit roundoff, and is the smallest acceptable difference in calculations.
$epsilon = 0.00001;
// make equal to 5 digits of precision
$a = (float)$a;
$b = (float)$b;
@webkader
webkader / isNetworkAvailable.java
Created July 13, 2015 18:51
Check network is available in Android
/**
* isNetworkAvailable() TRUE wenn eine Datenverbindung vorhanden ist
*
* @param mixed activity
* @return
*/
public static boolean isNetworkAvailable(Activity activity) {
ConnectivityManager connectivity = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;