Just a small jQuery plugin that I wrote to quickly add playing of vimeo clips in a fancybox (unobtrusive).
(function ($) {
$.fn.vimeoInFancybox = function (options) {
var opts = $.extend({}, $.fn.vimeoInFancybox.defaults, options);
$(this).each(function () {
var url = $(this).attr("href");
var optionRegex = new RegExp(".*?/([\\d]+)$");
var vimeoId = optionRegex.exec(url)[1];
var playerUrl = "http://player.vimeo.com/video/" + vimeoId;
$(this).fancybox({
href: playerUrl,
type: 'iframe',
width: opts.width,
height: opts.height
});
});
};
$.fn.vimeoInFancybox.defaults = {
width: 640,
height: 480
};
})(jQuery);
$(function () {
$("a.fancybox-vimeo").vimeoInFancybox();
});
Example: (Just include the js on the page in a javascript tag or in a separate file that is included)
<a href="http://vimeo.com/1084537" class="fancybox-vimeo">Add image here if you want</a>
This is just a small proof of concept (so don’t blame me for the lame CSS I created.
).
I found out it can be done nicer. (Read this awesome article about flip effects) I only do 90 degree rotations on the Y-axis and do no backside-hiding.
The idea is that a visible panel is seemingly rotated and the backside becomes visible. This works by using transition events. The 1st panel is visible at start and the 2nd panel is hidden. Then when an event is triggered (Hovered in this example) the 1st panel will be rotated 90 degrees (y-axis). The panel is then invisible the animation is ended and an event is triggered. At that point the 2nd panel is made visible and an class is added to trigger to animate it from 90 degrees back to 0 degrees. Thus creating an animation which makes it seem like the panel was completely rotated.
The implementation is currently only working for webkit based browsers.
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
div#slide1
{
width:100px;
height:100px;
background:red;
-webkit-transition: -webkit-transform 0.5s ease-in;
}
div#slide2
{
width:100px;
height:100px;
background:green;
-webkit-transform: rotateY(90deg);
-webkit-transition: -webkit-transform 0.5s ease-in;
}
div#slide1:hover
{
-webkit-transform: rotateY(90deg);
}
div#slide2.foo
{
-webkit-transform: rotateY(0deg);
}
</style>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
document.addEventListener(
'webkitTransitionEnd',
function( event ) {
$("#slide1").hide();
$("#slide2").show().addClass("foo");
}, false );
</script>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer.</p>
<div id="slide1">Test</div>
<div id="slide2" style="display: none;">Awesome</div>
<p>Hover over the div element above, to see the transition effect.</p>
</body>
</html>
Creating new classes during runtime can be nice when you need it. Below is a small example of what is possible. (No interface or existing base class is used in this example so reflection is required to invoke a method)
ClassPool classPool = ClassPool.getDefault();
CtClass cc = classPool.makeClass("AwesomeNewClass");
cc.addMethod(CtMethod.make("public String getValue() { return \"Hello World!\"; }", cc));
Class awesome = cc.toClass();
Object o = awesome.newInstance();
Method method = awesome.getMethod("getValue");
String returnValue = (String) method.invoke(o);
December 30th, 2011
Wytze
Wrote this custom NHibernate Criterion to be able to add custom SQL snippets with alias support when using criteria.
public class SqlAliasCriterion : SQLCriterion
{
private string sql;
public SqlAliasCriterion(string sql)
: base(new SqlString(sql), new string[0], new IType[0])
{
this.sql = sql;
}
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
{
string replacedString = Regex.Replace(
sql,
@"{([a-zA-Z_]((\.)?[a-zA-Z0-9_])*)}",
m =>
{
ICriteria critter = criteria.GetCriteriaByAlias(m.Groups[1].Value);
if (critter != null)
{
return criteriaQuery.GetSQLAlias(critter);
}
return m.Groups[0].Value;
}
);
return new SqlString(replacedString);
}
}
Usage example:
return Session.CreateCriteria<YourClass>("x")
.Add(new SqlAliasCriterion("{x}.YourField = SomeNativeSQLFunc(foo)"))
.List<YourClass>();
You can use the same trick to do ordering. (We use this for native MSSQL random ordering)
public class OrderBySql : Order
{
private string sql;
public OrderBySql(string sql, bool ascending)
: base(String.Empty, ascending)
{
this.sql = sql;
}
public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
string replacedString = Regex.Replace(
sql,
@"{([a-zA-Z_]((\.)?[a-zA-Z0-9_])*)}",
m =>
{
ICriteria critter = criteria.GetCriteriaByAlias(m.Groups[1].Value);
if (critter != null)
{
return criteriaQuery.GetSQLAlias(critter);
}
return m.Groups[0].Value;
}
);
return new SqlString(replacedString + (this.ascending ? " ASC" : " DESC"));
}
}
Example with random sorting (MSSQL):
criteria.addOrder(
new OrderBySql("NEWID()")
);
December 21st, 2011
Wytze
Came across this excellent presentation which covers (all?) new features of HTML5. Have a look at the html5rocks site.
December 19th, 2011
Wytze
Just a simple class I put together for easy cache handling.
public class CacheHelper
{
private static readonly ILog logger = LogManager.GetLogger(typeof(CacheHelper));
public static T CachedResult<T>(string key, Func<T> valueRetrieval, double timeout = 5)
{
T result = (T)HttpContext.Current.Cache[key];
if (result == null)
{
logger.InfoFormat("Cached item with key: {0} not found in Cache, fetching value", key);
result = valueRetrieval.Invoke();
HttpContext.Current.Cache.Insert(key, result, null, DateTime.Now.AddMinutes(timeout), Cache.NoSlidingExpiration);
}
else
{
logger.DebugFormat("Cached item with key: {0} retrieved from Cache", key);
}
return result;
}
}
Usage example:
RssFeed rssFeed = CacheHelper.CachedResult<RssFeed>(url, () => TwitterApplication.GetPublicTimelineFeed(url));
December 15th, 2011
Wytze
A friend of mine showed me the Knockout JavaScript Framework today. Seems quite promising. I love the idea of data-binding.
When putting together a new view I most often want to start from static html and add unobtrusive javascript from there to add dynamic functionality. I hope this new framework will stack well with jQuery.
December 12th, 2011
Wytze
Check out this article over here:
Spring security with the spring-security plugin for grails
Issue the following commands to add spring security to your app.
grails install-plugin spring-security-core
grails s2-quickstart your.package.name SecUser SecRole
Add the following two lines to UrlMappings.groovy:
"/login/$action?"(controller: "login")
"/logout/$action?"(controller: "logout")
I personally prefer to use annotations.
@Secured(['ROLE_USER'])
class PostController {
@Secured(['ROLE_ADMIN'])
def deletePost = { //...
}
}
Keep forgetting stuff. Too much input will cause a bufferoverflow I guess.
So here it is, some useful twitter stuff. If you won’t forget I will keep updating this post to include more and more twitter stuff.
Twitter GET search API
Twitter GET search – Search properties
Below is a short snippet that will allow you to restore your database by putting it in single user mode.
After restoring (if without errors) it will be in multi user mode again. If it is not you can still run the ‘alter database DATABASE_NAME set multi_user’ command to put it back in original mode.
USE master;
ALTER DATABASE [DATABASE_NAME] SET single_user WITH ROLLBACK immediate;
restore DATABASE [DATABASE_NAME] FROM disk = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup\YOUR_AWESOME_BACKUP.bak';