Skip to content

Instantly share code, notes, and snippets.

@kruxor
kruxor / Check if a table Exists PHP
Last active August 29, 2015 13:58
Will return true or false if a table exists or not $db is a mysqli db connection
<?php
function table_exists($table) {
global $db;
$sql = "SHOW TABLES LIKE '$table' ";
$result = $db->query($sql);
$num = 0;
$num = mysqli_num_rows($result);
if($num > 0) {
return true;
}
@kruxor
kruxor / Load directory content into a javascript array PHP JS
Last active August 29, 2015 13:58
Get an Image/file list into an javascript array - cross php with javascript
<script type="text/javascript">
var imageList=[<?php
$dir='uploads';
$files = scandir($dir);
foreach((array)$files as $file){
if($file=='.'||$file=='..') continue;
$fileList[]=$file;
}
echo "'".implode("','", $fileList)."'";
?>];
@kruxor
kruxor / index.php
Created April 14, 2014 00:32
Imgur Upload using v3 api - PHP - JSON : Ignores SSL Cert Errors
<html>
<body>
<form action="upload_img.php" method="post" enctype="multipart/form-data">
<input type="file" name="imgupload" /><br>
<input type="submit" value="Upload to Imgur" />
</form>
</body>
</html>
@kruxor
kruxor / show_all_db.php
Created April 15, 2014 00:44
show all tables in the selected database
<?php
/* list db structure */
function show_all_db() {
global $db;
global $db_name;
$out = "";
$sql = "SELECT table_name, column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = '$db_name'
@kruxor
kruxor / time_diff_days
Last active August 29, 2015 14:05
Show the number of days difference between now and a timestamp
function time_diff_days($your_date) {
$now = time(); // or your date as well
$your_date = strtotime($your_date);
$datediff = $now - $your_date;
return floor($datediff/(60*60*24));
}
@kruxor
kruxor / rand_color
Created September 8, 2014 07:28
return a random hex color value in php
function rand_color() {
return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
}
@kruxor
kruxor / php_curl_post.php
Last active August 29, 2015 14:06
Post back to a URL using curl
function httpPost($url,$params)
{
$postData = '';
//create name value pairs seperated by &
foreach($params as $k => $v)
{
$postData .= $k . '='.$v.'&';
}
rtrim($postData, '&');

Youtube Video in Modal/Dialog stops when closed

So the issue with modals/dialog and iframe videos / youtube embeds is that they keep playing in the background. This stops the playback when the dialog is closed. No More video playing in the background.

A Pen by Luke on CodePen.

License.

@kruxor
kruxor / find_links
Created October 15, 2014 00:43
find links from plain text and link them.