Skip to content

Instantly share code, notes, and snippets.

Kamran Ayub kamranayub

Block or report user

Report or block kamranayub

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
kamranayub / trigger-build.js
Created Mar 29, 2015
Manually trigger Travis CI build for repository
View trigger-build.js
var Travis = require('travis-ci');
// change this
var repo = "kamranayub/";
var travis = new Travis({
version: '2.0.0'
kamranayub /
Created Feb 26, 2015
Deploy site from Travis
echo "Running deployment script..."
CURRENT_COMMIT=`git rev-parse HEAD`
# Change the branch used if applicable (e.g. gh-pages)
echo "Cloning master branch..."
# Hide output since we use an access token here
git clone -b master "https://${GH_TOKEN}@${GH_REF}" _deploy > /dev/null 2>&1 || exit 1
kamranayub / removeRoot.js
Created Aug 29, 2013
Remove the root element of a JSON object, see:
View removeRoot.js
var rootElementJson = {
root: {
name: "Foo",
person: true
var removeRootElement = function (obj) {
var numKeys = 0,
kamranayub / DataContext.js
Created Apr 24, 2013
A working ASP.NET Web API MVC 4 Anti-Forgery approach that also works on cloud hosts like AppHarbor. See:
View DataContext.js
var options = {};
// jQuery options
// options.url = foo;
// CSRF Token
var csrfToken = $("input[name='__RequestVerificationToken']").val();
if (csrfToken) {
options.headers = {
kamranayub / TransparentButton.cs
Created Apr 6, 2013
Transparent button for Windows Phone
View TransparentButton.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace MyApp.Phone.UI.Controls {
public class TransparentButton : ContentControl {
public TransparentButton() {
HorizontalContentAlignment = HorizontalAlignment.Stretch;
kamranayub / CssClassBinding.js
Last active Dec 15, 2015
CSS Class binding for Knockout.js
View CssClassBinding.js
// Observable CSS Class Binding
// See Fiddle for usage:
ko.bindingHandlers['class'] = {
update: function (element, valueAccessor) {
var currentValue = ko.utils.unwrapObservable(valueAccessor()),
prevValue = element['__ko__previousClassValue__'],
kamranayub / SlideLeftRightTransitions.xaml
Created Feb 4, 2013
Slide Left / Right Transitions for `TransitioningContentControl`
View SlideLeftRightTransitions.xaml
<VisualState x:Name="NextTransition">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="CurrentContentPresentationSite" Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1">
<ExponentialEase EasingMode="EaseOut" Exponent="6"/>
kamranayub / TaskExtensions.cs
Created Jan 27, 2013
A Promise/A-like implementation of the `Then()` function. Accepts optional error callback, otherwise errors bubble up to next chained method. See:
View TaskExtensions.cs
public static class TaskExtensions {
/// <summary>
/// A CommonJS Promise-like method that will execute a success and error callback, or just bubble up errors if not handled
/// </summary>
/// <typeparam name="TFirst"></typeparam>
/// <typeparam name="TNext"></typeparam>
/// <param name="first"></param>
/// <param name="success"></param>
/// <param name="error"></param>
kamranayub / CryptoExtensions.cs
Last active Dec 11, 2015
Two useful hashing extension methods (MD5 and SHA1).
View CryptoExtensions.cs
using System.Security.Cryptography;
namespace Extensions {
public static class CryptoExtensions {
private static readonly SHA1 Sha1 = SHA1.Create();
private static readonly MD5 Md5 = MD5.Create();
/// <summary>
/// Performs an MD5 hash on the string and returns a 32 character hex format.
/// </summary>
kamranayub / RouteExtensions.cs
Last active Dec 10, 2015
RenderRoutes renders a JSON object that contains all your named routes, as long as you're using AttributeRouting
View RouteExtensions.cs
// RenderRoutes extension
// Use with AttributeRouting and JSON.NET to
// render out a JSON object that contains all your
// named routes for use in your client scripts.
public static class RouteExtensions {
/// <summary>
/// Renders a JSON object of routes
You can’t perform that action at this time.