Skip to content

Instantly share code, notes, and snippets.

View elvismdev's full-sized avatar
🏴

Elvis Morales elvismdev

🏴
View GitHub Profile
@BFTrick
BFTrick / deploy.sh
Created September 22, 2012 18:28
WordPress Plugin Deploy Script
#! /bin/bash
# A modification of Dean Clatworthy's deploy script as found here: https://github.com/deanc/wordpress-plugin-git-svn
# The difference is that this script lives in the plugin's git repo & doesn't require an existing SVN repo.
# main config
PLUGINSLUG="______your-plugin-name______"
CURRENTDIR=`pwd`
MAINFILE="______your-plugin-name______.php" # this should be the name of your main php file in the wordpress plugin
# git config
@Godefroy
Godefroy / troll.php
Created September 24, 2012 18:56
Balanced parentheses? in #PHP
<?php
function isBalanced($str){
$count = 0;
$length = strlen($str);
for($i = 0; $i < $length; $i++){
if($str[$i] == '(')
$count += 1;
else if($str[$i] == ')')
$count -= 1;
@wesleybliss
wesleybliss / gist:3813778
Created October 1, 2012 19:11
PHP Check If Parentheses Are Balanced
<?php
// Determine if there is an equal number of parentheses
// and if they balance logically, i.e.
// ()()) = Bad (trailing ")")
// (())()() = GOOD
// )()()(()) = BAD (leading ")")
function is_balanced( $s ) {
// Keep track of number of open parens
@danvbe
danvbe / 1-Explanations.md
Last active April 21, 2023 15:39
A way to integrate FosUserBundle and HWIOAuthBundle

I have managed to install this… and make it work. I implemented it for Facebook and Google, but you can extend it. My solution it is mostly as described in #116, with a bit of more code presented. The key aspects that lack in the #116 presentation (IMO) are:

  • the registration as service of your custom FOSUBUserProvider (with the necessary parameters)
  • set the service for oauth_user_provider in the security.yml with your custom created service

Here are the steps:

  1. Routing. In routing.yml I have added all the routes for both bundles.
  2. Configuration. I have set the config.yml mostly as it is presented in the HWIOAuthBundle.
  3. Security. I have set the security.yml mostly as it is presented in the HWIOAuthBundle (though my routes are using /login pattern, not /connect). Also, the oauth_user_provider is set for my custom service.
@yoren
yoren / gist:4553933
Last active May 26, 2022 01:03
WordPress: Select post parent from another post type
add_action('admin_menu', function() {
remove_meta_box('pageparentdiv', 'chapter', 'normal');
});
add_action('add_meta_boxes', function() {
add_meta_box('chapter-parent', 'Part', 'chapter_attributes_meta_box', 'chapter', 'side', 'high');
});
function chapter_attributes_meta_box($post) {
$post_type_object = get_post_type_object($post->post_type);
if ( $post_type_object->hierarchical ) {

This walk-through will demonstrate how to calculate and add tax to your entry total. There are two pieces to the Gravity Forms pricing puzzle (easy puzzle, huh?):

  1. the total that is calculated on the front-end as the user selects various products
  2. the total that is calculated (and validated!) in the backend

Any time you are customizing Gravity Form pricing, you'll need to make sure you implement your changes in both places.

The Front-end Total

To modify the front-end total we're going to use a Gravity Form definable function: [[gform_product_total]]. Gravity Forms will automatically check for this function and if you've defined it, it will run every time the total is updated. Here is snippet of code that defines this function for our form:

@reifman
reifman / default.vcl
Last active September 9, 2021 08:15
Example Varnish VCL Configuration e.g. /etc/varnish/default.vcl
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 60s;
.first_byte_timeout = 60s;
.between_bytes_timeout = 60s;
.max_connections = 800;
}
@reifman
reifman / varnish
Created January 28, 2013 00:09
Example Varnish configuration file e.g. /etc/default/varnish
# Configuration file for varnish
#
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
# to be set from this shell script fragment.
#
# Should we start varnishd at boot? Set to "no" to disable.
START=yes
# Maximum number of open files (for ulimit -n)
@mbijon
mbijon / posts_search_demo.php
Created February 18, 2013 18:48
WordPress posts_search filter example, for Tom Barrett on WP-Hackers list 2013-02-18
function tcb_filter_search( $term ) {
if ( is_search() )
$search = "(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
return $search;
}
add_filter( 'posts_search', 'tcb_filter_search', null, 2 );
@zimzat
zimzat / paydate_calculator.class
Created July 3, 2013 19:36
Part of a code challenge for a job application in 2007 was to create a pay date calculator. Presented here is the exact code created for it over 6 years ago. Needless to say some of my coding practices and styles have further developed since that time, such as placing the trailing parenthesis on a separate line, using lowerCamelCase for variable…
<?php
class Paydate_Calculator {
/**
* Indicate if we're going forward (1) or backward (-1) when we make our adjustments.
* @var int
*/
private $due_date_adjustment = 1;
/**