Skip to content

Commit

Permalink
few scripts added
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhu007 committed Nov 26, 2020
1 parent 48167bf commit 3c5fb9d
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 0 deletions.
77 changes: 77 additions & 0 deletions html_scripts/content-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<style>
.list-group {
list-style: decimal inside;
}

.list-group-item {
display: list-item;
}

.a_class {
color: inherit;
}
#bro{
border-style: solid;
}
</style>
</head>
<body>
<div class="row">
<div class="col-md-4 border border-dark">
<ul class="list-group list-group-flush" id="bro">
<li class="list-group-item "><a href="#" class="a_class">First Item</a></li>

<li class="list-group-item"><a href="#" class="a_class">second item
<!-- Look, the closing </li> tag is not placed here! -->
<ol class="list-group">
<li class="list-group-item"><a href="#" class="a_class">second item first subitem</a></li>
<li class="list-group-item"><a href="#" class="a_class">second item second subitem</a></li>
<li class="list-group-item"><a href="#" class="a_class">second item third subitem
<ol class="list-group">
<li class="list-group-item"><a href="#" class="a_class">second item first subitem</a></li>
<li class="list-group-item"><a href="#" class="a_class">second item second subitem</a></li>
<li class="list-group-item"><a href="#" class="a_class">second item third subitem
<ol class="list-group">
<li class="list-group-item active"><a href="#" class="a_class">second item first subitem siddidbsfdfdjfndfj</a></li>
<li class="list-group-item"><a href="#" class="a_class">second item second subitem</a></li>
<li class="list-group-item"><a href="#" class="a_class">second item third subitem</a></li>
</ol>
</a></li>
</ol>
</a></li>
</ol>
<!-- Here is the closing </li> tag -->
</a></li>
<li class="list-group-item"><a href="#" class="a_class">third item</a></li>
<li class="list-group-item"><a href="#" class="a_class">third item</a></li>
<li class="list-group-item"><a href="#" class="a_class">third item</a></li>
<li class="list-group-item"><a href="#" class="a_class">third item</a></li>
<li class="list-group-item"><a href="#" class="a_class">third item</a></li>
</ul>
</div>
<div class="col-md-8">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
</body>
</html>
30 changes: 30 additions & 0 deletions html_scripts/html_to_pdf.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("#btnPrint").live("click", function () {
var divContents = $("#dvContainer").html();
var printWindow = window.open('', '', 'height=400,width=800');
printWindow.document.write('<html><head><title>DIV Contents</title>');
printWindow.document.write('<style> #dvContainer {background:red;} </style>');
printWindow.document.write('</head><body >');
printWindow.document.write(divContents);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
});
</script>
<style> #dvContainer {background:red;} </style>
</head>


<body>
<form id="form1">
<div id="dvContainer">
This content needs to be printed.
</div>
<input type="button" value="Print Div Contents" id="btnPrint" />
</form>
</body>
</html>
84 changes: 84 additions & 0 deletions php_scripts/codesponsors_snippets/back_up_mysql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
//ENTER THE RELEVANT INFO BELOW
$mysqlUserName = "root";
$mysqlPassword = "";
$mysqlHostName = "localhost";
$DbName = "yourdatabase";
$backup_name = "mybackup.sql";
$tables = ['your_table1','your_table2'];

//or add 5th parameter(array) of specific tables: array("mytable1","mytable2","mytable3") for multiple tables

Export_Database($mysqlHostName,$mysqlUserName,$mysqlPassword,$DbName, $tables, $backup_name);

function Export_Database($host,$user,$pass,$name, $tables=false, $backup_name=false )
{
$mysqli = new mysqli($host,$user,$pass,$name);
$mysqli->select_db($name);
$mysqli->query("SET NAMES 'utf8'");

$queryTables = $mysqli->query('SHOW TABLES');
while($row = $queryTables->fetch_row())
{
$target_tables[] = $row[0];
}
if($tables !== false)
{
$target_tables = array_intersect( $target_tables, $tables);
}
foreach($target_tables as $table)
{
$result = $mysqli->query('SELECT * FROM '.$table);
$fields_amount = $result->field_count;
$rows_num=$mysqli->affected_rows;
$res = $mysqli->query('SHOW CREATE TABLE '.$table);
$TableMLine = $res->fetch_row();
$content = (!isset($content) ? '' : $content) . "\n\n".$TableMLine[1].";\n\n";

for ($i = 0, $st_counter = 0; $i < $fields_amount; $i++, $st_counter=0)
{
while($row = $result->fetch_row())
{ //when started (and every after 100 command cycle):
if ($st_counter%100 == 0 || $st_counter == 0 )
{
$content .= "\nINSERT INTO ".$table." VALUES";
}
$content .= "\n(";
for($j=0; $j<$fields_amount; $j++)
{
$row[$j] = str_replace("\n","\\n", addslashes($row[$j]) );
if (isset($row[$j]))
{
$content .= '"'.$row[$j].'"' ;
}
else
{
$content .= '""';
}
if ($j<($fields_amount-1))
{
$content.= ',';
}
}
$content .=")";
//every after 100 command cycle [or at last line] ....p.s. but should be inserted 1 cycle eariler
if ( (($st_counter+1)%100==0 && $st_counter!=0) || $st_counter+1==$rows_num)
{
$content .= ";";
}
else
{
$content .= ",";
}
$st_counter=$st_counter+1;
}
} $content .="\n\n\n";
}
//$backup_name = $backup_name ? $backup_name : $name."___(".date('H-i-s')."_".date('d-m-Y').")__rand".rand(1,11111111).".sql";
$backup_name = $backup_name ? $backup_name : $name.".sql";
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"".$backup_name."\"");
echo $content; exit;
}
?>
56 changes: 56 additions & 0 deletions php_scripts/codesponsors_snippets/shedule_repeater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
// Set timezone
date_default_timezone_set('UTC');
function repeatEvent($startTime, $interval, $frequency, $endTime)
{
//make sure all paramters are valid
$startTime = (int) $startTime;
$endTime = (int) $endTime;
if($startTime == 0)
{
user_error("repeatEvent(): invalid start time");
return(FALSE);
}

if($endTime < $startTime)
{
user_error("repeatEvent(): invalid end time");
}

$interval = strtolower(trim($interval));
if(!in_array($interval, array('day','week','month','year')))
{
user_error("repeatEvent(): Invalid interval '$interval'");
return(FALSE);
}
$frequency = (int)$frequency;
if($frequency < 1)
{
user_error("repeatEvent(): Invalid frequency '$frequency'");
return(FALSE);
}
$schedule = array();
for($time = $startTime; $time <= $endTime; $time = strtotime("+$frequency $interval", $time))
{
$schedule[] = $time;
}
return($schedule);
}

