Skip to content

Instantly share code, notes, and snippets.

@chrisyco
chrisyco / fixext.py
Created May 23, 2011 04:05
Recursively rename UPPERCASE filename extensions to lowercase
#!/usr/bin/env python
"""Epic script to rename scary uppercase extensions (like .JPG) to
more friendly lowercase (like .jpg).
How to use
==========
Recursively rename all files in the current directory::
fixext
@naholyr
naholyr / enableMultipleViewRoots.js
Created May 27, 2011 15:23
Allow multiple views roots in Express.js
// Usage:
// var express = require('express')
// require('enableMultipleViewRoots')(express)
module.exports = function(express) {
var old = express.view.lookup;
function lookup(view, options) {
// If root is an array of paths, let's try each path until we find the view
if (options.root instanceof Array) {
<!doctype html>
<!-- http://taylor.fausak.me/2015/01/27/ios-8-web-apps/ -->
<html>
<head>
<title>iOS 8 web app</title>
<!-- CONFIGURATION -->
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@jboner
jboner / latency.txt
Last active May 23, 2024 06:51
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@yratof
yratof / base.scss
Last active June 6, 2019 07:15
Contact Form 7 - Removing the unwanted stuff, Making it look pretty, then reading the needed stuff
/*********************
Contact Form 7 Styles -
If you want to leave these colours as they are, then do so,
otherwise, wap grey and green for your brand colours in your MIXINS file
*********************/
$dark: rgb(50,50,50);
$green: rgb(0,200,100);
div.wpcf7 {
margin: 0;
<?php
/**
* wdw_crop_img (http://webdeveloperswall.com/wordpress/crop-image-script)
* crops the image to given width and height
* Parameters :-
* $image_url : string : absolute url to the image
* $width: int : desired width after cropping
* $height : desired height after cropping
* $upload_directory : name of the target directory (directoty inside wp-content>uploads folder)
* Returns :- an array containing errors/success messages, new(cropped) file path and cropped file url
@othiym23
othiym23 / npm-upgrade-bleeding.sh
Created September 20, 2014 19:36
a safe way to upgrade all of your globally-installed npm packages
#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3)
do
npm -g install "$package"
done
@wthit56
wthit56 / .md
Last active August 29, 2015 14:17
Using Your Own Non-Templating Engine

Please read Writing Your Own Non-Templating Engine before reading this article.

Using Your Own Non-Templating Engine

In the previous article (link at the top), I showed how you can write a very simple function that will turn a given template string into something JavaScript can use. In this article, I'll go into how you can use this in practise.

The Basics

First, let's just make sure we're on the same page as to what the code is and what it does. And while we're at it, let's wrap it up in a function we can reference in later code examples: