Skip to content

Instantly share code, notes, and snippets.

@romannurik
romannurik / background-page.html
Created September 24, 2009 05:15
A workaround for Cross-domain XHR's not working in Chrome Extensions' content scripts. See http://groups.google.com/group/chromium-extensions/browse_thread/thread/43ec4d383cf8d01d
<!DOCTYPE html>
<html>
<head>
<script src="xhrproxy.js"></script>
<script>
setupXHRProxy();
</script>
</head>
// http://earth-api-samples.googlecode.com/svn/trunk/demos/geolocation/location.js
/**
* Watches the user's current location, continually calling the successCallback
* with a Gears Coords-like object (latitude, longitude, accuracy) or
* errorCallback with an error object. The second argument to successCallback
* will be the location provider, i.e. 'gears', 'html5', or 'ip'.
*/
function watchLocation(successCallback, errorCallback, ipFallback) {
successCallback = successCallback || function(){};
#
#
#
# MOVED TO http://code.google.com/p/romannurik-code/source/browse/misc/bash_completion/adb
#
#
#
function _adb()
@romannurik
romannurik / cdg.sh
Created February 27, 2010 22:12
cdg directory navigation scripts + bash completion
# cdg command
# A smarter cd, works well with up: http://daniele.livejournal.com/76011.html
# Help: cdg -h
# Show all links: cdg
# Delete link: cdg -d foo
# Clear all: cdg -c
# Store link to working directory: cdg -w foo
# Go to link: cdg foo
function cdg() {
// ==ClosureCompiler==
// @output_file_name google-buzz-bookmarklet.js
// @compilation_level SIMPLE_OPTIMIZATIONS
// ==/ClosureCompiler==
// Buzz API - Buttons: http://code.google.com/apis/buzz/buttons_and_gadgets.html#post_to_google_buzz
// Closure Compiler Service: http://closure-compiler.appspot.com/home
(function(){
var url = window.location.href;
<!DOCTYPE html>
<html>
<head>
<title>SVG/Canvas/toDataURL bug</title>
<script src="http://javascriptbase64.googlecode.com/svn/trunk/base64.js"></script>
<style>
img { border: 3px solid red; }
canvas { border: 3px solid blue; }
</style>
</head>
@romannurik
romannurik / DashboardLayout.java
Created March 23, 2011 05:06
A custom Android layout class that arranges children in a grid-like manner, optimizing for even horizontal and vertical whitespace.
/*
* ATTENTION:
*
* This layout is now maintained in the `iosched' code.google.com project:
*
* http://code.google.com/p/iosched/source/browse/android/src/com/google/android/apps/iosched/ui/widget/DashboardLayout.java
*
*/
/*
@romannurik
romannurik / antialias_this_on_win_and_linux.html
Created April 6, 2011 01:45
For some reason, Canvas.drawImage, with scaling, doesn't result in good anti-aliasing (ideally bicubic resampling) in browsers on Windows and Linux. On Mac, it looks great. Can this be fixed?
<!DOCTYPE html>
<html>
<head>
<style>
/* doesn't work */
img, canvas {
image-rendering: optimizeQuality;
}
</style>
</head>
@romannurik
romannurik / centered_triangle.html
Created May 3, 2011 05:43
A simple CSS trick to create a horizontally- or vertically-centered 'selected' callout triangle using zero images.
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 40px;
}
a {
display: inline-block;
@romannurik
romannurik / android_layout.xml
Created May 7, 2011 22:29
Center-crop scaling, ala scaleType=centerCrop in Android, using CSS3's object-fit property. Opera only for now.
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="centerCrop"
android:src="@drawable/foo" />