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 / detect.php
Last active November 14, 2017 12:57
[Detect city] detect russian and ukrainian cities in text #php
// Usage: detectCity("Я живу в Москве"); // return "Москва"
function detectCity($text)
{
$cities = [
// Россия
// Миллионники
'Москва' => ['моск', 'msk', 'moskva', 'moscow', 'столица'],
'Санкт-Петербург' => ['петербург', 'peterburg', 'petersburg'],
'Волгоград' => ['волгоград', 'volgograd'],
@Bizunow
Bizunow / fw.js
Created November 10, 2017 21:01
[NodeJS File Module] NodeJS file read/write async #js #nodejs
// Usage:
// await Files.write('test.json', JSON.stringify(data));
const fs = require('fs');
class Files {
static write(fname, data) {
return new Promise((resolve, reject) => {
fs.writeFile(`./${fname}`, data, (err) => {
if (err) {
@Bizunow
Bizunow / override.sh
Created October 27, 2017 10:24
[Override package (BREW)] #script
# To force the link and overwrite all conflicting files:
brew link --overwrite node
@Bizunow
Bizunow / php_ext_dir.sh
Last active January 9, 2018 11:54
[PHP extensions dir] Get PHP extensions directory #php #bash #script #shell
php --ini | grep "extension_dir"
@Bizunow
Bizunow / php_config.sh
Last active January 9, 2018 11:54
[PHP config path] get path of loaded PHP configuration file #php #bash #script #shell
php --ini | grep "Loaded Configuration File"
@Bizunow
Bizunow / array_deep_column.php
Last active October 25, 2017 09:31
[PHP array_deep_column] array column for array of objects #php
// array_deep_column($wallData->items, 'likes.count');
function array_deep_column($array, $path)
{
$currentArray = $array;
$path = explode('.', $path);
foreach ($path as $sub) {
if (is_object($currentArray)) {
$currentArray = get_object_vars($currentArray);
}
@Bizunow
Bizunow / masonry.css
Created September 26, 2017 09:54
[CSS Masonry] #css #html
.masonry {
column-count: 3;
column-gap: 1em;
}
.masonry .item {
background-color: #eee;
display: inline-block;
margin: 0 0 1em;
width: 100%;
@Bizunow
Bizunow / duck.js
Last active September 26, 2017 12:25
[React-Redux duck module] #js #react #redux
// Actions
const ACTION_1 = "my-app/social/ACTION_1";
// Dispatchers
export const dispatcher_1 = (data) => {
return (dispatch, getState) => {
dispatch({ type: ACTION_1, payload: data });
};
};
@Bizunow
Bizunow / yii_get_post.php
Last active September 15, 2017 14:56
[Yii GET/POST param] #php #yii
// Yii 1
Yii::app()->request->getParam('q');
// Yii 2?
Yii::$app->request->post('var');
Yii::$app->request->get('var');
@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
]);