Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
ChrisLTD / parse_youtube_url.php
Created February 1, 2014 23:39
Put in a youtube URL of just about any format and get back the ID
<?php
function parse_youtube_url($url){
$id = '';
preg_match("/^.*(youtu.be\\/|v\\/|u\\/\\w\\/|embed\\/|watch\\?v=|\\&v=)([^#\\&\\?]*).*/uism", $url, $matches);
if( isset($matches[2]) ){
$id = $matches[2];
}
return $id;
}
// Usage:
// $("#element").yourPluginName("20px");
//
// Reference functions
// $(‘#element’).data(‘pluginName’).functionName();
(function($){
$.yourPluginName = function(el, options){
// To avoid scope issues, use 'base' instead of 'this' to reference this class from internal events and functions.
var base = this;
@ChrisLTD
ChrisLTD / gist:8904834
Created February 9, 2014 19:40
Pull track and album from iTunes
tell application "iTunes"
if player state is playing then
set trackName to (get name of current track)
set trackArtist to (get artist of current track)
else
return
end if
end tell
("Listening to " & quote & trackName & quote & " by " & trackArtist & " ♫") as text
@ChrisLTD
ChrisLTD / gist:8957379
Created February 12, 2014 15:18
Drupal 7 Get nodes by type, taxonomy term, and sort by custom field
<?php
$query = db_select('node', 'n');
$query->join('field_data_field_vertical', 'v', 'v.entity_id=n.nid');
$query->join('field_data_field_date', 'd', 'd.entity_id=n.nid');
$query
->fields('n', array('nid', 'title', 'created'))
->fields('d', array('field_date_value'))
->condition('v.field_vertical_tid', 1)
->condition('n.status', 1)
->condition('n.type', 'event')
@ChrisLTD
ChrisLTD / gist:9061286
Last active August 29, 2015 13:56
jQuery & modernizr placeholder text fallback
// placeholder text fallback
if(!Modernizr.input.placeholder){
$('input').not('.placeholder-fallback-inited').each(function() {
var $this = $(this);
$this.val( $this.attr('placeholder') );
$this.addClass('placeholder-fallback-inited');
})
.focus(function(){
var $this = $(this);
if( $this.val() == $this.attr('placeholder') ){
@ChrisLTD
ChrisLTD / gist:9316849
Last active August 29, 2015 13:56
jQuery Smooth Scrolling anchors
// Smooth scrolling
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
var scrollValue = target.offset().top;
$('html,body').animate({
scrollTop: scrollValue
}, 1000);
@ChrisLTD
ChrisLTD / app.js.coffee
Created March 30, 2014 23:55
Making angular app POST and GET ajax work with Rails
@app = angular.module('MyApp',[]);
@app.config ($httpProvider) ->
authToken = $("meta[name=\"csrf-token\"]").attr("content")
$httpProvider.defaults.headers.common["X-CSRF-TOKEN"] = authToken
$httpProvider.defaults.headers.common['Accept'] = "application/json"
@ChrisLTD
ChrisLTD / gist:11061553
Created April 18, 2014 19:52
Add big integer strings, returns a string
function addBigInts(a, b) {
var result = '';
var carry = 0;
// convert to arrays and flip around
a = a.split('').reverse();
b = b.split('').reverse();
// we have to loop through the longer number to add all the values
var longerNumber = (a.length > b.length) ? a : b;
body {
font-family: BodyRegular, "Verdana", "Tahoma" ;
font-weight: normal;
color: red;
background-color: #d1f8fd;
// Small Font Size Scaling
font-size: 12pt;
text-rendering: optimizeLegibility;
@for $i from 1 through 15 {
@ChrisLTD
ChrisLTD / wp-config.php
Created May 7, 2014 17:20
Loading Wordpress local config
<?php
/**
* Local configuration information.
*/
if (file_exists(dirname(__FILE__) . '/wp-config-local.php')):
require_once(dirname(__FILE__) . '/wp-config-local.php');
/**
* Remote configuration settings.
*/