Skip to content

Instantly share code, notes, and snippets.

@purplejacket
purplejacket / selenium_hello.rb
Created January 26, 2011 22:22
A Selenium "hello world" program to be run in Ruby
require File.dirname(__FILE__) + '/../test_helper'
require "selenium/client"
class HelloTest < ActiveSupport::TestCase
def setup
@verification_errors = []
@selenium = Selenium::Client::Driver.new \
:host => "localhost",
:port => 4444,
:browser => "*safari",
@purplejacket
purplejacket / main_controller.rb
Created February 11, 2011 23:17
attempt at returning a 500 error if the params hash has a nil value
# Is this the proper way to detect whether any of the params has a nil value?
# I think it's being superseded by the before_filter because I see
# /Users/kaimiddleton/Sites/thundercat/vendor/plugins/fixie_whitelister/lib/white_list_helper.rb:34:in `strip_naughty_stuff'
# when I hit the browser with, say, http://localhost:3000/?/
class MainController < ApplicationController
skip_before_filter :require_restrictive_access
before_filter :main_sidebar, :only => [:index, :landing_page]
def index
@purplejacket
purplejacket / quine.php
Created February 15, 2011 23:12
A quine in PHP language
<?
# PHP Quine written by Ian Kjos - [email protected]
$y = "function q(\$q) {
\$q = str_replace('\\\\', '\\\\\\\\', \$q);
\$q = str_replace('\$', '\\\\\$', \$q);
\$q = str_replace('\\n', '\\\\n', \$q);
\$q = str_replace('\"', '\\\\\"', \$q);
return \$q;
}
@purplejacket
purplejacket / Picture1.rb
Created August 23, 2011 21:43
Picture class without S3 authentication
class Ckeditor::Picture < Ckeditor::Asset
has_attached_file :data,
:url => "/ckeditor_assets/pictures/:id/:style_:basename.:extension",
:path => ":rails_root/public/ckeditor_assets/" +
"pictures/:id/:style_:basename.:extension",
:styles => {:content => '800>', :thumb => '118x100#'}
# etc....
end
@purplejacket
purplejacket / halting.js
Last active November 23, 2021 01:28
Fermat's last theorem - halting problem
// Theory of computation: halting problem: will the following program ever halt?
outer_loop:
for (let bound=3; ; bound++)
for (let n=3; n<=bound; n++)
for (let a=1; a<=bound; a++)
for (let b=1; b<=bound; b++)
for (let c=1; c<=bound; c++)
if (a**n + b**n == c**n)
break outer_loop;
@purplejacket
purplejacket / Stack.java
Last active October 24, 2018 15:53
An implementation of a stack in java ... but with a bug in it
import java.util.*;
public class Stack {
private Object[] elements;
private int size = 0;
public Stack(int initialCapacity) {
this.elements = new Object[initialCapacity];
}
@purplejacket
purplejacket / Gull.cpp
Created May 1, 2014 01:43
Gull Chess version 3.0 by Vadim Demichev, released April 17, 2014
#define W32_BUILD
#undef W32_BUILD
#ifdef W32_BUILD
#define NTDDI_VERSION 0x05010200
#define _WIN32_WINNT 0x0501
#endif
#ifndef W32_BUILD
#define HNI
@purplejacket
purplejacket / micromax.c
Created May 1, 2014 02:06
MicroMax v. 4.0, by Harm Geert Muller - a chess program in under 2000 characters of C code -- see http://home.hccnet.nl/h.g.muller/progress.html
/***************************************************************************/
/* micro-Max, */
/* A chess program smaller than 2KB (of non-blank source), by H.G. Muller */
/***************************************************************************/
/* version 4.0 (1752 characters) features: */
/* - recursive negamax search */
/* - quiescence search with recaptures */
/* - recapture extensions */
/* - (internal) iterative deepening */
/* - best-move-first 'sorting' */
@purplejacket
purplejacket / apply.core.clj
Created April 1, 2015 23:53
The Clojure apply function
(defn apply
"Applies fn f to the argument list formed by prepending intervening arguments to args."
{:added "1.0"
:static true}
([^clojure.lang.IFn f args]
(. f (applyTo (seq args))))
([^clojure.lang.IFn f x args]
(. f (applyTo (list* x args))))
([^clojure.lang.IFn f x y args]
(. f (applyTo (list* x y args))))
@purplejacket
purplejacket / css_positioning_divs.html
Created November 17, 2015 18:46
Learn CSS Positioning in Ten Steps
<div id="example">
<div id="div-before">
<p>id = div-before</p>
</div>
<div id="div-1">
<div id="div-1-padding">
<p>id = div-1</p>
<div id="div-1a">
<p>id = div-1a</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer pretium dui sit amet felis. Integer sit amet diam. Phasellus ultrices viverra velit.</p>