Skip to content

Instantly share code, notes, and snippets.

@kiub
kiub / modify-response-wp-rest-api.php
Created August 6, 2015 20:10
Modifying responses in WP Rest Api. Add featured image thumbnail to the response for a custom post type (by default return ID).
// in function.php
// Modify Responses WP Rest Api
add_action( 'rest_api_init', 'featured_image_thumbnail_url' );
// Modifying Responses
function featured_image_thumbnail_url() {
// More info http://v2.wp-api.org/extending/modifying/
register_api_field(
@kiub
kiub / controller.js
Last active August 29, 2015 14:25 — forked from eyston/controller.js
angular typeahead
angular.module('ymusica').controller('AlbumSearch', ['$scope', 'Albums', 'Artists', '$q', function($scope, albums, artists, $q) {
$scope.albums = [];
$scope.artists = [];
var terms = new Rx.Subject();
$scope.searchMusic = terms.onNext.bind(terms);
terms.sample(250)
@kiub
kiub / orientable.js
Created July 22, 2015 18:22
Add class to img if image is portrait or landscape
// html: <img ng-src="image-url.jpg" class="horizontal" orientable />
app.directive('orientable', function () {
return {
link: function(scope, element, attrs) {
element.bind("load" , function(e){
// success, "onload" catched
// now we can do specific stuff:
if(this.naturalHeight > this.naturalWidth){
this.className = "vertical";
}
@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();
# 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 / 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>
@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;
<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;
<!-- 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 -->
$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} {