Skip to content

Instantly share code, notes, and snippets.

@gmarokov
gmarokov / wp-exerpt.php
Last active October 22, 2019 06:48
Modify excerpt to use limit of characters
//Modify excerpt to use limit of characters
function get_excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
@gmarokov
gmarokov / wp-breadcrumbs.php
Last active October 22, 2019 06:49
Generate breadcrumbs
<?php
/**
* Generate breadcrumbs
*/
//TODO Translation ready strings
function get_breadcrumb() {
echo '<a href="'.home_url().'" rel="nofollow">Home</a>';
if (is_category() || is_single()) {
@gmarokov
gmarokov / jquery-sticky-sidebar.js
Last active October 22, 2019 06:50
JQuery sticky sidebar
var stickySidebar = $('.sticky');
if (stickySidebar.length > 0) {
var stickyHeight = stickySidebar.height(),
sidebarTop = stickySidebar.offset().top;
}
// on scroll move the sidebar
$(window).scroll(function () {
if (stickySidebar.length > 0) {
@gmarokov
gmarokov / .vimrc
Created January 8, 2019 11:49
Vim configuraton
set numbers
@gmarokov
gmarokov / git-hook-post-merge
Last active October 22, 2019 06:51
ASP.NET post merge git hook for displaying available migrations
#!/usr/bin/env bash
changed_files="$(git diff ORIG_HEAD HEAD --name-only | grep "/Migrations/")" [[ ! -z $changed_files ]] && echo -e "\e[91mIncoming Migrations!\e[39m $changed_files"
@gmarokov
gmarokov / git-aliases
Last active October 22, 2019 06:51
Git alias for displaying migration files for ASP.NET projets
git config --global alias.migrations 'log -- **/Migrations/**/*.cs'
@gmarokov
gmarokov / github-api-repo-search.php
Last active October 22, 2019 06:53
Search repos on GitHub by given search string
<?php
$searchTerm = 'mail';
$language = 'php';
$reposPerPage = 100;
$repoUrls = array();
$page = 1;
// Start paging
using System;
namespace TaxCalculator
{
class TaxCalculator
{
static void Main(string[] args)
{
int salary;
@gmarokov
gmarokov / url-snippets.php
Last active October 22, 2019 06:57
PHP snippets for URLs
//Get host name from URL
preg_match('@^(?:https?://)?([^/]+)@i',
"http://www.php.net/index.html", $matches);
$host = $matches[1];
//Get last two segments of host name
preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";
//Check for valid domain
@gmarokov
gmarokov / update-wp-old-hostname.sql
Last active October 22, 2019 06:57
Update old hostname WP query
UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://olddomain.com','http://newdomain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');