Skip to content

Instantly share code, notes, and snippets.

@ijy
ijy / check-null-empty.xsl
Created September 15, 2013 17:14
XSLT: Check if a string is null or empty.
<!--
CHECK IF A STRING IS NULL OR EMPTY
-->
<!-- Example XML -->
<group>
<item>
<id>item 1</id>
<CategoryName>blue</CategoryName>
</item>
@ijy
ijy / sublime-text-3-setup.md
Last active January 15, 2024 14:21
My Sublime Text 3 setup.

Sublime Text 3 Setup

Install Package Control

Install Package Control for easy package management.

  1. Open the console with Ctrl+`
  2. Paste in the following:
@ijy
ijy / Compass px to em
Created December 7, 2011 08:18
A Compass function to convert pixel font-sizes to em's
@function em($target, $context: $base-font-size) {
@if $target == 0 { @return 0 }
@return $target / $context + 0em;
}
$base-font-size: 15px;
h1 {
font-size: em(21px, 15px); // Outputs 1.4em
}
@ijy
ijy / xhtml-to-markdown.xsl
Created July 21, 2013 14:29
XHTML to Markdown converter.
<?xml version='1.0' encoding='iso-8859-1'?>
<!-- XHTML-to-Markdown converter by Andrew Green, Article Seven, http://www.article7.co.uk/ -->
<!-- This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. -->
<xsl:stylesheet version='1.0' xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='text' encoding='utf-8'/>
@ijy
ijy / cartesian-product.js
Last active April 23, 2022 15:54
Underscore.js implementation of Cartesian Product (without any mutable variable). @see: http://stackoverflow.com/questions/12303989/cartesian-product-of-multiple-arrays-in-javascript
function cartesianProductOf() {
return _.reduce(arguments, function(a, b) {
return _.flatten(_.map(a, function(x) {
return _.map(b, function(y) {
return x.concat([y]);
});
}), true);
}, [ [] ]);
};
@ijy
ijy / Laravel: Blade: Limit foreach loop.php
Created June 22, 2013 23:15
A quick and easy way to limit a foreach loop in Laravel Blade.
@foreach (array_slice($posts->toArray(), 0, 5) as $post)
<h1>{{ $post['title'] }}</h1>
@endforeach
@ijy
ijy / sym-custom-datasource.php
Created January 12, 2014 22:10
A bare-bones example of a custom datasource for use with Symphony 2.3.
<?php
/**
* Custom Datasource Skeleton
*
* A bare-bones example of a custom datasource for use with Symphony 2.3
*
* @author: Ian Young
* @email: i.young@me.com
* @date: 12.01.2014
@ijy
ijy / xslt-random-no-generator.xsl
Created September 18, 2013 20:16
Generate a random number between 1- 10 in XSLT. @href: http://www.getsymphony.com/discuss/thread/81429/
<!-- Add the 'math' namespace to your XML stylesheet (so we can use 'math:random') -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:math="http://exslt.org/math"
extension-element-prefixes="math">
<!-- Pick a random number between 1 - 10 and set as a variable -->
<xsl:value-of select="(floor(math:random()*10) mod 10) + 1" />
@ijy
ijy / search-and-replace-2.xsl
Created September 15, 2013 16:56
Alternative search and replace template for XSLT 1.0.
<!--
ALTERNATIVE SEARCH & REPLACE
string: The text to be evaluated
replace: The character or string to look for in the above string
with: What to replace it with
Slightly more long winded approach if that's how you prefer to roll.
-->
<xsl:template name="string-replace">
@ijy
ijy / multiple-push-urls.md
Created May 7, 2018 16:35 — forked from bjmiller121/multiple-push-urls.md
Add multiple push URLs to a single git remote

Sometimes you need to keep two upstreams in sync with eachother. For example, you might need to both push to your testing environment and your GitHub repo at the same time. In order to do this simultaneously in one git command, here's a little trick to add multiple push URLs to a single remote.

Once you have a remote set up for one of your upstreams, run these commands with:

git remote set-url --add --push [remote] [original repo URL]
git remote set-url --add --push [remote] [second repo URL]

Once set up, git remote -v should show two (push) URLs and one (fetch) URL. Something like this: