Skip to content

Instantly share code, notes, and snippets.

View Bizunow's full-sized avatar

Ilya Bizunov Bizunow

  • Russia, Krasnodar
View GitHub Profile
@Bizunow
Bizunow / last_segment.js
Last active August 23, 2017 08:43
[Get URL last segment] #js
// getLastUrlSegment('https://vk.com/ibizunov') // return 'ibizunov'
function getLastUrlSegment(url) {
const parts = url.split('/');
return lastSegment = parts.pop() || parts.pop();
}
@Bizunow
Bizunow / url_param.js
Last active August 24, 2017 07:26
[Get URL parametr] #js
// getUrlParam('http://test.com?a=1', 'a') // return 1
function getUrlParam(urlString, param) {
const url = new URL(urlString);
return url.searchParams.get(param);
}
@Bizunow
Bizunow / nFormatter.js
Last active August 24, 2017 07:35
[JS number formater] #js
// From StackOverflow:
// https://stackoverflow.com/questions/9461621/how-to-format-a-number-as-2-5k-if-a-thousand-or-more-otherwise-900-in-javascrip
function nFormatter(num, digits) {
var si = [
{ value: 1E18, symbol: "E" },
{ value: 1E15, symbol: "P" },
{ value: 1E12, symbol: "T" },
{ value: 1E9, symbol: "G" },
{ value: 1E6, symbol: "M" },
@Bizunow
Bizunow / module.js
Created August 28, 2017 07:59
[ES6 Module-singleton] #js
const _data = [];
const UserStore = {
add: item => _data.push(item),
get: id => _data.find(d => d.id === id)
}
Object.freeze(UserStore);
export default UserStore;
@Bizunow
Bizunow / link.js
Created August 28, 2017 14:00
[Open link in new tab] #js
@Bizunow
Bizunow / fwrite.php
Created August 30, 2017 10:20
[PHP fwrite example] #php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, print_r($data, true));
fclose($myfile);
@Bizunow
Bizunow / link.css
Created August 30, 2017 12:18
[CSS link all props] #css
@Bizunow
Bizunow / allparams.js
Created August 31, 2017 11:48
[JS get all url params] #js
function allUrlParams(url) {
var url = decodeURIComponent(url);
var paramsPart = url.split('?')[1];
if (!paramsPart)
return {};
var params = paramsPart.split('&');
var pairs = {};
for (var i = 0; i < params.length; i++) {
@Bizunow
Bizunow / curl_helper.php
Last active September 15, 2017 12:49
[PHP Curl] Simple helper for create GET and POST requests. Always return JSON. #php
class CurlHelper
{
static function get($url, $params = [], $timeout = 60)
{
$paramsJoined = array();
foreach($params as $param => $value) {
$paramsJoined[] = "$param=$value";
}
@Bizunow
Bizunow / yii_command.php
Last active October 16, 2017 15:11
[Yii create command example] #php #yii
Yii::app()->db->createCommand('DELETE FROM table WHERE id = :id')->execute([
':id' => $item->user_id
]);
Yii::app()->db->createCommand('SELECT FROM table WHERE id = :id')->queryAll(true, [
':id' => $item->user_id
]);