Skip to content

Instantly share code, notes, and snippets.

@yusufhm
yusufhm / git.sh
Last active February 18, 2019 00:58
git commands
# ignore local changes to the .gitconfig file
git update-index --skip-worktree .gitconfig
# list skipped files
git ls-files -v | grep ^S
# revert the above
git update-index --no-skip-worktree .gitconfig
@yusufhm
yusufhm / add_to_known_hosts.sh
Created October 1, 2015 23:17
automatically add host key to known_hosts
#!/bin/bash
host=$1
# first remove the host's key if it exists
ssh-keygen -R $host
# then add to the known_hosts file
ssh-keyscan -H $host >> ~/.ssh/known_hosts
@yusufhm
yusufhm / add_remote.sh
Created October 1, 2015 23:40
Add git remote if it does not exist
#!/bin/bash
$remote_name=$1
$remote_url=$2
git ls-remote --exit-code $remote_name &>/dev/null
if [ $? -ne 0 ]; then
git remote add $remote_name $remote_url
fi
@yusufhm
yusufhm / rename_drupal_module.sh
Last active November 23, 2015 03:40
Rename Drupal modules
#!/bin/sh
# Copied from http://whaaat.com/rename-drupal-module-cli
old=$1
new=$2
mv $old $new
cd $new
rename "s/$old/$new/g;" *
perl -pi -w -e "s/$old/$new/g;" *
@yusufhm
yusufhm / ubuntu-set-up-user-sudo-no-pass.sh
Last active October 2, 2017 05:14
ubuntu set up user sudo without password
#!/bin/bash
adduser yusuf
usermod -aG sudo yusuf
echo 'yusuf ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/custom && chmod 0440 /etc/sudoers.d/custom
@yusufhm
yusufhm / ubuntu-set-au-repos.sh
Created December 30, 2015 05:54
ubuntu set au repos
#!/bin/bash
sed -i 's/archive.ubuntu.com/au.archive.ubuntu.com/g' /etc/apt/sources.list
.parent-element {
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
@yusufhm
yusufhm / drush_commands.sh
Last active September 15, 2022 07:31
Drush commands
# THESE COMMANDS HAVE TO BE RUN FROM INSIDE AN EXISTING DOCROOT
# Get docroot path
drush st root --no-field-labels --format=list
# Generate Drupal Hash - Drupal 8
drush php:eval '$hash = Drupal\Component\Utility\Crypt::randomBytesBase64(55); print $hash . "\n";'
# Generate Drupal Hash - Drupal 7
drush php:eval '$hash = drupal_random_key(); print $hash . "\n";'
@yusufhm
yusufhm / create_directory_bookmark.sh
Last active March 1, 2016 23:32
Create directory bookmark in zsh
# Create a bookmark using the following command
hash -d -- bookmark_name=/path/to/dir
# Access using
cd ~bookmark_name
@yusufhm
yusufhm / resize-with-debounce.js
Created March 21, 2016 23:11
JS resize with debounce
// adding a debounce function in order to prevent the resize
// code from being called too often.
// @see http://stackoverflow.com/a/9828919
// @see https://davidwalsh.name/javascript-debounce-function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
var debounce = function (func, wait, immediate) {
var timeout;