Skip to content

Instantly share code, notes, and snippets.

#####
# This config file enables 802.11/n speeds with RealTek
# 27x0 and 28x0 model pci wireless networking cards in
# Linux. Create the directory /etc/Wireless/RT2860STA/
# and name this file RT2860STA.dat to use.
#
# Originally posted:
# http://ww.ubuntuforums.org/showpost.php?p=8346399&postcount=9
#
# The word of "Default" must not be removed
<?php
function isPrime($number) {
// A prime number is only divisible by 1 and itself.
// All numbers are divisible by 1, so start with 2.
for ($div = 2; $div < $number; $div++) {
// If $number is wholly divisible by $div (no remainder).
if (($number % $div) === 0) {
// If we can evenly divide $number by anything that
// is not 1 or itself, it is not prime and we can return
<?php
$string = "My product Vol. 002 Season 03";
$new_string = preg_replace(/\b0+(?=\d+\b)/, '', $string);
?>
#!/usr/bin/env python
from urllib import urlopen, quote
url = 'http://www.example.com/example.jpg'
# Check valid url
resource = urlopen(url)
status = resource.getcode()
content_type = resource.info().get('Content-Type')
// Bind input placeholder text
$(document).ready(function() {
// Check for placeholder support
var i = document.createElement('input');
if (('placeholder' in i) == false) {
$('input[placeholder]').each(function() {
// Set initial value and class
if ($(this).val() == '' || $(this).val() == $(this).attr('placeholder')) {
$(this).val($(this).attr('placeholder')).addClass('placeholder-text');
}
@twaddington
twaddington / jquery-stickybox.js
Created March 8, 2011 02:44
Sticks an element to the top of the window after scrolling past it.
/**
* Copyright (c) 2011 Tristan Waddington <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@twaddington
twaddington / web-dev-apt.sh
Created March 28, 2011 06:31
Install web developer packages on Debian/Ubuntu using Apt.
!#/bin/bash
##
# Install requirements for Apache2, MySQL, PHP, Django, Rails
# on Debian/Ubuntu.
##
sudo apt-get install \
apache2 \
apache2-doc \
apache2-suexec \
sqlite3 \
@twaddington
twaddington / search.js
Created May 26, 2011 19:26
Search a string for a substring
function search(str1, str2) {
var i,n;
for (i=0; i<str2.length; i++) {
for (n=0; n<str1.length; n++) {
var c1 = str1.charAt(n);
var c2 = str2.charAt(i+n);
if (c1 === c2) {
if (n === (str1.length-1)) {
return i;
}
@twaddington
twaddington / naiveStringSearch.py
Created June 1, 2011 04:53
A naive string searching algorithm
def search(needle, haystack, end=False):
"""
A naive string searching function.
"""
n = len(needle)
h = len(haystack)
start = 0
offset = n
@twaddington
twaddington / csv.class.php
Created June 3, 2011 07:54
Basic class for serializing PHP arrays in a csv format.
<?php
class CSV {
protected $data;
/*
* @params array $columns
* @returns void
*/
public function __construct($columns) {
$this->data = '"' . implode('","', $columns) . '"' . "\n";