Skip to content

Instantly share code, notes, and snippets.

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
View jafov-demo.js
$(document).ready(function () {
// add custom method
$.yafov.addMethod('[type="tel"]', 'telfoobar', function (value, element, cb) {
// imagine that this is an ajax call, and the function is the callback
setTimeout(function () {
var isValid = value !== '123';
cb(isValid);
}, 1000);
});
$.yafov.setMessage('telfoobar', 'value shouldn\'t be 123');
@Ajnasz
Ajnasz / foo.js
Created Dec 24, 2011
doctorjs bug example
View foo.js
var Foo = function () {};
exports.Foo = Foo;