Skip to content

Instantly share code, notes, and snippets.

View ichadhr's full-sized avatar
Focusing

Chad ichadhr

Focusing
View GitHub Profile
  1. What is the output of the following code:
$a = '1';
$b = &$a;
$b = "2$b";
echo $a.", ".$b;
  1. What is the difference between $_GET and $_POST?
  2. What does the isset() function mean?
@ichadhr
ichadhr / Test.md
Last active September 24, 2021 07:40
  1. What is the output of the following code:
$a = '1';
$b = &$a;
$b = "2$b";
echo $a.", ".$b;
  1. What is the difference between $_GET and $_POST?
  2. What does the isset() function mean?
@ichadhr
ichadhr / Test.md
Created September 21, 2021 02:21
  1. What is the output of the following code:
$a = '1';
$b = &$a;
$b = "2$b";
echo $a.", ".$b;
  1. What is the difference between $_GET and $_POST?
  2. What does the isset() function mean?
  3. Convert bellow conditional statements to ternary conditional operator?
@ichadhr
ichadhr / create-efi-keys.sh
Created October 22, 2020 11:59 — forked from Era-Dorta/create-efi-keys.sh
Sign kernel modules on Ubuntu, useful for Nvidia drivers in UEFI system
# VERY IMPORTANT! After each kernel update or dkms rebuild the modules must be signed again with the script
# ~/.ssl/sign-all-modules.sh
# Place all files in ~/.ssl folder
mkdir ~/.ssl
cd ~/.ssl
# Generate custom keys with openssl
openssl req -new -x509 -newkey rsa:2048 -keyout MOK.priv -outform DER -out MOK.der -nodes -subj "/CN=Owner/"
@ichadhr
ichadhr / FileDownload.cs
Last active January 23, 2020 20:41
C# File Download
public class FileDownload {
private volatile bool _completed;
public void DownloadFile(string address, string location) {
using(WebClient client = new WebClient()) {
Uri Uri = new Uri(address);
_completed = false;
client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(Completed);
@ichadhr
ichadhr / FindRealtedTable.sql
Created November 11, 2019 05:37
Find Realted Table SQL
SELECT
c.CONSTRAINT_NAME,
cu.TABLE_NAME AS ReferencingTable, cu.COLUMN_NAME AS ReferencingColumn,
ku.TABLE_NAME AS ReferencedTable, ku.COLUMN_NAME AS ReferencedColumn
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS c
INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE cu
ON cu.CONSTRAINT_NAME = c.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE ku
ON ku.CONSTRAINT_NAME = c.UNIQUE_CONSTRAINT_NAME
WHERE ku.TABLE_NAME = 'FOO'
@ichadhr
ichadhr / PercentRounder.cs
Created October 23, 2019 07:24 — forked from dochoffiday/PercentRounder.cs
Uses the "Largest Remainder Method" to ensure rounded percentages add up to their correct total
using System;
using System.Collections.Generic;
using System.Linq;
public class PercentRounder
{
public class PercentInfo
{
public int Index;
public int Percent;
function in_array_r($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && in_array_r($needle, $item, $strict))) {
return true;
}
}
return false;
}
// sample
```php
$array=[
['day'=>'11','movements'=>'1'],
['day'=>'11','movements'=>'1'],
['day'=>'11','movements'=>'1'],
['day'=>'12','movements'=>'1'],
['day'=>'12','movements'=>'1'],
['day'=>'12','movements'=>'1']
];
foreach($array as $row){ // iterate all rows
@ichadhr
ichadhr / Sql Sorting Lat Long.md
Last active October 7, 2019 15:36
Geo latitude longtitude order

simple ordering lat long MySQL

SELECT
	*,
	6371 * ASIN(
		SQRT(
			POWER( SIN( ( '-8.637420' - sample.lat ) * pi( ) / 180 / 2 ), 2 ) + COS( '-8.637420' * pi( ) / 180 ) * COS( sample.lat * pi( ) / 180 ) * POWER( SIN( ( '115.253001' - sample.lng ) * pi( ) / 180 / 2 ), 2 ) 
		) 
	) AS distance 
FROM