Skip to content

Instantly share code, notes, and snippets.

View bocharsky-bw's full-sized avatar
💔
#StandWithUkraine 🇺🇦

Victor Bocharsky bocharsky-bw

💔
#StandWithUkraine 🇺🇦
View GitHub Profile
@bocharsky-bw
bocharsky-bw / dump-array-keys.php
Last active August 29, 2015 13:56
Dump array keys
<?php
foreach ($result as $key => $value) {
var_dump($key);
}
@bocharsky-bw
bocharsky-bw / call.php
Last active April 14, 2017 00:19
Automatic call getter and isser methods
<?php
public function __call($method, $arguments) {
if ( method_exists($this->lang, $method) ) {
return call_user_func_array(array($this->lang, $method), $arguments);
}
$getter = 'get'. ucfirst($method);
if ( method_exists($this->lang, $getter) ) {
@bocharsky-bw
bocharsky-bw / display-errors.php
Created March 14, 2014 13:18
Display errors in PHP
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
<?php
$data = new stdClass();
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
/* Router */
if (isset($_POST['buy'])) {
$data->success = TRUE;
$data->message = 'Message succesfully sent';
@bocharsky-bw
bocharsky-bw / default-values.php
Last active August 29, 2015 13:57
Passed array options with default values
<?php
public function __construct(array $options = array()) {
/* By default */
$options = array_merge(
array(
'one' => 1,
'two' => 2,
'three' => 3,
),
@bocharsky-bw
bocharsky-bw / doctrine-default-value.php
Created March 25, 2014 10:45
Default value of the field in Doctrine 2
<?php
/**
* @var string $surname
*
* @ORM\Column(name="surname", type="string", length=255, options={"default" = ""})
*/
private $surname;
@bocharsky-bw
bocharsky-bw / oop.js
Last active August 29, 2015 13:57
Create class with object constructor and public/private properties and methods.
function MyClass(publicVal, privateVal) {
var self = this;
/**
* Public Property
*/
this.publicValue = publicVal;
@bocharsky-bw
bocharsky-bw / bw-timer.js
Last active August 29, 2015 13:57
Count down timer in seconds
function BWTimer(_delay, _step) {
var self = this;
/**
* Delay in seconds
*/
var delay = _delay;
/**
@bocharsky-bw
bocharsky-bw / to-top-button.html
Created April 21, 2014 19:22
To top button on JavaScript with jQuery library
<a id="bw_to_top" href="#top" style="
position: fixed;
left: 20px;
bottom: 20px;
display: block;
opacity: 0;
" title="To top">To top</a>
<script type="text/javascript">
var obj = $('#bw_to_top'); // object of to_top button
@bocharsky-bw
bocharsky-bw / display-all-errors.php
Last active August 29, 2015 14:00
Display all errors for debug in production
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);