Skip to content

Instantly share code, notes, and snippets.

View kares's full-sized avatar
💤

Karol Bucek kares

💤
View GitHub Profile
/**
* A helper for embedding gists from http://gist.github.com/
* @param args the gist to embed full URL or ID only
* - asyncLoad - will load gist via ajax (non-blocking)
* - loadHTML - the HTML to use while gist is not loaded
* - removeStyleLink removes the embedded css link (useful
* for custom gist styling)
*/
function embedGist(args) {
if ( ! args ) throw 'no arguments given';
@kares
kares / FileGlob.groovy
Created February 21, 2010 13:45
Globbing implemented in Groovy
// Licensed under the "Apache License, Version 2.0" (c) 2010
/**
* Returns filenames found by expanding the passed pattern which is String or
* a List of patterns.
* NOTE: that this pattern is not a regexp (it’s closer to a shell glob).
* NOTE: that case sensitivity depends on your system.
*
* <code>*</code> Matches any file. Can be restricted by other values in
* the glob pattern (same as <code>.*</code> in regexp).
* <code>*</code> will match all files,
@kares
kares / FileGlobExample.groovy
Created February 24, 2010 14:29
Gist '310321' globbing example
// all .jsp and .jspf not starting with '_'
def jsps = File.glob( "**/[^_]*.js{p|pf}" )
@kares
kares / removeGistStyleLink.js
Created March 2, 2010 11:05
loaded callback for script.js
@kares
kares / dirty_memento.rb
Created March 31, 2010 13:46
ActiveRecord::Dirty memoized
# Extension of the ActiveRecord's Dirty module to enable
# tracking changes even after the record has been saved
# (as ActiveRecord's dirty changes are emptied on save).
#
# User.send :include, DirtyMemento
#
# user = User.find_by_name 'kares'
#
# assert ! user.name_changed?
@kares
kares / pom.xml
Created April 5, 2010 16:51
WebLogic MBean Maker - Maven Build Example
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--
Oracle WebLogic MBean Maker Maven Sample Build
- {weblogic.home} should point to the server installation
- {bea.modules} is expected to hold the weblogic "shared" jars
- sources are expected to live under 'src' folder
- the src folder is expected to contain the SampleAsserter.xml
@kares
kares / jquery.linkselect.js
Created April 21, 2010 09:49
extension of jQuery linkselect plugin to enable { yPosition: 'top' } positioning
/*!
* Linkselect jQuery Plug-in
*
* Copyright 2008 Giva, Inc. (http://www.givainc.com/labs/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@kares
kares / acts_as_commentable.rb
Created April 24, 2010 18:07
acts_as_commentable for ActiveRecord
# ActsAsCommentable
module Commentable #:nodoc:
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_commentable
has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at ASC'
@kares
kares / getTimeZoneOffsetDST.js
Created April 28, 2010 18:43
same as Date.getTimezoneOffset() but with DST
/**
* Calculate the time zone offset with DST !
* e.g. Prague - if DST enabled ? -60 (summer) : -120 (winter)
*
* NOTE: this is to be compatible to how Rails helper
* time_zone_options_for_select renders zones e.g. :
* - in summer (GMT+01:00) Prague
* - in winter (GMT+02:00) Prague
*/
function getTimeZoneOffsetDST() {
@kares
kares / jquery.klass.js
Created April 30, 2010 11:02
the jQuery $.klass plugin extracted from the low-pro plugin
/**
* $.klass is a full port of Prototype's Class.create !
*
* This code is based on the jQuery port of the Low Pro behavior framework
* that was originally written for Prototype.
* @see http://github.com/danwrong/low-pro-for-jquery
*/
(function($) {
var addMethods = function(source) {