Skip to content

Instantly share code, notes, and snippets.

@kiub
kiub / functions.php
Created November 11, 2012 19:07 — forked from johnmegahan/functions.php
Extended Walker class for use with the Twitter Bootstrap toolkit Dropdown menus in Wordpress.
<?php
add_action( 'after_setup_theme', 'bootstrap_setup' );
if ( ! function_exists( 'bootstrap_setup' ) ):
function bootstrap_setup(){
add_action( 'init', 'register_menu' );
@kiub
kiub / gist:6412964
Last active December 22, 2015 03:49
# Sample code for sending MailChimp Email Campaigns from a Rails App using Gibbon API wrapper v0.3.5
# All recipients must already be on the associated MailChimp list (list_id), for this app we add those via another
# API call every few minutes.
#
# Member function of EmailCampaign.rb model
# See http://labs.saidigital.co/using-mailchimp-api-to-send-email-campaigns-to-a-dynamic-set-of-email-addresses-425/
# for explanation.
def send_campaign(api_key, gb, list_id, template_id, from_name, from_email)
self.reset_unique_id
segment_id = gb.list_static_segment_add(:id => list_id, :name => self.safe_name)
@kiub
kiub / Generate excerpt from html
Last active August 29, 2015 14:21
Generate excerpt from html (trim, replace) as string
(function($) {
// jQuery function to set a maximum length or characters for a page element it can handle mutiple elements
$.fn.createExcerpts = function(elems,length,more_txt) {
$.each($(elems), function() {
var item_html = $(this).html(); //
item_html = item_html.replace(/< /?[^>]+>/gi, ''); //replace html tags
item_html = jQuery.trim(item_html); //trim whitespace
$(this).html(item_html.substring(0,length)+more_txt); //update the html on page
});
return this; //allow jQuery chaining
$alpha_color: red;
$bravo_color: blue;
$charlie_color: green;
$color_names: alpha_color bravo_color charlie_color;
$color_vars: $alpha_color $bravo_color $charlie_color;
@each $name in $color_names {
$i: index($color_names, $name);
%#{$name} {
<!-- example 1 -->
<li ng-class="$first ? 'firstRow' : 'nonFirstRow'">...</li>
<!-- example 2 -->
<li ng-class="{myClass: $first, anotherClass: $index == 2}">...</li>
<!-- example 3 -->
<li ng-style="{true: {color: 'red'}, false: {}}[$first]">...</li>
<!-- from: http://stackoverflow.com/questions/12008580/a-ternary-in-templates -->
<html>
<head>
<script src="https://rawgithub.com/ai/autoprefixer-rails/master/vendor/autoprefixer.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style type="unprocessed" id="AutoprefixerIn">#output {
width: 307px;
height: 250px;
background: rgba(255,255,255,0.5);
border: 1px solid #ccc;
@kiub
kiub / index.html
Last active August 29, 2015 14:22
JS Bin// source http://jsbin.com/beroxu
<html>
<head>
<script src="https://rawgithub.com/ai/autoprefixer-rails/master/vendor/autoprefixer.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style type="unprocessed" id="AutoprefixerIn">#output {
width: 307px;
height: 250px;
background: rgba(255,255,255,0.5);
border: 1px solid #ccc;
@kiub
kiub / basic-html5.html
Last active August 29, 2015 14:22
A basic example of html5 with new sectioning elements
<!DOCTYPE html>
<html>
<head>
<title>Simple HTML5 blog</title>
</head>
<body>
<main role="main">
<header>
<h1>Simple <span>HTML5</span> blog</h1>
# bash function, usage: $ st -p [projectname] -opt2 -opt3
function sublime() {
if [ -n "$1" -a -n "$2" ]; then # if more than one argument
if [ "$1" = "-p" -o "$1" = "--project" ]; then # if arg1 is -p or --project
local projectfile="$2"
[[ $projectfile != *.sublime-project ]] && projectfile="$2.sublime-project" # detect if arg2 already includes the ext
if [ -e $projectfile ]; then # does project file exist?
subl -n --project $projectfile ${*:3} # open project file, in new window, include trailing args
#echo "project specified, and project file exists, execute: subl -n --project $projectfile ${*:3}"
else
@kiub
kiub / img-angular-directive.js
Last active August 29, 2015 14:25
Img directive to render a default image if ngSrc path resolves to a 404
// source code from:
// http://stackoverflow.com/questions/16310298/if-a-ngsrc-path-resolves-to-a-404-is-there-a-way-to-fallback-to-a-default
app.directive('img', function () {
return {
restrict: 'E',
link: function (scope, element, attrs) {
// show an image-missing image
element.bind('error', function () {
var w = element.width();
var h = element.height();