Skip to content

Instantly share code, notes, and snippets.

@metaphox
metaphox / Default (OSX).sublime-keymap
Last active October 10, 2015 21:48
sublime text 2 settings
[
{
"keys": ["alt+w"],
"command": "toggle_setting",
"args":
{
"setting": "word_wrap"
}
}
]
@metaphox
metaphox / example-user.js
Created May 5, 2012 14:42 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@metaphox
metaphox / vim7.3_mac_install.rb
Created April 24, 2012 23:46 — forked from sirupsen/vim7.3_mac_install.rb
Script to install Vim 7.3 with ruby support for Mac OS X Lion
# requires root permissions in /usr/bin/
star = String.new
8.times { star += "*" }
Star = "\n#{star * 3}\n"
def newblock string
puts "\n#{Star}#{string}#{Star}\n"
end
@metaphox
metaphox / terminwatch.py
Created April 15, 2012 23:28
watch shanghai german consulate termin
#!/usr/bin/env python
#-*- coding: utf-8 -*-#
import smtplib, time, urllib2
from bs4 import BeautifulSoup
from email.mime.text import MIMEText
def mailme(message):
msg = MIMEText(message)
msg['Subject'] = 'German Consu Termin!'
msg['From'] = '[email protected]'
@metaphox
metaphox / Importing posts from Wordpress into Jekyll.rb
Created February 26, 2012 10:31 — forked from vitobotta/Importing posts from Wordpress into Jekyll.rb
The script I used to import posts from my Wordpress blog into a new Jekyll one.
%w(rubygems sequel fileutils yaml active_support/inflector).each{|g| require g}
require File.join(File.dirname(__FILE__), "downmark_it")
module WordPress
def self.import(database, user, password, table_prefix = "wp", host = 'localhost')
db = Sequel.mysql(database, :user => user, :password => password, :host => host, :encoding => 'utf8')
%w(_posts _drafts images/posts/featured).each{|folder| FileUtils.mkdir_p folder}
// Helper function, used below.
// Usage: ['img1.jpg','img2.jpg'].remove('img1.jpg');
Array.prototype.remove = function(element) {
for (var i = 0; i < this.length; i++) {
if (this[i] == element) { this.splice(i,1); }
}
};
// Usage: $(['img1.jpg','img2.jpg']).preloadImages(function(){ ... });
// Callback function gets called after all images are preloaded
@metaphox
metaphox / gist:1755841
Created February 6, 2012 23:23
General principles for good URI design
General principles for good URI design:
Don't use query parameters to alter state
Don't use mixed-case paths if you can help it; lowercase is best
Don't use implementation-specific extensions in your URIs (.php, .py, .pl, etc.)
Don't fall into RPC with your URIs
Do limit your URI space as much as possible
Do keep path segments short
Do prefer either /resource or /resource/; create 301 redirects from the one you don't use
Do use query parameters for sub-selection of a resource; i.e. pagination, search queries
@metaphox
metaphox / normalized.html
Created January 23, 2012 10:03 — forked from scottkellum/normalized.html
pixel normalization
<!doctype html>
<html>
<head>
<!-- Encoding -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"></meta>
@metaphox
metaphox / gist:1644401
Created January 20, 2012 01:34
Fixing the postgresql initdb fatal shared memory error on Leopard
Fixing the postgresql initdb fatal shared memory error on Leopard
Published Tue 18 December 2007 11:09 (+1300)
Tagged
software (43 posts and 3 photos)
mac os x (6 posts)
When doing the post-install setup of postgresql default database using initdb, you may hit this error:
FATAL: could not create shared memory segment: Cannot allocate memory
DETAIL: Failed system call was shmget(key=1, size=1646592, 03600).
@metaphox
metaphox / tryme.bf
Created January 11, 2012 16:18
yes, repl.it haz unicode, luke.
++[>++++++++++[>++++++++++[>++++++++++[>++++++++++<-]<-]<-]<-]>+++++[>++++++++++[>++++++++++[>++++++++++<-]<-]<-]>>++++++++++[>++++++++++<-]>+++++.<<<++++[>++++++++++[>++++++++++[>++++++++++<-]<-]<-]>++[>++++ ++++[>++++++++<-]<-]>>.>+++++++++[>++++++++++[>++++++++++[>++++++++++<-]<-]<-]+++++++++[>+++++++++<-]>[>>-<<-]>>------[<<<<->>>>-]<<<<.