Skip to content

Instantly share code, notes, and snippets.

View BR0kEN-'s full-sized avatar
Coding... A lot.

Sergii Bondarenko BR0kEN-

Coding... A lot.
View GitHub Profile
BR0kEN- /
Created February 19, 2022 00:37
macOS: Enable Touch ID in CLI after reboot

Many of those who have enabled Touch ID for Terminal/iTerm found out that the /etc/pam.d/sudo is reverted to its original state after reboot.

Setting the permission to edit the file, adding a necessary line, and reverting the permission back are all trivial operations that can be automated.

If you are a bash user, add these lines to your .bash_profile:

ensure_touch_id() {
    local AUTH_FILE_PATH="/etc/pam.d/sudo"
    local AUTH_FILE_LINES=()
BR0kEN- / guzzle_gzip_unpack.php
Created March 3, 2021 12:13
Guzzle unarchive Gzip on the fly (without storing an archive on disk)
// Requirements:
// - ext-zlib
// - guzzlehttp/guzzle
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
### Keybase proof
I hereby claim:
* I am br0ken- on github.
* I am br0ken ( on keybase.
* I have a public key ASDVn9CNGI5gGbGUT2Xd1-FYZX4xR3HlGPYOTWjLPsdOQAo
To claim this, I am signing this object:
BR0kEN- /
Last active July 14, 2017 09:39
Flush Memcache or only prefixed entries from a command line
#!/usr/bin/env bash
MEMCACHE_PID=$(\pgrep -f memcache)
if [ -n "${MEMCACHE_PID}" ]; then
# @todo Do we have an ability to use passwordless "sudo"?
DATA=$(\sudo \netstat -plunt | \grep "${MEMCACHE_PID}" | \awk '{print $4}' | \head -n1)
BR0kEN- / vagrant.log
Created May 23, 2017 15:11
[Windows] "Vagrant::Util::Platform.windows_admin" hangs forever
INFO global: Vagrant version: 1.9.5
INFO global: Ruby version: 2.2.5
INFO global: RubyGems version:
INFO global: VAGRANT_EXECUTABLE="C:\\HashiCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-1.9.5\\bin\\vagrant"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="C:\\HashiCorp\\Vagrant\\embedded"
INFO global: VAGRANT_LOG="debug"
INFO global: VAGRANT_OLD_ENV_="C:=C:\\cygwin64\\bin"
BR0kEN- / Vagrantfile
Created April 7, 2017 23:48
Check VM state in Vagrantfile
VagrantEnv =
if "running" == (VagrantEnv.machine_index.find{|machine| machine.vagrantfile_path == VagrantEnv.cwd}).state
puts "Machine is running!"
BR0kEN- / MODULE.module
Last active November 25, 2016 15:57
Drupal 8: validate entity field if value changed (PHP 7).
* Implements hook_entity_type_alter().
function MODULE_entity_type_alter(array &$entity_types) {
/* @var \Drupal\Core\Entity\ContentEntityType $entity_user */
$entity_user = $entity_types['user'];
$entity_user->setFormClass('default', \Drupal\MODULE\Entity\User\Form\ProfileForm::class);
#!/usr/bin/env bash
# Move contents from this subdirectory into root directory of a repository.
# - Any relative directory could be as a value.
# - Pass "--default" to keep this value and affect on the next.
# Commit moved content in this branch.
# - Any name can be specified. Branch will be created.
# - Pass "--default" to keep this value and affect on the next.
BR0kEN- / repostat
Last active August 11, 2019 22:37
Per-user repository statistic (commits, additions and deletions counter)
#!/usr/bin/env bash
set -e
# Show help.
if [ "help" == "$BRANCH" ]; then
echo "$0 BRANCH"
BR0kEN- /
Created June 8, 2015 11:25
Bash implementation of strpos and substr functions from PHP library
#!/usr/bin/env bash
# @param string $1
# Input string.
# @param int $2
# Cut an amount of characters from left side of string.
# @param int [$3]
# Leave an amount of characters in the truncated string.