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 / 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 / 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 / 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 / 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 / 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 / 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 / chartjs-example.php
Last active December 21, 2020 01:42
PDO chart data example, chartjs multiline tooltip text
<script src="Chart.bundle.js"></script>
<?php
$host = 'localhost';
$username = 'root';
$password = '';
$db_name = 'tes';
$conn = new PDO("mysql:host={$host};dbname={$db_name}", $username, $password);
$conn->exec("set names utf8");
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
@relliv
relliv / ReadableNumberHelper.php
Last active March 2, 2021 13:09 — forked from mauro-baptista/NumberFormat.php
Easily readable numbers with custom locale
<?php
namespace App\Helpers;
/**
* Numbers more readable for humans
* It intends to change numbers as 1000 as 1K or 1200000 as 1.2M
* This code is heavly base in this one: https://gist.github.com/RadGH/84edff0cc81e6326029c
* How to use \NumberFormat::readable(1000);
*
@relliv
relliv / AppServiceProvide.php
Last active May 29, 2021 22:23
Laravel SVG loader directive example
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\File;
class AppServiceProvider extends ServiceProvider
{