Skip to content

Instantly share code, notes, and snippets.

View niftylettuce's full-sized avatar

niftylettuce

View GitHub Profile
@gruber
gruber / Liberal Regex Pattern for All URLs
Last active November 4, 2024 20:04
Liberal, Accurate Regex Pattern for Matching All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:[email protected]", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
@mathiasbynens
mathiasbynens / jquery.insertAtCaret.js
Created March 9, 2010 11:13
jQuery insertAtCaret plugin
// I found this somewhere on the intertubes, and optimized it
$.fn.insertAtCaret = function(myValue) {
return this.each(function() {
var me = this;
if (document.selection) { // IE
me.focus();
sel = document.selection.createRange();
sel.text = myValue;
me.focus();
} else if (me.selectionStart || me.selectionStart == '0') { // Real browsers
#!/usr/bin/perl
#
# Eric Jiang
# http://notes.ericjiang.com/posts/54
# This software is public domain.
#
# NOTE: This code is not maintained!
# There is a newer version written in C:
# https://github.com/erjiang/usbscale
#
@logicplace
logicplace / gist:951220
Created May 2, 2011 05:54
email validation regex. Complete to spec. Requires a lookarounds (trying to remove the lookbehind for JS compatibility)
^(?!\.)(([a-zA-Z0-9!#$%&'*+/=?^_`{}|~\-]|\.(?!\.))+|"[^"\n\r]+")(?<!\.)([+\-][a-zA-Z0-9!#$%&'*+/=?^_`{}|~\-.]+)?@(\[(?:[0-9]{1,3}\.){3}[0-9]{1,3}\]|[a-zA-Z][a-zA-Z\-$_@.&+!*"'(),]*)$
@priithaamer
priithaamer / useragent.js
Created July 15, 2011 21:07 — forked from terkel/jquery.ua.js
Node.js User-Agent parser
// Based on fantastic jQuery useragent parser plugin https://gist.github.com/373298
function parse(uaStr) {
var agent = {
platform: {},
browser: {},
engine: {}
};
var ua = uaStr,
p = agent.platform,
@flockonus
flockonus / app.js
Created September 6, 2011 18:14
An Express app that should integrate to socket.io
/**
* Module dependencies.
*/
var express = require('express');
var app = module.exports = express.createServer();
io = require('socket.io').listen(app),
@changemewtf
changemewtf / vim-html5tags.diff
Created September 30, 2011 20:46
Add new HTML5 tags to vim indent & syntax files.
diff -r ba9f075a347d runtime/indent/html.vim
--- a/runtime/indent/html.vim Sun Aug 28 16:02:28 2011 +0200
+++ b/runtime/indent/html.vim Sun Aug 28 11:57:32 2011 -0400
@@ -76,7 +76,6 @@
call <SID>HtmlIndentPush('object')
call <SID>HtmlIndentPush('ol')
call <SID>HtmlIndentPush('optgroup')
-" call <SID>HtmlIndentPush('pre')
call <SID>HtmlIndentPush('q')
call <SID>HtmlIndentPush('s')
@tj
tj / routes.js
Created October 15, 2011 00:23
Express routes
var app = require('../app');
console.log();
app.routes.all().forEach(function(route){
console.log(' \033[90m%s \033[36m%s\033[0m', route.method.toUpperCase(), route.path);
});
console.log();
process.exit();
@dalethedeveloper
dalethedeveloper / gist:1503252
Created December 20, 2011 21:00
Mobile Device Detection via User Agent RegEx

#Mobile Device Detection via User Agent RegEx

Yes, it is nearly 2012 and this exercise has been done to death in every imaginable language. For my own purposes I needed to get the majority of non-desktop devices on to a trimmed down, mobile optimized version of a site. I decided to try and chase down an up-to-date RegEx of the simplest thing that could possibly work.

I arrived at my current solution after analyzing 12 months of traffic over 30+ US based entertainment properties (5.8M+ visitors) from Jan - Dec 2011.

The numbers solidified my thoughts on the irrelevancy of including browsers/OSes such as Nokia, Samsung, Maemo, Symbian, Ipaq, Avant, Zino, Bolt, Iris, etc. The brass tacks of the matter is that you certainly could support these obscure beasts, but are you really going to test your site on them? Heck, could you even find one?! Unless the folks that pay you are die hard Treo users my guess is "No".

Interestingly enough my research shows that /Mobile/ is more efficient than **/iP(

@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a