Skip to content

Instantly share code, notes, and snippets.

View JKirchartz's full-sized avatar
🤖

Joel Kirchartz JKirchartz

🤖
View GitHub Profile
@JKirchartz
JKirchartz / nextis.js
Created April 4, 2011 14:21
Extend xuiJS with jQuery style next & is functions
x$.extend({
'next': function() {
var n = this[0];
do{n = n.nextSibling;}
while (n && n.nodeType != 1);
return x$(n);
},
'is': function(sr) {
sr = sr.toUpperCase();
var n = this[0];
@JKirchartz
JKirchartz / clearfix.css
Created April 22, 2011 13:47
CSS-only Micro Clearfix
/* For modern browsers */
.cf:before,
.cf:after {
content:"";
display:block;
overflow:hidden;
}
.cf:after {
clear:both;
######################################################
# Redirect to separate directory for mobile site
######################################################
# Don't redirect if we're already there!
RewriteCond %{REQUEST_URI} !^/mobile/.*$
# Check Cookie to (en|dis)able redirect to mobile or stay on desktop
RewriteCond %{HTTP_COOKIE} !^.*mobile.*$ [NC]
@JKirchartz
JKirchartz / xuiAccordion.html
Created April 25, 2011 16:36
XUIjs Accordion
<!DOCTYPE html>
<html>
<head>
<title>XUIaccordion Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!--[if !IE]>-->
<!-- no blackberry support if you use IE conditionals to detect browser, but this is a demo so relax -->
<script type="text/javascript" src="http://xuijs.com/downloads/xui-2.0.0.min.js"></script>
<!-- sorry for hotlinking, XUI dudes, but this is a demo so deal with it. -->
@JKirchartz
JKirchartz / blockquote.css
Created May 5, 2011 14:56
Pure CSS Blockquote decoration
blockquote:before {
content: '\201C';
height: 0;
margin-left: -0.55em;
}
blockquote:after {
content: '\201D';
height: 50px;
margin-top: -70px;
margin-left: 360px;
@JKirchartz
JKirchartz / redirect.php
Created May 11, 2011 19:13
PHP Mobile Redirect
<?php
$agents = "/(sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera mini|IEmobile|DoCoMo|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox|blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-|ipad|ipod|iphone|portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc|smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|mobile safari|android)/i";
$accepts = "/(text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml)/i";
if(preg_match($agents,$_SERVER['HTTP_USER_AGENT'])||preg_match($accepts,$_SERVER['HTTP_ACCEPT'])){
header("Location: mobile");
}
?>
@JKirchartz
JKirchartz / html2css
Created August 1, 2011 15:30
Generate a CSS document based on the content of a HTML file.
#! /usr/bin/env python
from BeautifulSoup import BeautifulSoup
import os.path
import re
def html2css(FILEsource, OUTPUT):
fname = os.path.join(os.curdir, FILEsource)
FILE, OUT = open(fname,'r'), open(OUTPUT,'w')
source, Tags_regexp, HTML, CSS = FILE.read(), "(?i)<\/?\w+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>", '', ''
IDlist, CLASSlist, TAGlist = [], [], []
@JKirchartz
JKirchartz / README.markdown
Created September 21, 2011 15:09
Mobile Redirect

Here is a simple javascript redirect that uses the [Mobile Link Discovery Spec][1] a valid markup link tag that tells the browser where to find an Alternate for Hand-Held devices.

<link rel="alternate" media="handheld" href="http://m.google.com" />

simply replace m.google.com with the url of your mobile site.

and import this script

<script type="text/javascript" src="redirect.js"></script>
@JKirchartz
JKirchartz / unique_chars.py
Created November 17, 2011 20:55
Python one-liner to print a sorted list of unique characters in a string; just change the input file from "test.html" to whatever file you need. This is great for optimizing google webfonts
print 'Unique Characters: %s' % ''.join(sorted(set(open("test.html", "r").read())))
@JKirchartz
JKirchartz / html5 notepad
Created November 26, 2011 03:28
simple html5 Notepad, saves in localStorage, but you can only have one note at a time.
<!DOCTYPE html>
<html><head><meta charset="UTF-8">
<title>HTML5 notepad app</title>
<meta charset="utf-8">
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<style>
html,body{background:#FCFCFC;color:#444;height:100%;width:100%;margin:0;padding:0;}
#notepad{height:98%;width:98%;padding:1%;font-size:100%;line-height:125%;font-family:san-serif}
::selection{background:#7D7}
::-moz-selection{background:#7D7}