Skip to content

Instantly share code, notes, and snippets.

@lebedevsergey
lebedevsergey / gist:89e33af49099e87ee17cdfb26ab8780c
Created March 17, 2026 12:32
Bash one-liner to purge all untracked Git files with confirmation
read -p "Purge all untracked Git files? " -n 1 && [[ $REPLY =~ ^[Yy]$ ]] && git stash save -u && git stash drop "stash@{0}"
@lebedevsergey
lebedevsergey / gist:851453e66af2b3f99c9698d2074f2af0
Created February 27, 2026 07:54
Bash alias to show all commands/targets in makefile.
# when investigationg an existing project that uses makefiles it is very useful to lookup all its commands/targets
# this bash alias does exactly that when run in makefile containing directory
# the script taken from here https://unix.stackexchange.com/questions/230047/how-to-list-all-targets-in-make
# and fixed a bit to use it in the alias
alias mkshowall="make -npq : 2> /dev/null | awk -v RS= -F: '\$1 ~ /^[^#%.]+$/ { print \$1 }'"
@lebedevsergey
lebedevsergey / gist:5b73e0e9e281d47a30d72d69b6de7d2a
Created April 13, 2022 12:51
Laravel app debuggin - logging all SQL-queries
// When debugging Laravel application
// just add this code somewhere in AppServiceProvider::boot()
// and it will log all SQL-queries in file "query.log"
$file = storage_path('query.log');
if (file_exists($file)) {unlink($file);}
\Illuminate\Support\Facades\DB::listen(function($query) use ($file) {
\Illuminate\Support\Facades\File::append(
$file,
$query->sql . ' [' . json_encode($query->bindings) . ']' . PHP_EOL
@lebedevsergey
lebedevsergey / gist:4701a59107d98bb1bbb2055ea434a326
Created April 13, 2022 12:45
Workaround for PHP Laravel Mockery issue - mocking a class by alias persists even after Mockery::close() and affects remainder tests
/**
* When testing Laravel PHP code, sometimes it is necessary to mock object through alias,
* for example to override object static methods.
*
* It can be done like this:
* $this->mockSomeObject = $this->mock('alias:SomeObjectClassName');
* .
* Hovewer mocking a class in a such way persists even after Mockery::close() and could affects remainder tests.
* To overcome this, just add these two annotations in each class where class is mocked by alias
*
@lebedevsergey
lebedevsergey / chromedriver_autodownloader
Last active January 14, 2021 09:52
Python 3 script that downloads the latest Chromedriver for Linux of version matching currently installed Chrome browser version
import os
import re
import requests
import zipfile
XML_INFO_URL = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE_'
DRIVER_PATH = 'https://chromedriver.storage.googleapis.com'
ZIPPED_DRIVER_FILE_NAME = 'chromedriver_linux64.zip'
UNZIPPED_DRIVER_FILE_NAME = 'chromedriver'
@lebedevsergey
lebedevsergey / facebook-image-real-url
Created March 27, 2018 11:47
How to get Facebook image real url from "fake" url returned by Facebook API
<?php
/**
* gets real image urls in Facebook CDN from "fake" url that comes from Facebook API news feeds
* take in account that those real urls have embedded timestamp that makes them valid only temporarily
* @param type $imageFakeUrl - "fake" url from Facebook API output
* @return array with image info in multiple resolutions including theirs urls
* @throws UnexpectedValueException
*
* detailed description: being queried for content, Facebook API returns fake images urls
* that points to HTML page with this image and text description
@lebedevsergey
lebedevsergey / WordPress API v2 image upload from media endpoint with Guzzle
Created January 12, 2018 10:27
WordPress API v2 image upload from media endpoint with Guzzle
/*
* WP REST API version 2.0-beta7
* API base url ishttp://www.example.com/wp-json
*
* Reference
* https://developer.wordpress.org/rest-api/reference/media/
*
* Description
* an example of loading image to WordPress API using Guzzle
* inspired by s-hiroshi's gist at https://gist.github.com/s-hiroshi/3477e07454d809b9d38f
@lebedevsergey
lebedevsergey / tabs_undefined_useUrlFragment_issue
Last active September 28, 2017 16:38
Minimal code to show vue-tabs-component_component undefined useUrlFragment_issue
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.4/vue.js"></script>
</head>
<body>
<div id='vue-app'>
<tabs>
<tab name="First tab">
This is the content of the first tab
</tab>