Skip to content

Instantly share code, notes, and snippets.

Christopher Crouch chrisdc

Block or report user

Report or block chrisdc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chrisdc
chrisdc / search.js
Last active Oct 11, 2018
Binary Search
View search.js
function search(key, data) {
var min = 0;
var max = data.length - 1;
var half;
while (max >= min) {
half = Math.floor((max + min)/2);
if (data[half] === key) {
return half;
@chrisdc
chrisdc / stemmer.js
Last active Oct 8, 2018
A compact implementation of the Porter 2 stemming algorithm in Javascript
View stemmer.js
'use strict';
function handleSuffix(word, patterns) {
var wordLen = word.length;
for (var i = 0, len = patterns.length; i < len; i++) {
if (patterns[i][0].test(word)) {
if (wordLen - patterns[i][3] < patterns[i][2]) {
// The given suffix does not fit in the required region.
return word;
@chrisdc
chrisdc / log-message.js
Created Sep 24, 2018
Mocking globals in Jest.
View log-message.js
function logMessage(message) {
console.log(message);
}
module.exports = logMessage
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
View gist:e99763a1d9da1aaf99a1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Template</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
@chrisdc
chrisdc / .jscsrc
Last active Nov 2, 2018
Options file for JSCS
View .jscsrc
{
"disallowKeywordsOnNewLine": ["else"],
"disallowMixedSpacesAndTabs": "smart",
"disallowNewlineBeforeBlockStatements": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowTrailingWhitespace": true,
"requireBlocksOnNewline": true,
@chrisdc
chrisdc / events.js
Last active Aug 29, 2015
Publish/subscribe module
View events.js
/**
* A simple Publish/subscribe javascript module based on code by David Walsh:
* http://davidwalsh.name/pubsub-javascript
*/
var events = (function(){
// Holds the subscribed topics.
var topics = {};
return {
subscribe: function( topic, callback ) {
@chrisdc
chrisdc / navigation.js
Last active Nov 2, 2018
Object Orientated navigation.js
View navigation.js
( function() {
function Menu( containerId, options ) {
var container,
menu,
button;
function init() {
container = document.getElementById( containerId );
if ( ! container ) {
@chrisdc
chrisdc / term-meta.php
Last active Aug 30, 2018
Add a custom meta box to the new/edit category pages. The meta data is saved to the array term_meta[], which can handle further fields in the future. Based on: https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/
View term-meta.php
<?php
/**
* Add a custom meta box to the new/edit category pages.
* The meta data is saved to the array term_meta[], which can handle further
* fields in the future.
*
* Based on: https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/
*/
/**
@chrisdc
chrisdc / plugin.php
Created Jul 31, 2014
Wordpress Plugin Template
View plugin.php
<?php
/**
* Plugin Name: My Plugin
* Plugin URI: https://example.com/plugin/
* Description: An amazing WordPress plugin.
* Version: 1.0
* Author: [Author Name]
* Author URI: https://example.com/author/
* License: GPL2
* Text Domain: myplugin
You can’t perform that action at this time.