Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / collectd-metrics-dashboard.json
Created November 10, 2014 05:01
collectd metrics dashboard for Kibana
{
"title": "Metrics",
"services": {
"query": {
"list": {
"0": {
"query": "collectd_type = \"memory\" and type_instance = \"used\"",
"alias": "Used",
"color": "#EF843C",
"id": 0,
@yusufhm
yusufhm / file-by-type-size.sh
Created August 23, 2016 23:30
List file by type & size
#!/bin/bash
ftypes=$(find . -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq)
for ft in $ftypes
do
echo -n "$ft "
find . -name "*${ft}" -exec ls -l {} \; | awk '{total += $5} END {print total}'
done
@yusufhm
yusufhm / ssh_config
Last active August 30, 2016 08:31
SSH Tunnel
Host some-name
Hostname server-address(ip or hostname)
User username
ForwardAgent yes
# The first parameter is the port which you will access from
# your local computer. The second is the IP & Port on the remote
# server that you want to access
LocalForward 8085 127.0.0.1:80
@yusufhm
yusufhm / get-domain-info.md
Created September 15, 2016 02:16
Find domain information.

nslookup -type=soa domain.name

dig +short NS domain.name

@yusufhm
yusufhm / logstash-ossec-alerts.conf
Last active May 22, 2017 16:54
Logstash configuration for reading OSSEC alerts files and send to Elasticsearch (credits to https://mig5.net)
input {
file {
type => "ossec"
path => "/var/ossec/logs/alerts/alerts.log"
sincedb_path => "/opt/logstash/"
codec => multiline {
pattern => "^\*\*"
negate => true
what => "previous"
}
@yusufhm
yusufhm / disable-xdebug-composer.md
Last active June 7, 2017 17:26
Disable xdebug for composer in Homebrew
@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