Skip to content

Instantly share code, notes, and snippets.

View jimmy89Li's full-sized avatar

Li jimmy89Li

View GitHub Profile
<!-- 32x32 favicon.ico file for legacy browsers. -->
<link rel="icon" href="/favicon.ico">
<!-- A single SVG icon with light/dark version for modern browsers. -->
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<!-- 180×180 PNG image for Apple devices. -->
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<!-- Web app manifest with 192×192 and 512×512 PNG icons for Android devices. -->
@jimmy89Li
jimmy89Li / fibonacci.js
Created March 30, 2019 11:20
JavaScript fibonacci function
function fib(num) {
if(num <= 1) {
return 1;
} else {
return fib(num - 1) + fib(num - 2);
}
}
console.log(fib(4)); // 5
console.log(fib(10)); // 89
@jimmy89Li
jimmy89Li / sortObjects.js
Created March 30, 2019 11:14
Sort objects by key
const list = [
{ key: 7, val: "amazon" },
{ key: 3, val: "msn" },
{ key: 5, val: "github" },
{ key: 1, val: "google" },
{ key: 4, val: "stackoverflow" },
{ key: 6, val: "jsfiddle" },
{ key: 2, val: "yahoo" },
{ key: 8, val: "ebay" }
];
@jimmy89Li
jimmy89Li / sortObjects.js
Created March 30, 2019 11:14
Sort objects by value
const list = [
{ key: 7, val: "amazon" },
{ key: 3, val: "msn" },
{ key: 5, val: "github" },
{ key: 1, val: "google" },
{ key: 4, val: "stackoverflow" },
{ key: 6, val: "jsfiddle" },
{ key: 2, val: "yahoo" },
{ key: 8, val: "ebay" }
];
@jimmy89Li
jimmy89Li / fibonacci.php
Last active February 20, 2019 17:55
Fibonacci sequence (0 omitted)
function fibonacci($n)
{
//$fib = [0,1] // use this if you don't want to omit '0'
$fib = [1,1];
for($i=1;$i<$n;$i++)
{
$fib[] = $fib[$i]+$fib[$i-1];
}
//print_r($fib);
echo $fib[$n];
@jimmy89Li
jimmy89Li / functions.php
Last active May 3, 2018 12:38
WordPress TinyMCE customizing
<?php
// Custom font format button
add_filter( 'mce_buttons', 'my_mce_buttons' );
function my_mce_buttons( $buttons ) {
array_unshift( $buttons, 'styleselect' ); // Add custom format selector
$remove = 'formatselect'; if ( ( $key = array_search( $remove, $buttons ) ) !== false ) unset( $buttons[$key] ); // Remove default format selector
return $buttons;
}
// Custom font styles
@jimmy89Li
jimmy89Li / functions.php
Created December 12, 2017 11:08
Display medium size images without srcset in WordPress
<?php
// Add support for cropping default WordPress medium images
if(!get_option("medium_crop")) {
add_option("medium_crop", "1");
} else {
update_option("medium_crop", "1");
}
update_option( 'medium_size_w', 200 );
update_option( 'medium_size_h', 300 );
@jimmy89Li
jimmy89Li / top.php
Created November 30, 2017 14:00
WP nav menu excluding pages with specific template
<nav class="navmenu">
<?php
$args = array( 'post_type' => 'page', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array( array( 'key' => '_wp_page_template', 'value' => 'page-gallery.php', 'compare' => '=', ) ), );
$pages_to_exclude = new WP_Query( $args );
wp_page_menu( array( 'before' => '<ul class="sf-menu">', 'sort_column' => 'menu_order, ID', 'menu_class' => 'primary-menu', 'exclude' => implode( ',', $pages_to_exclude->posts ), ) );
?>
</nav>
@jimmy89Li
jimmy89Li / functions.php
Last active November 30, 2017 13:57
Remove custom submenu pages
// You need to find out the parent menu slug, used when added the submenu:
// add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
// Replace those next
function remove_submenu() {
remove_submenu_page( '$parent_slug', '$menu_slug' );
}
add_action( 'admin_menu', 'remove_submenu', 999 );
@jimmy89Li
jimmy89Li / web.config
Created August 11, 2017 09:14
Microsoft Server IIS - Wordpress Upload Limit (Set upload limit to 120M)
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="120000000" />
</requestFiltering>
</security>
</system.webServer>
</configuration>