Skip to content

Instantly share code, notes, and snippets.

View martinsotirov's full-sized avatar

Martin Sotirov martinsotirov

View GitHub Profile
@martinsotirov
martinsotirov / bash_helpers.sh
Last active May 25, 2021 12:19
Bash Helpers
// batch-change file extension of multiple files
// change mv to git mv to retain git history
find . -name "*.css" -exec bash -c 'mv "$1" "${1%.css}".scss' - '{}' \;
// get summed file size of all files from type
find . -name "*.css" | xargs du -sch
@martinsotirov
martinsotirov / prefetch.directive.ts
Created May 24, 2021 11:52
Prefetch Angular Content
/**
* Kudos to https://timdeschryver.dev/blog/making-your-application-feel-faster-by-prefetching-data-with-ngrx
*/
@Directive({
selector: '[prefetch]',
})
export class PrefetchDirective implements OnInit, AfterViewInit, OnDestroy {
@Input()
prefetchMode: ('load' | 'hover' | 'visible')[] = ['visible']

Keybase proof

I hereby claim:

  • I am martinsotirov on github.
  • I am martinsotirov (https://keybase.io/martinsotirov) on keybase.
  • I have a public key ASDKnS8MMqzWl9D55dCVsTPZ0kZVgwYpWIsn1-oY7Y5tZAo

To claim this, I am signing this object:

@martinsotirov
martinsotirov / functions.php
Created October 20, 2016 12:48
WPML - REST API
/**
* Handle WPML REST requests
*/
add_action('rest_api_init', function() {
if (isset($_REQUEST['lang']) && !empty($_REQUEST['lang'])) {
global $sitepress;
$availableLangs = array_keys(apply_filters('wpml_active_languages', []));
$currentLang = get_query_var('lang');
$newLang = sanitize_text_field($_REQUEST['lang']);
@martinsotirov
martinsotirov / install_ssh2_php7.sh
Created July 8, 2016 11:12
Builds and installs the ssh2 extension for php 7
#!/bin/bash
echo "Installing prerequisites"
apt-get install libssh2-1 libssh2-1-dev -y &>/dev/null
echo "Downloading pecl-networking-ssh2"
wget https://github.com/php/pecl-networking-ssh2/archive/master.zip &>/dev/null
echo "Installing pecl-networking-ssh2"
unzip master.zip &>/dev/null
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:50m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
server {
location / {
try_files $uri $uri/ /index.php?$args;
}
apt-get install git nginx-extras python-software-properties build-essential php5-common php5-dev php5-cli php5-fpm curl php5-curl php5-gd php5-mcrypt php5-mysql -y