$start_date = "2020-10-10 04:05:00";
$end_date = "2022-11-25 04:05:00";
//$interval must be (case-insensitive): 'day', 'week', 'month', or 'year'
$new_interval = 'day';
// $frequency must be positive integer (1 = every, 2, = every other, 3 = every 3rd, 4 = every 4th. 5 = every 5th, 6 = every 6th)
$new_frequency = 4;

$sched = repeatEvent(strtotime($start_date), $new_interval, $new_frequency, strtotime($end_date));
// echo "<pre>";
// print_r($sched);

foreach ($sched as $d)
{
echo date('d-M-Y h:i:s', $d).PHP_EOL;
}
?>

49 changes: 49 additions & 0 deletions php_scripts/codesponsors_snippets/sortable_menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
#Set up your database return below format array
$data = [
["id" => 1, "name"=>"A", "parent_id" => 0],
["id" => 2, "name"=>"B", "parent_id" => 1],
["id" => 3, "name"=>"C", "parent_id" => 1],
["id" => 4, "name"=>"D", "parent_id" => 1],
["id" => 5, "name"=>"E", "parent_id" => 1],
["id" => 6, "name"=>"F", "parent_id" => 1],
["id" => 7, "name"=>"G", "parent_id" => 1],
["id" => 8, "name"=>"H", "parent_id" => 1],
["id" => 9, "name"=>"B1", "parent_id" => 2],
["id" => 10, "name"=>"B2", "parent_id" => 2],
["id" => 11, "name"=>"B3", "parent_id" => 2],
["id" => 12, "name"=>"C1", "parent_id" => 3],
["id" => 13, "name"=>"C2", "parent_id" => 3],
["id" => 14, "name"=>"C3", "parent_id" => 3],
["id" => 15, "name"=>"D1", "parent_id" => 4],
["id" => 16, "name"=>"D2", "parent_id" => 4],
["id" => 17, "name"=>"DD1", "parent_id" => 15],
["id" => 18, "name"=>"DDD1", "parent_id" => 17],
["id" => 19, "name"=>"DDDD1", "parent_id" => 18],
["id" => 20, "name"=>"DDDDD1", "parent_id" => 19]
];


$arr = $data;
$new = array();
foreach ($arr as $a)
{
$new[$a['parent_id']][] = $a;
}

function createTree(&$list, $parent)
{
$tree = array();
foreach ($parent as $k=>$l){
if(isset($list[$l['id']])){
$l['children'] = createTree($list, $list[$l['id']]);
}
$tree[] = $l;
}
return $tree;
}

$tree = createTree($new, array($arr[0]));
echo "<pre>";
print_r($tree);
?>
38 changes: 38 additions & 0 deletions php_scripts/codesponsors_snippets/zip_folder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
class GoodZipArchive extends ZipArchive
{
//@author Nicolas Heimann
public function __construct($a=false, $b=false) { $this->create_func($a, $b); }

public function create_func($input_folder=false, $output_zip_file=false)
{
if($input_folder !== false && $output_zip_file !== false)
{
$res = $this->open($output_zip_file, ZipArchive::CREATE);
if($res === TRUE) { $this->addDir($input_folder, basename($input_folder)); $this->close(); }
else { echo 'Could not create a zip archive. Contact Admin.'; }
}
}

// Add a Dir with Files and Subdirs to the archive
public function addDir($location, $name) {
$this->addEmptyDir($name);
$this->addDirDo($location, $name);
}

// Add Files & Dirs to archive
private function addDirDo($location, $name) {
$name .= '/'; $location .= '/';
// Read all Files in Dir
$dir = opendir ($location);
while ($file = readdir($dir)) {
if ($file == '.' || $file == '..') continue;
// Rekursiv, If dir: GoodZipArchive::addDir(), else ::File();
$do = (filetype( $location . $file) == 'dir') ? 'addDir' : 'addFile';
$this->$do($location . $file, $name . $file);
}
}
}

new GoodZipArchive('path/to/input/folder', 'path/to/output_zip_file.zip') ;
?>

0 comments on commit 3c5fb9d

Please sign in to comment.