Skip to content

Instantly share code, notes, and snippets.

@Ajnasz
Ajnasz / gist:318378
Created Mar 1, 2010
YUI 2 toggleClass
View gist:318378
YAHOO.util.Dom.toggleClass = function(el, cn) {
return YAHOO.util.Dom.hasClass(el, cn) ? YAHOO.util.Dom.removeClass(el, cn) : YAHOO.util.Dom.addClass(el, cn);
};
YAHOO.util.Element.prototype.toggleClass = function(cn) {
return YAHOO.util.Dom.toggleClass(this.get('element'), cn);
};
YAHOO.util.Dom.toggleClass('elementid', 'hidden');
// or
@Ajnasz
Ajnasz / gist:435666
Created Jun 12, 2010
hide google reader watcher statusbar icon with stylish
View gist:435666
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul); /* you should not put this line into the userchrome.css if you already have it */
#GRW-statusbar {
display:none;
}
View googleclientlogin.js
var https = require('https'),
events = require('events');
const userAgent = 'GCLNodejs';
const version = 0.1;
const loginURL = '/accounts/ClientLogin';
const googleHost = 'www.google.com';
/**
* Helps to log in to any google service with the clientlogin method
View gitsvnrelocate.sh
#!/bin/sh
# Must be called with two command-line args.
# Example: git-svn-relocate.sh http://old.server https://new.server
if [ $# -ne 2 ]
then
echo "Please invoke this script with two command-line arguments (old and new SVN URLs)."
exit $E_NO_ARGS
fi
@Ajnasz
Ajnasz / bookmarklet.html
Created Jun 4, 2011
google +1 hup.hu article titles
View bookmarklet.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>A</title>
</head>
<body>
<a href="javascript:(function(){var doc=document,a=Array.prototype.slice.call(doc.querySelectorAll('h2.title a')).filter(function (a) {return a.href!==''&&a.parentNode.className!=='nnew';}),b=doc.createElement('span');a.forEach(function(l,i){var c=b.cloneNode(true),id='plusone'+i;c.id=id;a[i].parentNode.appendChild(c);gapi.plusone.render(id,{size:'small',count:true,href:l.href});});Array.prototype.slice.call(doc.querySelectorAll('.comment')).forEach(function(comment,i){var href=comment.previousSibling.previousSibling.id;if(href){var span=doc.createElement('span'),id='commentcount'+i;span.id=id;comment.querySelector('.submitted').appendChild(span);gapi.plusone.render(id,{href:doc.location.href+'#'+href,count:true,size:'small'});}});}());
">+1</a>
</body>
</html>
View require_these.js
/* override require for testing, comment it out */
var require = function (what, cb) {
console.log('request: ' + what.join(', '));
setTimeout(function () {
require.ready(cb);
}, 300);
};
require.ready = function (cb) {
cb();
};
View 1.js
(function () {
var a = ['lorem', 'ipsum', 'dolor'];
var repeat = true;
var i = 0;
var f = function () {
console.log(a[i]);
var finished = i + 1 >= a.length;
if (!finished || repeat) {
i = finished && repeat ? 0 : i + 1;
@Ajnasz
Ajnasz / cookies.js
Created Jul 25, 2011
cookies to object
View cookies.js
var a= {};document.cookie.split(';').forEach(function(c){var b = c.split('=');a[b[0]]=b[1];});
@Ajnasz
Ajnasz / git-svn-commit-rev.sh
Created Aug 30, 2011
Get svn revision number from git svn log
View git-svn-commit-rev.sh
git log --grep=... --format=format:%b | awk '/@/ {print gensub(/^.*@([0-9]+).*$/, "\\1", 1)}' | sort -n | tr '\n' ','
@Ajnasz
Ajnasz / pre-commit.jssyntax.sh
Created Oct 7, 2011
Precommit hook for git to check js syntax
View pre-commit.jssyntax.sh
#!/bin/sh
# Precommit hook to check js syntax
gitstatus=$(git st --short | awk '/^M.+js$/ {print $2}');
echo $gitstatus | while read i; do
if [ ! -z "$i" ]; then
echo "parse: $i";
output=$(js -e "parse(read('$i'))" 2>&1);
if [ ! -z "$output" ]; then