Skip to content

Instantly share code, notes, and snippets.

@Nayjest
Nayjest / Singleton.cs
Created January 21, 2022 08:53
Singleton for Unity3D, can be automatically loaded with GameObject from resources
/**
* © 2022 Vitalii Stepanenko
* Licensed under the MIT License
*
* Base Singleton class
*
* Features:
* - Can be loaded with object from resources (may be useful if you need some configuration of singleton instance made in editor, but dont want to store it in each scene)
* - Can be placed to scene as regular Monobehaviour
* - Can be instantiated with DontDestroyOnLoad if persistance between scenes needed
@Nayjest
Nayjest / gist:7750335e2fdae9358ccc
Created November 28, 2014 17:36
get laravel version starting from 5
method_exists(\App::getInstance(),'version')
the easiest way to use multiple constructors:
<?php
class A
{
function __construct()
{
$a = func_get_args();
$i = func_num_args();
if (method_exists($this,$f='__construct'.$i)) {
@Nayjest
Nayjest / PHP: Instantiate a class by class name and arguments.php
Last active January 21, 2022 08:48
PHP: Instantiate a class by class name and arguments
<?php
function makeInstance($class, $arguments = [])
{
switch (count($arguments)) {
case 0: return new $class();
case 1: return new $class(array_shift($arguments));
case 2: return new $class(array_shift($arguments), array_shift($arguments));
default:
$reflection = new \ReflectionClass($class);
return $reflection->newInstanceArgs($arguments);
@Nayjest
Nayjest / FullAccessWrapper.php
Last active June 15, 2023 14:43
PHP Wrapper class for accessing protected/private members outside class
<?php
class FullAccessWrapper
{
protected $_self;
protected $_refl;
public function __construct($self)
{
$this->_self = $self;
$this->_refl = new ReflectionObject($self);
@Nayjest
Nayjest / jade_browser_extends_include.js
Last active December 15, 2015 13:59
Jade 'extends' or 'include' in browser
if (typeof window !== 'undefined') {
/**
* client based path.js
*
*/
require.register("path.js", function(module, exports, require){
var list = [];
module.exports = {
dirname : function(path) {
path = path || "";