Skip to content

Instantly share code, notes, and snippets.

View kricore's full-sized avatar

Krikor Boghossian kricore

  • Greece
View GitHub Profile
@acdlite
acdlite / app.js
Last active January 20, 2023 08:23
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@mayeenulislam
mayeenulislam / WP: post_is_in_descendant_category
Last active December 4, 2016 16:25
WordPress: post_is_in_descendant_category function (Source: Codex)
<?php
/**
* Tests if any of a post's assigned categories are descendants of target categories
*
* @param int|array $cats The target categories. Integer ID or array of integer IDs
* @param int|object $_post The post. Omit to test the current post in the Loop or main query
* @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
* @see get_term_by() You can get a category by name or slug, then pass ID to this function
* @uses get_term_children() Passes $cats
* @uses in_category() Passes $_post (can be empty)
@andfinally
andfinally / .htaccess
Last active November 23, 2020 02:01
Barebones Backbone Router example for an Apache site with a local URL like http://local5/backbone-router.
# html5 pushstate (history) support:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L,QSA]
</ifModule>
@nternetinspired
nternetinspired / gist:7482445
Last active February 24, 2022 17:20
Load Disqus comments only on demand if you give a shit about page weight and your visitors. Even with no comments, i.e. an empty comment form, calling Disqus will load an extra 226Kb. If your page has comments this can be far higher. This Gist accompanies my blog post: http://internet-inspired.com/wrote/load-disqus-on-demand/
// Requires jQuery of course.
$(document).ready(function() {
$('.show-comments').on('click', function(){
var disqus_shortname = 'YOUR-DISQUS-USERNAME'; // Replace this value with *your* username.
// ajax request to load the disqus javascript
$.ajax({
type: "GET",
url: "http://" + disqus_shortname + ".disqus.com/embed.js",
dataType: "script",
@AndersDJohnson
AndersDJohnson / setIntervalSynchronous.js
Last active March 28, 2023 09:17
A synchronous version of setInterval (functional form). Waits for the interval function to finish before starting the timeout to the next call.
var setIntervalSynchronous = function (func, delay) {
var intervalFunction, timeoutId, clear;
// Call to clear the interval.
clear = function () {
clearTimeout(timeoutId);
};
intervalFunction = function () {
func();
timeoutId = setTimeout(intervalFunction, delay);
}
@banago
banago / get-fisrt-paragraph.php
Created November 6, 2012 09:18
Get first paragraph from a WordPress post.
<?php
/**
* Get first paragraph from a WordPress post. Use inside the Loop.
*
* @return string
*/
function get_first_paragraph(){
global $post;
$str = wpautop( get_the_content() );