Skip to content

Instantly share code, notes, and snippets.

View mityukov's full-sized avatar

Vladimir Mityukov mityukov

  • Individual Entrepreneur
  • Ulyanovsk, Russia
  • X @pilat
View GitHub Profile
@mityukov
mityukov / PlayPauseVkYa
Last active August 29, 2015 14:06
VK/YandexMusic remote control
# This is AppleScript to play/pause player in VK.com or in Music.Yandex.ru
# Make it a Service (via Automator) and assign shortkey to call it.
#
# Look here: https://www.evernote.com/shard/s40/sh/a77fd23b-47f0-4b8d-a18f-6cea2c6dd4c4/389e1fe1622daff105433f75158bdd0d
#
# TODO: find a way to assign use <Play/Pause> key on keyboard to this shortcut
# + even better, if it would also listen to <Play/Pause> on my headphones cord (like iTunes)
#
# (c) Vladimir Mityukov, 2014
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<ul>
<li class="list-item">Item #1</li>
@mityukov
mityukov / date_helpers.js
Created February 2, 2016 18:11
JavaScript: Date() helpers + paddingLeft()
/**
* Pads string or number with symbols
* @param {string} paddingValue Padding string. E.g., "0000"
* @return {string} E.g., "0032"
*/
String.prototype.paddingLeft = function (paddingValue)
{
return String(paddingValue + this).slice(-paddingValue.length);
};
/**
@mityukov
mityukov / findElementContains.js
Created February 2, 2016 18:25
JavaScript: findElementContains(elmName, needle) -- a function, allowing to find the deepest HTML element of given tag name, containing the text node with given text
function findElementContains(elmName, needle) {
var foundTextNode = null;
var allElms = document.querySelectorAll("*");
for (var i=0; i < allElms.length; i++) {
var allChildren = allElms[i].childNodes;
for (var j=0; j < allChildren.length; j++) {
if (allChildren[j].nodeType == 3 && allChildren[j].nodeValue.indexOf(needle) > -1) { // text node
foundTextNode = allChildren[j];
break;
@mityukov
mityukov / substr_in_array.js
Created February 16, 2016 10:50
Check string has any of array's values in it
function substr_in_array(arr, str)
{
return arr.some( function(v) { return str.indexOf(v) >= 0; } );
}
@mityukov
mityukov / queue_ensure.sh
Last active November 21, 2018 07:57
Superviser replacement for shared hosting (Laravel queues)
# just put the following command to crontab. Let say, every 5 minutes:
flock -xn /tmp/laravel_queues.lockfile -c "/usr/bin/php /path/to/laravel/artisan queue:listen"
class ActivityRepositoryEloquent extends BaseRepository implements ActivityRepository
{
// ...
public function insertMany($records)
{
$searchFields = [
'subdomain',
'element_type',
'element_id',
// ==UserScript==
// @name Search site with google
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Kotique
// @match *food4vita.ru*
// @grant none
// ==/UserScript==
@mityukov
mityukov / helpers.php
Last active January 13, 2018 03:18
array_undot() helper functon
<?php
function array_undot($dottedArray, $initialArray = [])
{
// to make it recursive:
$dottedArray = array_dot($dottedArray);
foreach ($dottedArray as $key => $value) {
array_set($initialArray, $key, $value);
}
@mityukov
mityukov / helpers.php
Created January 23, 2018 09:53
Helpers to work with date in Laravel
<?php
function carbon($dateTime = null)
{
if (is_null($dateTime)) {
return \Carbon\Carbon::now();
}
if (is_numeric($dateTime)) { // timestamp is passed:
return \Carbon\Carbon::createFromTimestamp($dateTime);