Skip to content

Instantly share code, notes, and snippets.

🐦
fly like a bird ...

Kcko

View GitHub Profile
View random-number-between.sql
-- For range (min..max( (min inclusive, max exclusive) it is:
FLOOR( RAND() * (max-min) + min )
-- For range (min..max) (min+max inclusive) it is:
FLOOR( RAND() * (max-min+1) + min )
View johny-ex.php
<?php
// For each flag, assign a power of two
// This makes a mask with a single bit turned on
$male = 1;
$bald = 2;
$tall = 4;
$funny = 8;
$fictitious = 16;
View permission.php
<?php
class Permissions {
const ADD_CONTENT = 0x1;
const ADD_OWN_CONTENT = 0x2;
const EDIT_CONTENT = 0x4;
const EDIT_OWN_CONTENT = 0x8;
const DELETE_CONTENT = 0x10;
@Kcko
Kcko / bitwise-permission-checking.php
Created Mar 22, 2019 — forked from phnah/bitwise-permission-checking.php
Check permission using bitwise operators
View bitwise-permission-checking.php
Initially, I found bitmasking to be a confusing concept and found no use for it. So I've whipped up this code snippet in case anyone else is confused:
<?php
// The various details a vehicle can have
$hasFourWheels = 1;
$hasTwoWheels = 2;
$hasDoors = 4;
$hasRedColour = 8;
@Kcko
Kcko / headings.scss
Last active Mar 8, 2019 — forked from paramburu/headings.scss
Sass recursive headings function (h1, h2, h3...)
View headings.scss
// orig source: https://guwii.com/bytes/sass-function-loop-headings-h1h2h3h4h5h6/
@function headings($from:1, $to:6) {
@if $from == $to {
@return 'h#{$from}';
} @else {
@return 'h#{$from},' + headings($from+1, $to);
}
}
View submitted-by.php
<?php
if ($form['submit']->isSubmittedBy()) {
// ...
}
or
if ($form->isSubmitted() === $form['submit']) {
// ...
}
View curl-php-auth.php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
View php-auth.php
<?php
if (empty($_SERVER['PHP_AUTH_USER']) ||
$_SERVER['PHP_AUTH_USER'] != "login" ||
$_SERVER['PHP_AUTH_PW'] != "pass") {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo 'Zde nemáte přístup bez jména a hesla';
exit;
}
View gistApi.php
<?php
class GistEdit {
private $data;
private static $_instance = NULL ;
public static function init () {
if (self::$_instance === NULL) {
You can’t perform that action at this time.