Skip to content

Instantly share code, notes, and snippets.

@yusufhm
yusufhm / regex.php
Last active December 29, 2017 17:38
php regex
<?php
// YouTube id from url.
// @see http://stackoverflow.com/a/6382259/351590
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
$video_id = $match[2];
}
@yusufhm
yusufhm / d8-show-config.php
Created April 11, 2016 06:30
Drupal 8 various Field & Entity (display) config
<?php
$entity_type = 'node';
$bundle = 'page';
$field_name = 'field_description';
$fsc = FieldStorageConfig::loadByName($entity_type, $field_name);
$fc = FieldConfig::loadByName($entity_type, $bundle, $field_name);
$display = entity_get_display($entity_type, $bundle, 'default');
$form_display = entity_get_form_display($entity_type, $bundle, 'default');
@yusufhm
yusufhm / fork-push-pull.md
Created April 11, 2016 01:12
Fork different push & pull remote URLs

Using different push & pull URLs for a forked git project

Start with source repo url

git remote -v

should give something like

origin git@github.com:/.git (fetch)

@yusufhm
yusufhm / disable-xdebug-composer.md
Last active June 7, 2017 17:26
Disable xdebug for composer in Homebrew
@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;
@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 / 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";'
.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 / 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
@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