Skip to content

Instantly share code, notes, and snippets.

View kpion's full-sized avatar

Konrad Papała kpion

View GitHub Profile
<?php
/**
It's about a different way of passing params to an sql query. Yes, still using PDO behind the scenes.
*/
///////////////////////////
//The standard way of passing params:
$stmt = $dbh->prepare("INSERT INTO some_table (first_name, last_name) VALUES (?, ?)");
$stmt->bindValue(1, $_GET['first_name']);
@kpion
kpion / phpdoc-var-type.php
Last active February 10, 2017 12:47
Why would we want to type hint variables via php doc
<?php
/**
Here is an example of type hinting variables (not function parameters), using php doc.
There is only one reason for doing this - to let IDEs know what is what.
*/
class X{
public function blahx(){
echo 'blahx';
}
<?php
/**
* Disclaimer - I am aware using __call to set things isn't anything new, once upon a time, I created an ORM class doing that, but this
* time I'd like to ask about using this approach actually everytime we need accessors like set/get.
*
* OK, so using accessors is a good practice. But quite boring, isn't it? Even with all this IDEs' support (menu code -> create accessors for me please).
*
* Why not use the __call magic method catching "get/set" methods?
*
Create two files:
PHP file get_image.php:
<?php
//you'll play with dirs / paths later
$file = 'some_image.png';
$type = 'image/png';
header('Content-Type:'.$type);
header('Content-Length: ' . filesize($file));
@kpion
kpion / test
Created February 22, 2017 04:12
adfadfadsf
How to get PHP errors to log/display
TL;DR:
Put/modify this in the php.ini file:
error_reporting = -1
display_errors = On
Long version:
bind ^S savefile main
bind ^F whereis main
bind F3 findnext main
#bind esc cancel main
bind ^X cut main
bind ^C copytext main
bind ^V uncut main
df -h /dev/sdc1
Filesystem Size Used Avail Use% Mounted on
/dev/sdc1 699G 692G 6,8G 100% /media/konrad/Elements
public function defaultMethod() {
lib::$view->assign("pageTemplate", $this->templateDir."cities.tpl");
$cityId = 2;
$defaultCityIds = '2, 3, 7, 12';
$cityIds = null;
if (isset($_GET['city']) && !empty($_GET['city'])) {
$cityId = $_GET['city'];
$cityIds = $_GET['city'];
}else{
@kpion
kpion / remove-tab-bar-firefox
Created November 16, 2017 15:05
How to remove tab bar in Firefox
# when you installed the Tree Style Tab in your Firefox Quantum or any newer,
# you don't need the FX's Tab Bar anymore, therefore:
1. Click help -> Troubleshooting Information -> next to "Profile Directory " click "Open Directory".
(if you can't see the menu, click the "wrench" icon on the right, then Help and Troubleshooting Information )
2. Create (if not exists) a "chrome" directory
3. Create (if not exists) "userChrome.css" file and edit it