Skip to content

Instantly share code, notes, and snippets.

@visnup
visnup / dabblet.html
Last active August 29, 2015 14:07
Untitled
<input type="number" pattern="\d+" />
@visnup
visnup / index.html
Created December 19, 2014 22:05
simple test case for closed issue in fastclick https://github.com/ftlabs/fastclick/issues/23, but not fixed in angular-touch
<html ng-app='test'>
<head>
<title>touch test</title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
<style>
button {
width: 100%;
-webkit-tap-highlight-color: transparent;
}
</style>
@visnup
visnup / curl.txt
Created January 11, 2015 21:59
first example I've seen of ipv6 working in the real world: google ads being smarter than my blocking hosts file
$ curl -v http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js 2>&1 | less
* Hostname was NOT found in DNS cache
* connect to 127.0.0.1 port 80 failed: Connection refused
* Trying 2607:f8b0:4010:801::100d...
* Connected to pagead2.googlesyndication.com (2607:f8b0:4010:801::100d) port 80 (#0)
> GET /pagead/js/adsbygoogle.js HTTP/1.1
> User-Agent: curl/7.37.1
> Host: pagead2.googlesyndication.com
> Accept: */*
@visnup
visnup / sudoku.js
Last active August 29, 2015 14:17
sudoku solver
var _ = require('lodash');
var hard = [ '6 2 3 ',
' 2 7 8',
' 9 4 ',
' 6 3 ',
'8 1',
' 7 4 ',
' 6 9 ',
'4 3 2 ',
@visnup
visnup / index.html
Last active August 29, 2015 14:18
angular directive for frozen columns
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" type="text/css" />
<style type="text/css">
.table-frozen {
position: relative;
}
.table-frozen .col-frozen {
background-color: white;
}
</style>
@visnup
visnup / gi
Last active August 29, 2015 14:28
like `git`, but for typos (e.g. `gi tbranch -a`)
#!/bin/sh
# like `git`, but for typos (e.g. `gi tbranch -a`)
git "${1:1}" "${@:2}"
@visnup
visnup / date_time_selector_with_meridian.rb
Created December 14, 2008 20:14
Time select elements in rails use 0-23 for the hour. I'm used to 1-12 AM/PM.
#
# <%= form.select_time :start, :meridian => true %>
#
module ActionView
module Helpers
class DateTimeSelector
def select_time_with_meridian
html = select_time_without_meridian
if @options[:meridian]
id = input_id_from_type(:hour)
@visnup
visnup / more dynamic object literals.js
Created December 19, 2008 23:17
dynamic js object literals
// a helper function to create more dynamic object literals
// $h('key'+i, value) => { key1: value }
var $h = function() {
var constructor = function() {
var k = null, args = arguments[0];
for (var i = 0; i < args.length; i++) {
if (k == null) {
k = args[i];
} else {
this[k] = args[i];
@visnup
visnup / in place edit that doesn't submit.js
Created December 20, 2008 22:53
an in place editor that doesn't submit
var editor = new Ajax.InPlaceEditor('chart_name', '', {
okControl: false,
cancelControl: false,
submitOnBlur: true,
highlightcolor: 'transparent'
});
// override the bound submit handler function to prevent
// the control from actually submitting to a url and instead
// do something more useful with the edit.
editor._boundSubmitHandler = function(e) {
@visnup
visnup / validates_length_of_less_than_max_allowed_packet.rb
Created December 21, 2008 03:31
validates_length_of_less_than_max_allowed_packet
def self.max_allowed_packet
r = connection.execute "SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'"
r.fetch_row.last.to_i rescue 128.megabytes
end
validates_length_of :data, :in => 1 .. max_allowed_packet,
:allow_blank => true
validates_length_of :file, :in => 1 .. max_allowed_packet,
:allow_blank => true