Skip to content

Instantly share code, notes, and snippets.

@swannodette
swannodette / gist:3217582
Created July 31, 2012 14:52
sudoku_compact.clj
;; based on core.logic 0.8-alpha2 or core.logic master branch
(ns sudoku
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
@baopham
baopham / apache.md
Created June 5, 2012 17:14
Apache notes

To set up a new domain name

$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mynewsite
  • Change the line DocumentRoot /var/www/ to DocumentRoot /var/www/mynewsite

  • Create an alias in /etc/apache2/sites-enabled:

@I82Much
I82Much / Scramble Solver Output.txt
Created May 30, 2012 05:27
Scramble Solver Output
FoundWord(word='a', locations=[Location(row=2, col=0)])
FoundWord(word='al', locations=[Location(row=2, col=0), Location(row=1, col=1)])
FoundWord(word='alice', locations=[Location(row=2, col=0), Location(row=1, col=1), Location(row=2, col=2), Location(row=2, col=3), Location(row=3, col=2)])
FoundWord(word='alien', locations=[Location(row=2, col=0), Location(row=1, col=1), Location(row=2, col=2), Location(row=3, col=2), Location(row=3, col=3)])
FoundWord(word='alin', locations=[Location(row=2, col=0), Location(row=1, col=1), Location(row=2, col=2), Location(row=3, col=3)])
FoundWord(word='aline', locations=[Location(row=2, col=0), Location(row=1, col=1), Location(row=2, col=2), Location(row=3, col=3), Location(row=3, col=2)])
FoundWord(word='alit', locations=[Location(row=2, col=0), Location(row=1, col=1), Location(row=2, col=2), Location(row=2, col=1)])
FoundWord(word='alite', locations=[Location(row=2, col=0), Location(row=1, col=1), Location(row=2, col=2), Location(row=2, col=1), Location(row=3, col=2)])
F
@baopham
baopham / modal.html
Created May 28, 2012 19:35
Popup form -JQuery UI
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.20/themes/base/jquery-ui.css" type="text/css" media="all" />
<link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" />
<style>
body { font-size: 62.5%; }
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; }
fieldset { padding:0; border:0; margin-top:25px; }
@esmooov
esmooov / ctrr.md
Created May 25, 2012 16:50
Carats and Tildes, Resets and Reverts

Until last night I lived in fear of tildes, carats, resets and reverts in Git. I cargo culted, I destroyed, I laid waste the tidy indicies, branches and trees Git so diligently tried to maintain. Then Zach Holman gave a talk at Paperless Post. It was about Git secrets. He didn't directly cover these topics but he gave an example that made me realize it was time to learn.

A better undo

Generally, when I push out bad code, I panic, hit git reset --hard HEAD^, push and clean up the pieces later. I don't even really know what most of that means. Notational Velocity seems to be fond of it ... in that I just keep copying it from Notational Velocity and pasting it. Turns out, this is dumb. I've irreversibly lost the faulty changes I made. I'll probably even make the same mistakes again. It's like torching your house to get rid of some mice.

Enter Holman. He suggests a better default undo. git reset --soft HEAD^. Says it stag

@nijikokun
nijikokun / example-user.js
Created May 3, 2012 20:46
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
);
@psobot
psobot / randomthumbs.rb
Created April 22, 2012 00:49
Random Image Thumbnailer
# Hacky random image thumbnailer.
# by Peter Sobot, April 21, 2012
# Based heavily on code by Michael Macias
# (https://gist.github.com/a54cd41137b678935c91)
require 'rmagick'
images = Dir.glob(ARGV[0] ? ARGV[0]
: '-default-input-paths-')
output_dir = (ARGV[1] ? ARGV[1]
@baopham
baopham / mobile-redirect.mkd
Created April 11, 2012 22:29
Mobile Redirect js Snippets

Redirect Mobile Devices

<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "mobile.html";
}
//-->
@baopham
baopham / .osx
Created April 4, 2012 17:45
Defaults commands for OSX
# GistID: 2304197
# Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Enable subpixel font rendering on non-Apple LCDs
defaults write NSGlobalDomain AppleFontSmoothing -int 2
# Enable the 2D Dock
defaults write com.apple.dock no-glass -bool true
@baopham
baopham / git_commands.md
Created February 23, 2012 19:32
git commands notes

To delete a commit

Assuming you are sitting on that commit

git reset --hard HEAD~1

Or