Skip to content

Instantly share code, notes, and snippets.

View NV's full-sized avatar

Nikita Vasilyev NV

View GitHub Profile
<html>
<h1 class=title id=head>Quack-Quack!</h1>
<p>
Quack
<span>quack</span>
quack!
</p>
</html>
@NV
NV / gist:128192
Created June 11, 2009 20:01
'foo bar'. Guess why?
var foo = function(bar) {
console.log("foo");
return bar;
}
(function(){
console.log("bar")
})();
// 'foo bar'
var request = new XMLHttpRequest;
request.open('POST', 'http://twitter.com/statuses/update.json', false, 'username','password');
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send('status=Quack-quack!');
curl -u username:password -d status="Quack-quack!" http://twitter.com/statuses/update.json
a=['first', 'last'];
a[-1] == null;
a[-1] = a[a.length-1];
a[-1] == 'last'
@NV
NV / pythons_ugly_re.py
Created September 12, 2009 11:49
Why result cannot be accessed like array?
result = re.search(r"#[a-f0-9]{3}", 'Roses are #f00')
result.group(0) == '#f00' # True
result[0] # Damn! TypeError: '_sre.SRE_Match' object is unsubscriptable
# Why result cannot be accessed like array?
window.addEventListener('load', function(){
//Works in Opera
//Doesnt' work in Greasemonkey
alert('window')
}, false)
window.wrappedJSObject.addEventListener('load', function(){
//Doesn't work in Opera
//Works in Greasemonkey. See http://wiki.greasespot.net/UnsafeWindow
alert('wrappedJSObject')
// this gist is response to http://dmitry.baranovskiy.com/post/201475166
// Code by Dmitry Baranovskiy
var w=window,e=w.addEventListener,v=w.attachEvent;e&&e("load",a,!1);v&&v("onload",a);google.timers.load.t.prt=+new Date;
// Mine optimization. 4 characters less!
window[/*@cc_on'attachEvent'||@*/'addEventListener'](/*@cc_on'on'+@*/'load',a,0);google.timers.load.t.prt=+new Date;
// I found /*@cc_on @*/ trick at http://lusever.livejournal.com/43326.html
@NV
NV / String.insert.js
Created October 6, 2009 17:53
JavaScript implementation Ruby's str.insert method
/**
* 'Hello world'.insert(6, 'happy ') == 'Hello happy world'
* 'Hello world'.insert(-1, '!!!') == 'Hello world!!!'
* @param at {Number} index
* @param text {String}
* @see http://ruby-doc.org/core/classes/String.html#M000773
*/
String.prototype.insert = function (at, text) {
if (at < 0) {
at += this.length + 1;
@NV
NV / .htaccess
Created October 13, 2009 10:37
Apache .htaccess
DirectoryIndex index.html index.htm index.xhtml index.xml index.php
AddType message/rfc822 mht
AddType application/octet-stream safariextz
AddType application/atom+xml atom
AddType application/msword doc
AddType application/opensearchdescription+xml osd
AddType application/pdf pdf
AddType application/rdf+xml rdf
AddType application/rss+xml rss