Skip to content

Instantly share code, notes, and snippets.

View sscovil's full-sized avatar

Shaun Scovil sscovil

View GitHub Profile
@sscovil
sscovil / custom-gravity-forms.css
Created September 21, 2014 17:36
CSS Template for Gravity Forms WordPress plugin - based on docs found here: http://www.gravityhelp.com/documentation/page/CSS_Targeting_Samples
// Form Wrapper
body .gform_wrapper {
}
// Form Heading
body .gform_wrapper .gform_heading {
}
@sscovil
sscovil / javascript-regex-functions.js
Last active August 29, 2015 14:07
A random collection of JavaScript RegEx functions, in no particular order.
function stripTags(string) {
// Remove anything wrapped in angle brackets
return string.replace(/(<([^>]+)>)/ig, '');
}
function stripUrlQueryChars(string) {
// Disallow the following characters: ? & : " '
return string.replace(/(\?|\&|\:|\"|\')/g, '').replace('&', '');
}
@sscovil
sscovil / javascript-utils.js
Created October 9, 2014 19:51
Useful JavaScript utility functions.
/**
* Given an object with unknown fields AND an object containing default values that are required, this method
* will populate the unknown object with the default object's values for any undefined fields.
*
* @param object
* @param defaults
* @returns {*|{}}
*/
function applyDefaults(object, defaults) {
object = object || {};
/**
* Let's say we have JSON-style URL query parameter values like this:
* ?metadata={"or":{"eq":"foo===bar","neq":"fez===baz"}}&id={"nin":"abc,def,ghi"}
*/
String urlParams = "?metadata={\"or\":{\"eq\":\"foo===bar\",\"neq\":\"fez===baz\"}}&id={\"nin\":\"abc,def,ghi\"}";
/**
* ...and we want to parse out each key-value pair into a Map<String, String>, with the value being a JSON string.
*/
Map<String, String> urlParamsMap = new HashMap<String, String>();
@sscovil
sscovil / MostCommonLetter.java
Created November 12, 2014 05:40
An exercise to create a function that, given a string, returns the most commonly-used letter (or letters, in the case of a tie). It should only consider letters and should gracefully handle strings that do not contain letters.
import junit.framework.Assert;
import org.junit.Test;
import java.util.*;
public class MostCommonLetterTests {
public Character[] mostCommonLetter(String string) {
if (string.isEmpty())
throw new IllegalArgumentException("Empty string can not be evaluated for most common letter.");
{
"string": "foobar",
"number": 123,
"boolean": true,
"array": [ "foo", "bar" ],
"object": { "foo": "bar" }
}

In PHP Storm (and presumably other IDEs), use the following RegEx patterns to Find/Replace all instances of define('FOO', 'bar'); with static $FOO = "bar".

Find: define\('(.+)', '(.+)'\);

Replace: static \\$$\1 = "$\2";

@sscovil
sscovil / app.js
Last active August 29, 2015 14:13
An example of how one might use https://github.com/nervgh/angular-file-upload to communicate with a PHP proxy and Amazon S3.
(function() {
var module = angular.module('myApp', [
'angularFileUpload'
]);
module.controller('MyCtrl', ['$scope', 'FileUploader', function($scope, FileUploader) {
'use strict';
$scope.uploader = new FileUploader({
url : 'http://mydomain.com/s3proxy.php',
@sscovil
sscovil / yourdomain.com
Last active August 29, 2015 14:14
Nginx server block example for a site (yourdomain.com) running a dpd server on a subdomain (api.yourdomain.com).
server {
server_name api.yourdomain.com;
location / {
# Pass API requests to Deployd server listening on port 3000
proxy_pass $scheme://127.0.0.1:3000$request_uri;
# Required for Socket.io
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
<?php
/**
* Current Region
*
* Region IDs used in index.php and passed to populate_region() by __call() via $method.
*/
public static function current_region() {
if ( is_front_page() ) {
$region = 'home';