Skip to content

Instantly share code, notes, and snippets.

View hsleonis's full-sized avatar
🏝️
Travellers unite.

Hasan Shahriar hsleonis

🏝️
Travellers unite.
View GitHub Profile
@hsleonis
hsleonis / wp-related-posts.php
Created February 3, 2017 05:23
WP Related Posts by Categories
@hsleonis
hsleonis / image-sizes-extd.php
Created January 24, 2017 18:29 — forked from franz-josef-kaiser/image-sizes-extd.php
Altering & handling default and custom wordpress image sizes and related stuff
<?php
defined( 'ABSPATH' ) OR exit;
add_action( 'init', array( 'oxoImageSizesExtd', 'init' ), 0 );
class oxoImageSizesExtd extends oxoImageSizes
{
/**
* The Class Object
* @var
@hsleonis
hsleonis / limit_admin_post_list_fields.php
Created January 24, 2017 18:19 — forked from franz-josef-kaiser/limit_admin_post_list_fields.php
Speed up the post list views in WordPress admin UI screens. Reduce the queried fields to what is needed to display the posts and what "Quick Edit" needs. Saved time increases with a higher limit set for `posts_per_screen` in the screen options drop down.
<?php
defined( 'ABSPATH' ) OR exit;
/**
* Plugin Name: (WCM) Faster Admin Post Lists
* Description: Reduces the queried fields inside WP_Query for WP_Post_List_Table screens
* Author: Franz Josef Kaiser <[email protected]>
* AuthorURL: http://unserkaiser.com
* License: MIT
*/
@hsleonis
hsleonis / wp-action-hook-arguments.php
Created January 19, 2017 08:44
WP pass arguments to action function
<?php
// Hook function with action
// add_action( hook_id, func_name, priority, number_of_arguments )
add_action('thesis_hook_before_post','recent_post_by_author',10,2);
function function_name ( $arg1, $arg2 ) {
/* do stuff here */
}
// At the place of action
@hsleonis
hsleonis / wp-post-gallery-html-modify.php
Created January 6, 2017 09:48
WP change default post gallery output
<?php
add_filter('post_gallery', 'my_post_gallery', 10, 2);
function my_post_gallery($output, $attr) {
global $post;
if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby'])
unset($attr['orderby']);
}
@hsleonis
hsleonis / flickr-feed.js
Created December 19, 2016 12:11
Purses flickr public feed from API
$.fn.flickr =
function(arr){
var wrapper = this;
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id="+arr.id+"&lang=en-us&format=json&jsoncallback=?", displayImages);
function displayImages(data)
{
// Choose where in the feed to start, 0 is latest
var iStart = 0;
@hsleonis
hsleonis / ssh-remove-files-folders.c
Created December 13, 2016 10:37
SSH commands to remove files and folders
/* The command in its simpliest form looks like: */
rm myFile.txt myFile1.txt myFile2.txt …etc…
/* Fortunately, rm accepts several arguments which can ease us.
In the above example, we could type: */
rm myFile*.txt
/* This will match all files starting with ‘myFile’ and ending in ‘.txt’ */
/* To delete a whole folder and its content recursively, you can use: */
rm -rf foldername/
@hsleonis
hsleonis / css-wildcard-class.css
Created December 12, 2016 07:02
Wildcard * in CSS for classes
div[class^="tocolor-"], div[class*=" tocolor-"] {
color:red
}
/*
In the place of div you can add any element or remove it altogether,
and in the place of class you can add any attribute of the specified element.
[class^="tocolor-"] — starts with "tocolor-".
[class*=" tocolor-"] — contains the substring "tocolor-" occurring directly after a space character.
@hsleonis
hsleonis / golang-simple-clouser.go
Created October 26, 2016 09:55
Simple closure with GoLang
package main
import "fmt"
func name(s string, m int) func(int) (int, string) {
sum := len(s)+m
return func(x int) (int, string) {
sum += x
var val string
if val="even"; sum%2==1 {
@hsleonis
hsleonis / golang-word-counter.go
Created October 26, 2016 09:04
Counts number of each word in a string
import (
_ "fmt"
"strings"
)
func WordCount(s string) map[string]int {
word:=make(map[string]int)
m:=strings.Fields(s)
for _,w:=range m{