Skip to content

Instantly share code, notes, and snippets.

View mgsmus's full-sized avatar

Mustafa Akçakaya mgsmus

View GitHub Profile
<?php
class User {
public int $id;
public string $name;
public function __construct(int $id, string $name) {
$this->id = $id;
<?php
class User {
/** @var int $id */
private $id;
/** @var string $name */
private $name;
<?php
use Money\Currencies\ISOCurrencies;
use Money\Parser\DecimalMoneyParser;
use Money\Formatter\IntlMoneyFormatter;
use Money\Converter;
use Money\Currency;
use Money\Exchange\FixedExchange;
use Money\Exchange\ReversedCurrenciesExchange;
@mgsmus
mgsmus / AppServiceProvider.php
Created April 12, 2019 06:53 — forked from simonhamp/AppServiceProvider.php
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@mgsmus
mgsmus / cryptor.php
Created November 20, 2018 13:08 — forked from petermuller71/cryptor.php
cryptor : PHP Encryption and decryption based on libsodium (standard lib >php7.2)
<?php
print "<h1>PHP Encryption with libsodium</h1>";
$message = "This text is secret";
$ciphertext = cryptor::encrypt("password", $message);
$plaintext = cryptor::decrypt("password", $ciphertext);
print "Message:<br />$message <br /><br />Ciphertext:<br />$ciphertext<br /><br />Plaintext:<br />$plaintext";
Resources marked with > are used, have been used, or are actively advocated in the threads. This applies for everything in the [Necessities] section.
[Necessities]
Hiragana & Katakana: http://www.realkana.com/
Kanji: http://kanjidamage.com/
Japanese IME: http://www.google.com/intl/ja/ime/
Anki Flashcards: http://ankisrs.net/
Genki (↓Bottom↓)
Tae Kim Japanese: http://www.guidetojapanese.org/learn/grammar
@mgsmus
mgsmus / nested_array.php
Created March 7, 2018 10:10
Creating a nested array from items with parent IDs
function makeNested($source) {
$nested = array();
foreach ( $source as &$s ) {
if ( is_null($s['parent_id']) ) {
// no parent_id so we put it in the root of the array
$nested[] = &$s;
}
else {
$pid = $s['parent_id'];
@mgsmus
mgsmus / product_variants.php
Created January 2, 2018 12:29
Products variants
// https://stackoverflow.com/a/33259643
function get_combinations($arrays) {
$result = array(array());
foreach ($arrays as $property => $property_values) {
$tmp = array();
foreach ($result as $result_item) {
foreach ($property_values as $property_key => $property_value) {
$tmp[] = $result_item + array($property_key => $property_value);
}
@mgsmus
mgsmus / function_v1.php
Created November 8, 2016 12:36 — forked from b-b3rn4rd/function_v1.php
Convert adjacency list into tree without recursion and second array.
<?php
function array_to_tree(array $array, $parent_id = 0)
{
$array = array_combine(array_column($array, 'id'), array_values($array));
foreach ($array as $k => &$v) {
if (isset($array[$v['parent_id']])) {
$array[$v['parent_id']]['children'][$k] = &$v;
}
@mgsmus
mgsmus / rgb_to_hex_to_rgb.php
Created October 4, 2016 00:55 — forked from Pushplaybang/rgb_to_hex_to_rgb.php
php functions convert hex to rgb and rgb to hex
function hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));