Skip to content

Instantly share code, notes, and snippets.

View nicklasos's full-sized avatar
💭
😅

Olkhovyk Mykyta nicklasos

💭
😅
View GitHub Profile
@nicklasos
nicklasos / timeelapsed.php
Last active January 1, 2016 18:09
Time elapsed
<?php
/**
* Inline profiler :)
*
* $time = s();
* for ($i = 0; $i < 100000; $i++) {
* $j = $i + 1;
* }
* s($time);
@nicklasos
nicklasos / scroll.js
Last active January 4, 2016 02:49
Simple endless scroll
var page = {
scrollAvailable: true,
currentPage: 0,
init: function() {
var _this = this;
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height() /* - 10 */) {
_this.scroll();
}
});
@nicklasos
nicklasos / scale.js
Created January 29, 2014 09:08
iPad, iPod and iPhone initial scale
(function(doc) {
var viewport = document.getElementById('viewport');
if ( navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
doc.getElementById("viewport").setAttribute("content", "width=1024,initial-scale=0.469");
} else if ( navigator.userAgent.match(/iPad/i) ) {
doc.getElementById("viewport").setAttribute("content", "initial-scale=1.0");
}
}(document));
@nicklasos
nicklasos / typehint.php
Created January 29, 2014 10:28
PHP Type hinting
<?php
define('TYPEHINT_PCRE', '/^Argument (\d)+ passed to (?:(\w+)::)?(\w+)\(\) must be an instance of (\w+), (\w+) given/');
class TypeHintException extends Exception {}
class TypeHint
{
private static $Typehints = array(
@nicklasos
nicklasos / dateformat.js
Last active August 29, 2015 13:55
So fucking JavaScript. Number format
function dateFormat(daysAgo) {
var d = new Date();
daysAgo = daysAgo || 0;
d.setDate(d.getDate() - daysAgo);
var date = d.getDate(),
month = d.getMonth() + 1,
year = d.getFullYear();
@nicklasos
nicklasos / ip.php
Created March 12, 2014 09:38
Get client ip
<?php
function get_client_ip()
{
if (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
} else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else if (isset($_SERVER['HTTP_X_FORWARDED'])) {
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
@nicklasos
nicklasos / db.php
Last active June 15, 2016 09:22
PHP db mysql
<?php
use PDO;
use PDOStatement;
/**
* Class Db
* Small helper for working with native PDO
*
* $pdo = new Db(new \PDO(
<?php
/*
* Convert seconds to human readable text.
* Found at: http://csl.sublevel3.org/php-secs-to-human-text/
*
*/
function secs_to_h($secs)
{
$units = [
@nicklasos
nicklasos / curl.php
Last active April 19, 2016 11:05
Curl
<?php
namespace App\Utils;
/**
* Simple curl wrapper
* @package Plariumed\Utils
*
* $curl = new Curl('http://localhost/api');
* $curl
* ->set(CURLOPT_USERPWD, 'appKey:appSecret')
@nicklasos
nicklasos / csv_to_array.php
Created April 24, 2014 11:50
CSV to array
<?php
function csv_to_array($filename, $delimiter = ',')
{
if (!file_exists($filename) || !is_readable($filename)) {
return false;
}
$header = null;
$data = [];