Skip to content

Instantly share code, notes, and snippets.

View KATT's full-sized avatar
🌴
On vacation

Alex / KATT KATT

🌴
On vacation
View GitHub Profile
@KATT
KATT / background-image2x.scss
Last active December 26, 2015 07:29
SCSS mixin for retina background images
@mixin background-image2x($image, $extension: 'png') {
$imageOrig: "#{$image}.#{$extension}";
$image2x: "#{$image}@2x.#{$extension}";
$width: image-width($imageOrig);
$height: image-height($imageOrig);
background-image: image-url($imageOrig);
@KATT
KATT / handlebar_helper_or.js
Created June 26, 2013 11:37
Handlebar helper `or` - grabs the first *truthy* argument that you send in and outputs it. See running example at http://cdpn.io/mxBjE
// Handlebar helper
Handlebars.registerHelper('or', function () {
var args = arguments;
for (var i in args) {
if (args[i]) {
return args[i];
}
}
return null;

Nice ordered list, but hard to maintain

  1. First item
  2. Second item
  3. Third item

Ugly ordered list

  1. First item
  2. Second item
if( !window.location.hash && window.addEventListener && document.documentElement.clientWidth <= 500 ){
window.addEventListener( "load",function() {
setTimeout(function(){
window.scrollTo(0, 1);
}, 0);
});
}
// Ajax Get. Cached. And aborts current request
var get = (function($) {
var xhr;
var xhrURL;
var cache = {};
return function(url, callback, jsonp) {
url += ((url.indexOf('?') === -1) ? '?' : '&');
url += jsonp ? 'callback=?' : 'ajax=1';
if (url == xhrURL && xhr.readystate != 4) {
// Already loading stuff, wait for it to finish
<?php
/**
* Check if content is JSON
*
* @param string $content
* @return boolean
*/
function w3_is_json($content) {
return json_decode($content) !== NULL;
}
@KATT
KATT / NSString+Distance.h
Created November 27, 2011 17:10
NSString+Distance category (using ARC)
//
// NSString+Distance.h
//
// Created by Alexander Johansson on 2011-11-27.
// Based on http://stackoverflow.com/q/5684973/590396
//
#import <Foundation/Foundation.h>
@interface NSString (Distance)
@KATT
KATT / CustomerController.php
Created September 14, 2011 08:02
Non-working loginAction()
<?php
// Include parent
require_once 'Mage/Adminhtml/controllers/CustomerController.php';
class MyNamespace_CustomerLogin_CustomerController extends Mage_Adminhtml_CustomerController {
function loginAction() {
$customerID = (int) $this->getRequest()->getParam('id');
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId,
UserSchema = require('./User').UserSchema;
var FriendRequest = new Schema({
from : {type: ObjectId, index:true}, // Why does not UserSchema.ObjectId work here, instead of ObjectId?
to : {type: ObjectId, index:true},
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId,
hashlib = require('hashlib');
var SAFE_COLS_TO_RETURN = function() {
return {
_id:1,