Skip to content

Instantly share code, notes, and snippets.

@shawndreck
shawndreck / detect element is in view.js
Created June 2, 2022 15:51
detects with js if an element is in view or not
function isInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
@shawndreck
shawndreck / apply_filter_to_show_only_custom_post_type_in_wordpress.php
Created June 22, 2020 08:19
Add this code at the bottom of the theme functions file to show only custom post type in sidebar recent post in a wordpress installation
<?php
/**
* Display CPT on Recent Post widget
* @author Maxwell
* @version 0.0.1
*/
add_filter( 'widget_posts_args', 'jps_news_widget_recent_post' );
function jps_news_widget_recent_post( $params )
@shawndreck
shawndreck / gist:6186311
Last active December 20, 2015 19:49
Basic code structure for sending email with SwiftMailer. The mbstring.func_overload value 2 does not work nicely with the swiftmailer library so a change before sending email is required.
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2)
{
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
// Create your message and send it with Swift Mailer
if (isset($mbEncoding))
{
@shawndreck
shawndreck / simple_recaptcha_form.html
Created November 2, 2012 13:43
Simple form to test my Extended Zend_Form_Element for reCAPTCHA
<form action="somefile.php" method="post" >
<!-- Recaptcha -->
<script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=public_key">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
@shawndreck
shawndreck / App_Form_Common_Validator_Recaptcha.php
Created November 2, 2012 11:07
Zend Form element validator for custom recaptcha element
<?php
class App_Form_Common_Validate_Recaptcha extends Zend_Validate_Abstract
{
const INVALID_VALUE = 'invalidValue';
protected $_messageTemplates = array(
self::INVALID_VALUE => "'%value%' is not valid");
public function isValid($value)
{
@shawndreck
shawndreck / ZendExt_view_Smarty3
Created October 17, 2012 06:30
integrating smarty 3 with zend application
<?php
/**
* Uses smarty template engine to render html pages
* @author shawndreck
*
*/
require_once APPLICATION_PATH . '/../lib/Smarty/SmartyBC.class.php';
class ZendExt_View_Smarty3 implements Zend_View_Interface
{
@shawndreck
shawndreck / smarty_modifier_gravatar_link.php
Created October 14, 2012 19:10
A simple smarty3 modifier to create a gravatar link
@shawndreck
shawndreck / HTMLWindow.mxml
Created October 5, 2012 14:51
A simple way to create a web browser using flex and air
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
protected function verifyURL(sUrl:String):String{
if(sUrl.substring(0,"http".length) == "http"){
return sUrl;
@shawndreck
shawndreck / pi_calculator.c
Created October 5, 2012 12:07
Calculate the value of pi using basic C programming langage
#include<stdio.h>
#include<math.h>
/*
* To compile use the following, use the command:" gcc -o my_pi pi.c -lm"
* Assuming you are using gcc compiler and the file name is pi.c
*/
double calc1(int num1)
{
return (16/(num1 * pow(5.0,num1 * 1.0)));
}