Skip to content

Instantly share code, notes, and snippets.

View nathanp's full-sized avatar

Nathan Parikh nathanp

View GitHub Profile
WebSockets vs. Server-Sent events/EventSource
---------------------------------------------
Both WebSockets and Server-Sent Events are capable of pushing data to browsers. To me they seem to be competing technologies.
What is the difference between them? When would you choose one over the other?
Websockets and SSE (Server Sent Events) are both capable of pushing data to browsers, however they are not competing technologies.
Websockets connections can both send data to the browser and receive data from the browser.
A good example of an application that could use websockets is a chat application.
@secretstache
secretstache / get-video-thumbnail.php
Last active January 16, 2024 09:43
Get Video Thumbnail from Youtube or Vimeo
<?php
/**
* Retrieves the thumbnail from a youtube or vimeo video
* @param - $src: the url of the "player"
* @return - string
* @todo - do some real world testing.
*
**/
function get_video_thumbnail( $src ) {
@pippinsplugins
pippinsplugins / gist:11402562
Last active December 15, 2021 17:07
Custom user fields for Restrict Content Pro
<?php
/*
Plugin Name: Restrict Content Pro - Custom User Fields
Description: Illustrates how to add custom user fields to the Restrict Content Pro registration form that can also be edited by the site admins
Version: 1.0
Author: Pippin Williamson
Author URI: http://pippinsplugins.com
Contributors: mordauk
*/
@Strap1
Strap1 / Convert Custom Taxonomy to Custom Post Type
Last active November 26, 2024 09:31
A very hacky and quick way to transfer a Custom Taxonomy to Custom Post Type and transfer associated metadata to Custom Meta Fields. Note: You can use this if it fits your needs, but it is custom to my set up. Use in a testing environment. It's a plugin with no interface, runs on activation and depending on the amount of data, may hit PHP timeou…
<?php
/*
Plugin Name: Convert Custom Taxonomy to Custom Post Type
Plugin URI: N/A
Description: A plugin to convert a Custom Taxonomy to a Custom Post Type and transfer associated metadata.
Version: 0.1
Author: Strap1
Author URI: http:/www.hiphopinenglish.com
/** Convert Taxonomy '%name%' to CPT '%name%' **/
@tjhole
tjhole / WORDPRESS: Get And Cache Vimeo Thumbnails
Created December 5, 2013 13:07
WORDPRESS: Get And Cache Vimeo Thumbnails
// Get And Cache Vimeo Thumbnails
function get_vimeo_thumb($id, $size = 'thumbnail_small')
{
if(get_transient('vimeo_' . $size . '_' . $id))
{
$thumb_image = get_transient('vimeo_' . $size . '_' . $id);
}
else
{
$json = json_decode( file_get_contents( "http://vimeo.com/api/v2/video/" . $id . ".json" ) );
@alana-mullen
alana-mullen / Detect the last post in the WordPress loop
Last active May 29, 2023 16:50
Detect the last post in the WordPress loop
<?php if (($wp_query->current_post +1) == ($wp_query->post_count)) {
echo 'This is the last post';
} ?>
<?php if (($wp_query->current_post +1) != ($wp_query->post_count)) {
echo 'This is the not the last post';
} ?>
<?php
// LOGOUT LINK IN MENU
function diww_menu_logout_link( $nav, $args ) {
$logoutlink = '<li><a href="'.wp_logout_url().'">Logout</a></li>';
if( $args->theme_location == 'primary' ) {
return $nav.$logoutlink ;
} else {
return $nav;
@chuckreynolds
chuckreynolds / wordpress-remove-seo-columns.php
Last active March 29, 2020 06:17 — forked from norcross/remove-seo-columns.php
remove WordPress SEO columns from admin post tables
<?php
function rkv_remove_columns( $columns ) {
// remove the Yoast SEO columns
unset( $columns['wpseo-score'] );
unset( $columns['wpseo-title'] );
unset( $columns['wpseo-metadesc'] );
unset( $columns['wpseo-focuskw'] );
@frankyonnetti
frankyonnetti / wordpress-post-type-name.php
Last active December 31, 2022 15:30
WordPress - get post type name #wordpress
<?php
$post_type = get_post_type_object( get_post_type($post) );
echo $post_type->labels->name;
?>
@BFTrick
BFTrick / functions.php
Created November 15, 2012 01:49
Rename Existing Section in WordPress Theme Customizer
// rename existing sections
$wp_customize->add_section( 'section_id' , array(
'title' => __('Section Title','mytheme'),
'priority' => 20,
));