Skip to content

Instantly share code, notes, and snippets.

View alanshaw's full-sized avatar
🫀
https://web3.storage

Alan Shaw alanshaw

🫀
https://web3.storage
View GitHub Profile
@alanshaw
alanshaw / gist:2354103
Created April 10, 2012 20:05
Get the underlying object instance from a Spring proxy
def getTargetObject[T](proxy: AnyRef, targetClass: Class[T]): T = {
if(AopUtils.isJdkDynamicProxy(proxy)) {
proxy.asInstanceOf[Advised].getTargetSource.getTarget.asInstanceOf[T]
} else {
proxy.asInstanceOf[T] // expected to be cglib proxy then, which is simply a specialized class
}
}
@alanshaw
alanshaw / gist:2644213
Created May 9, 2012 12:35
LESS CSS class for cross browser opacity
.opacity(@opacity) {
@ieOpacity: @opacity * 100;
// If you don't use this order, IE8-as-IE7 doesn't apply the opacity, although IE8 and a pure IE7 do.
// http://www.quirksmode.org/css/opacity.html
-ms-filter: ~"progid:DXImageTransform.Microsoft.Alpha(Opacity=@{ieOpacity})"; // IE 8
filter: ~"alpha(opacity=@{ieOpacity})"; // IE 5-7
opacity: @opacity;
}
@alanshaw
alanshaw / gist:2836615
Created May 30, 2012 14:18
Github styles markdown nicely, use this tool to make a PDF with those styles
<!doctype html>
<html>
<head>
<title>Github styled markdown to PDF</title>
<link href="https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github-c7ba6c512453df8f611d2a8568351b86323d2a76.css" media="all" rel="stylesheet" type="text/css" />
<link href="https://a248.e.akamai.net/assets.github.com/stylesheets/bundles/github2-77e5855e2aded4d3c3957eb064a24cea174c93b8.css" media="all" rel="stylesheet" type="text/css" />
<style media="screen">
body {padding: 1em;}
#setup label, #setup textarea {display: block; margin: 0.5em 0;}
#setup textarea {width: 60em; height: 10em;}
@alanshaw
alanshaw / gist:3097092
Created July 12, 2012 09:54
JavaScript function for checking if an object key chain exists
/**
* <code>
* var o = {
* foo: {
* bar: {
* baz: 'w00t!'
* }
* }
* }
* keyChainExists('foo.bar.baz', o); // -> true
@alanshaw
alanshaw / gist:4085837
Created November 16, 2012 09:24
Lazy singleton class instance function
class Foo
@instance: (=>
instance = null
=>
instance = new @() if not instance
instance
)()
singletonFoo = Foo.instance()
@alanshaw
alanshaw / gist:4087172
Created November 16, 2012 13:01
Compiled CoffeeScript from https://gist.github.com/4085837
var Foo, singletonFoo;
Foo = (function() {
var _this = this;
function Foo() {}
Foo.instance = (function() {
var instance;
instance = null;
@alanshaw
alanshaw / index.html
Created December 26, 2012 01:03
A CodePen by Alan Shaw. Unicode snowflakes in not a million lines of code
<div id="main"></div>
@alanshaw
alanshaw / gist:4585876
Created January 21, 2013 13:00
JavaScript test for integer
function isInt(value){
return (Object.prototype.toString.call(value) == '[object Number]' && parseFloat(value) == parseInt(value)) && !isNaN(value);
}
/*
Test data:
isInt(null) -> false
isInt(undefined) -> false
isInt('') -> false
@alanshaw
alanshaw / gist:4585888
Created January 21, 2013 13:04
JavaScript test for String
function isString(str) {
return Object.prototype.toString.call(str) == '[object String]';
}
/*
Test data:
isString(null) -> false
isString(undefined) -> false
isString([]) -> false

Ext's event model is so messed up that I can inadvertantly trigger another run of event processing whilst in the middle of event processing. It means that new events can be triggered and handled whilst half way through processing the current set of events. This is what is happening:

Event handler invoked
Mid way through some code causes Ext to do an event run
    Event handler invoked again
    Event dealt with
Event dealt with