Skip to content

Instantly share code, notes, and snippets.

View jl2's full-sized avatar

Jeremiah LaRocco jl2

View GitHub Profile
function randInt(minv, maxv) {
var rv = minv + Math.floor(Math.random()*(maxv-minv));
return rv;
}
function initialize(width, height, prob) {
var life = new Array(height);
for (var i = 0; i<height; ++i) {
life[i] = new Array(width);
for (var j=0; j<width; ++j) {
-- haskell code that spits out cgm3dt javascript calls to solidblock and point to create a menger sponge.
class JSObject a where
to_js :: a -> String
class PtOffset a where
add :: a -> CgmPt -> a
data CgmPt = CgmPt {
x :: Double,
@jl2
jl2 / sourceforge.js
Created October 18, 2011 20:39
Opera user javascript to remove the stupid time delay on SourceForge downloads and start downloading immediately.
if (location.hostname.indexOf('sourceforge.net') != -1) {
window.opera.addEventListener('BeforeScript', function (e) {
e.preventDefault();
}, false);
window.opera.addEventListener('BeforeEvent.load', function (e)
{
if (e.event.target instanceof Document)
{
e.preventDefault();
var nodes = e.event.target.getElementsByClassName('direct-download');
@jl2
jl2 / catia.rb
Created October 19, 2011 22:39
Quick Ruby script to create a cube in CATIA using COM.
#!/usr/bin/ruby
require 'win32ole'
def get_catia()
catia = nil
catia = WIN32OLE.connect('CATIA.Application')
if catia == nil then
catia = WIN32OLE.new('CATIA.Application')
end
@jl2
jl2 / replace-python-region.el
Created November 10, 2011 17:45
Emacs Lisp to run the current region through Python, then replace the region with the output of the script.
(defun replace-python-exp ()
"Run the region as a Python script, kill the region, insert the output of the Python script."
(interactive)
(let* ((tmp-file (make-temp-file "tmppl"))
(rb (region-beginning))
(re (region-end))
(str (buffer-substring-no-properties rb re)))
(if (string-match "print" str)
(progn
(write-region rb re tmp-file nil 1)
@jl2
jl2 / ddg.el
Created November 11, 2011 19:11
Emacs Lisp to search for the current region on DuckDuckGo. To use, type \C-\M-g and enter a bang command or just press enter to search plain duckduckgo
(global-set-key "\C-\M-g" 'ddg-bang-search)
(defun ddg-bang-search (bang)
(interactive "s!")
(let* ((search-query (replace-regexp-in-string " " "+" (buffer-substring-no-properties (region-beginning) (region-end))))
(search-string (if (> (length bang) 0)
(concat "!" bang "+" search-query)
search-query)))
(browse-url (concat "http://duckduckgo.com/?ka=h&kh=1&kj=b2&km=m&ko=1&ks=n&kt=h&ku=-1&kv=1&kw=s&kx=e&ky=b&k1=-1&q=" search-string))))
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/SQLAlchemy-0.7.3-py3.2.egg/sqlalchemy/pool.py", line 675, in _do_get
return self._pool.get(wait, self._timeout)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/SQLAlchemy-0.7.3-py3.2.egg/sqlalchemy/util/queue.py", line 137, in get
raise Empty
sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
@jl2
jl2 / mysqlconnector.py.diff
Created November 14, 2011 04:31
Changes I made to "lib/ sqlalchemy/dialects/mysql/mysqlconnector.py" to get SQLAlchemy 0.7.3 and MySQL Connector 0.3.2-devel working together under Python 3.
79a80,81
> description_encoding = 'use_encoding'
>
116c118
< return connection.connection.get_characterset_info()
---
> return connection.connection.get_charset()
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/SQLAlchemy-0.7.3-py3.2.egg/sqlalchemy/pool.py", line 675, in _do_get
return self._pool.get(wait, self._timeout)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/SQLAlchemy-0.7.3-py3.2.egg/sqlalchemy/util/queue.py", line 137, in get
raise Empty
sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
@jl2
jl2 / .emacs
Created November 23, 2011 21:22
My .emacs and jl2_functions.el
(setq load-path (cons "~/emacs" load-path))
(setq load-path (cons "~/.emacs_stuff" load-path))
(setq load-path (cons "c:/emacs/site-lisp" load-path))
;; (setq load-path (cons "c:/emacs/site-lisp/color-theme" load-path))
(defadvice replace-string (around turn-off-case-fold-search)
(let ((case-fold-search nil))
ad-do-it))