Skip to content

Instantly share code, notes, and snippets.

@luk3thomas
luk3thomas / readme.md
Last active August 29, 2015 13:55
Google Analytics track Facebook social actions

Add this directly after the opening <body> tag

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=477427382375494";
  fjs.parentNode.insertBefore(js, fjs);

}(document, 'script', 'facebook-jssdk'));

@luk3thomas
luk3thomas / gulpfiles.js
Created March 22, 2014 18:59
Gulp example
var gulp = require('gulp')
, less = require('gulp-less')
, plumber = require('gulp-plumber')
, replace = require('gulp-replace')
, jshint = require('gulp-jshint')
, concat = require('gulp-concat');
var cfg = {
files: {
@luk3thomas
luk3thomas / external-links.js
Created March 22, 2014 19:52
Open links in an new tab
@luk3thomas
luk3thomas / menu-tree.js
Last active August 29, 2015 13:58
Recursive function for creating a menu object. The function takes a jQuery object and recursively builds a menu tree
var _links = function($lis, depth) {
return $.makeArray($lis.map(function(i, li) {
var $li = $(li),
$a = $li.find('> a'),
$children = $li.find('> .sub-menu > li'),
link = {
name: $a.text(),
href: $a.attr('href'),
depth: depth
};
@luk3thomas
luk3thomas / broken.html
Last active August 29, 2015 13:59
JavaScript closure problem loop
<!--
console.log always says '10'
-->
<style>
#links {
padding:1em;
}
a {
text-decoration:none;
Model = require "lib/model"
class Card extends Model
defaults:
name: ""
value: ""
transform: (name, value)->
@luk3thomas
luk3thomas / gulpfile.coffee
Last active August 29, 2015 14:11
working example of gulp, coffeescript, react, jsx, browserify
sys = require "sys"
exec = require("child_process").exec
spawn = require("child_process").spawn
browserify = require "browserify"
watchify = require "watchify"
coffee_react = require "coffee-reactify"
gulp = require "gulp"
jade = require "gulp-jade"
plumber = require "gulp-plumber"
reload = require "gulp-livereload"
@luk3thomas
luk3thomas / sortBy-spec.coffee
Last active August 29, 2015 14:14
Crazy sort using eval
describe "#sortBy", ->
it "sorts on simple props", ->
sorted = [ {name: "bar"}, {name: "baz"}, {name: "foo"} ]
unsorted = [ {name: "foo"}, {name: "bar"}, {name: "baz"} ]
expect(unsorted.sort(sortBy("name"))).toEqual(sorted)
it "sorts in nested objects", ->
unsorted = [ {name: first: "foo"}, {name: first: "bar"}, {name: first: "baz"} ]
@luk3thomas
luk3thomas / wordpress-plugin-error-resolution.md
Created December 13, 2012 19:59
A client cannot search for plugins or install plugins from the WordPress dashboard

Problem

A client cannot search for plugins or install plugins from the WordPress dashboard and Akismet will not connect to the servers. The client is on a VPS. After investigation, the error was caused becuase the server is timing out on the requtest.

In this file: /wp-admin/includes/plugin-install.php line 44

$request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array( 'timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))) 

In this file:

=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')