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 / autoload.php
Created October 14, 2020 03:37
PHP PSR-4 Autoloader Example
<?php
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
/**
* Custom PSR-4 autoloader
*
* @param array $packages: array of packages
* @source https://github.com/Wilkins/composer-file-loader
*/
@relliv
relliv / delete-recursive.php
Created October 9, 2020 16:42
Delete folder and contains with recursive way
<?php
// target directory path
$target = __DIR__.'/./thumbs';
/**
* Delete folder and contents recursively
*
* @param string $target: target dir path
* @return bool|null
@relliv
relliv / form1.cs
Created December 7, 2019 16:00
Başka formdaki resmiyazdırma
```csharp
// açık olan formlar içinde dönelim
foreach (Form form in Application.OpenForms.OfType<Form>().ToList())
{
if (form.Name == "Form2")
{
// Form2'nin içindeki controller içinde dönelim
foreach (Control control in form.Controls)
{
if (control.Name == "pictureBox1")
@relliv
relliv / main.cs
Created June 6, 2019 11:35
C# WFA Grid Cell If Contains Then Set Color
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace TestaWFA
{
public partial class Form1 : Form
{
public Form1()
@relliv
relliv / hex-to-rgba.php
Created February 26, 2019 18:56
PHP HEX to RGBa
<?php
/**
* Hex to RGBa
*
* @param string $color: hex color
* @param bool|float $opacity: alpha channel, optional
* @param string $default: default return value
*/
function hex2rgba($color, $opacity = false, $default = 'rgb(0,0,0)')
{
@relliv
relliv / GetMonitorSize.cs
Created February 22, 2019 20:20
C# Get Monitor Size As Inch
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
private void Button_Click(object sender, RoutedEventArgs e)
{
Graphics graphics = Graphics.FromHwnd(IntPtr.Zero); // using System.Drawing; (add from referances)
IntPtr desktop = graphics.GetHdc();
int monitorHeight = GetDeviceCaps(desktop, 6);
int monitorWidth = GetDeviceCaps(desktop, 4);
Content = $"Height: {monitorHeight} mm., Width: {monitorWidth} mm. This Monitor Size: {Math.Sqrt(Math.Pow(monitorHeight, 2) + Math.Pow(monitorWidth, 2)) / 25,4:#,##0.00} inch.";
@relliv
relliv / GetMonitorSize.cs
Created February 22, 2019 20:20
C# Get Monitor Size As Inch
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
private void Button_Click(object sender, RoutedEventArgs e)
{
Graphics graphics = Graphics.FromHwnd(IntPtr.Zero); // using System.Drawing; (add from referances)
IntPtr desktop = graphics.GetHdc();
int monitorHeight = GetDeviceCaps(desktop, 6);
int monitorWidth = GetDeviceCaps(desktop, 4);
Content = $"Height: {monitorHeight} mm., Width: {monitorWidth} mm. This Monitor Size: {Math.Sqrt(Math.Pow(monitorHeight, 2) + Math.Pow(monitorWidth, 2)) / 25,4:#,##0.00} inch.";
@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
@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 / 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)
{