Skip to content

Instantly share code, notes, and snippets.

View relliv's full-sized avatar
no time for caution

Eyüp relliv

no time for caution
View GitHub Profile
@relliv
relliv / SQLite_Like.cs
Created June 14, 2018 23:28
SQLite Database CRUDS Operations
ProductsListView.ItemsSource = null;
const string connSTring = "Data Source=example.db; Version=3;";
using (var conn = new SQLiteConnection(connSTring))
{
conn.Open();
using (var comm = new SQLiteCommand(conn))
{
@relliv
relliv / folder_parser.php
Last active June 18, 2018 20:58
PHP URL Based Folder Parser
// url based folder parser
public function folderParser(){
// get current protocol
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https" : "http";
// build current full url
$requesturl = "{$protocol}://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
// parse request url with protocol
preg_match("/(https?:\/\/)(www.)?([a-z-_]+\.)?([a-z-_]+)(\.[a-z]{0,10})(\/)(.+)/", $requesturl, $allMatchs);
@relliv
relliv / disk.php
Created September 6, 2018 07:59
PHP Disk Quota, Percentages And Disks
<?php
class Disk
{
/**
* Returns detailed disk usage info
*
* @param string $dir target directory (default is root dir)
* @see http://php.net/manual/tr/function.disk-total-space.php
*/
@relliv
relliv / cksave.php
Last active July 27, 2020 23:57
PHP CKEditor content save to database and load from database
<?php
/*--------------------- CKEditor ----------------- START */
// CKEditor content prepare to database add process
public function CKEditorContentPrepare($content)
{
$content = trim($content);
$content = stripslashes($content);
$content = htmlspecialchars($content);
return $content;
@relliv
relliv / list-of-files-in-folder.php
Created February 3, 2019 16:16
List of Files in Folder (PHP)
// folder path and
// limits of selected files, *.* = all files
$folder = 'upload/profiles/2018-11/*.*';
// searched extensions
$ext_array = ['gif','jpg','jpeg','png'];
// get all files
$files = glob($folder);
@relliv
relliv / pagination.php
Created February 5, 2019 14:28
PHP Pagination Function
<?php
function pagination($total, $page, $limit, $query)
{
$total = !is_numeric($total) ? 0 : (int) $total;
$page = !is_numeric($page) ? 1 : (int) $page;
$limit = !is_numeric($limit) ? 25 : (int) $limit;
$total = (int) $total;
// query limit start
@relliv
relliv / mail.php
Created February 6, 2019 12:52
PHP Native Mail Function and Custom Mail Metod (with PHPMailer)
<?php
require_once dirname(__DIR__) . '/libs/phpmailer/Exception.php';
require_once dirname(__DIR__) . '/libs/phpmailer/PHPMailer.php';
require_once dirname(__DIR__) . '/libs/phpmailer/SMTP.php';
class Mail
{
/**
* Mail sender with PHPMailer library
*/
@relliv
relliv / date-comparer.php
Created February 7, 2019 10:16
PHP Date Comparer
/**
* Date comparer
*
* @param string $date: current date
* @param string $date2: target date
* @param bool $diff: date diff or past time condition
* @return bool|array
*/
public function dateCompare($current, $expire, $diff = false)
{
@relliv
relliv / common.php
Created February 15, 2019 18:11
Human Readable Time String with PHP
<?php
/**
* Get time elapsed string from given between dates by human readable format
*
* @param string $date_now: current date
* @param string $date_old: target old date
* @param bool $full: need full date ago string
*
* @see source: https://stackoverflow.com/a/18602474
*
@relliv
relliv / FolderCreator.cs
Created February 22, 2019 08:32
C# Auto Numeric Folder Creator With LINQ
private bool AutoFolderCreate(int incrementCount = 1)
{
var targetPath = Directory.GetCurrentDirectory() + "\\Saves";
if (Directory.Exists(targetPath))
{
var newDirName = Directory.EnumerateDirectories(targetPath) // list of sub directories in target
.Select(Path.GetFileName) // get directory/file name
.Where(n => n.All(Char.IsDigit)) // get only digits
.Select(int.Parse) // string parse to int