Skip to content

Instantly share code, notes, and snippets.

@Jach
Jach / gist:6b82fb57bf0bc13937be
Last active August 29, 2015 14:03
REPL commands using clj-webdriver to get my tweets
; See revision version 1 for non-phantomJS version, setup phantomJS here: http://blog.zolotko.me/2012/12/clojure-selenium-webdriver-and-phantomjs.html
(use 'clj-webdriver.taxi)
(import 'org.openqa.selenium.phantomjs.PhantomJSDriver
'org.openqa.selenium.remote.DesiredCapabilities)
(use '[clj-webdriver.driver :only [init-driver]])
; skip this section until 'lawl' comment
(use '[clj-webdriver.core :only [execute-script*]])
@Jach
Jach / .vimrc
Last active August 29, 2015 14:04
My master .vimrc. It needs to be cleaned up, but meh.
nnoremap <F2> :set invpaste paste?<CR>
imap <F2> <C-O><F2>
set pastetoggle=<F2>
set incsearch
set ignorecase
set smartcase
set scrolloff=2
set wildmode=longest,list
set showcmd
@Jach
Jach / .htaccess
Created January 5, 2011 02:49
micro-framework pieces
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|imgs|js|css|flex|public|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
@Jach
Jach / encryption.py
Created June 8, 2011 06:53
Caesar, ROT13 encryption/decryption
import collections
import string
def rotate(lst, amount):
items = collections.deque(lst)
items.rotate(amount)
return items
def rotate_str(str, amount):
return ''.join(rotate(str, amount))
@Jach
Jach / crab_canon.mxml
Created June 11, 2011 13:51
crab canon helper/maker
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">
<s:layout>
<s:VerticalLayout paddingLeft="10" paddingRight="10" paddingBottom="10" paddingTop="10" />
</s:layout>
<fx:Declarations>
</fx:Declarations>
<s:TextArea id="norm" change="alter();" width="100%" height="100%" />
@Jach
Jach / pw.sh
Created July 1, 2011 13:43
Random password generator, remember a passphrase + unique key (such as sitename)
#!/bin/sh
# Prints out (highly likely at least) 64 random characters, along with some truncations for common password length limits.
# Shows random characters in the printable set as well as just alpha-numeric.
# get rid of -s flag if you want to see what you type
# (possible enhancement for people who typo a lot: read into $p2 as well and only proceed if the entries are equal.)
read -s p
hash=`echo -n $p | sha256sum | sed -e 's/-//' | sed -e 's/ //'`
hash=`python -c "import random, sys, struct; random.seed(0x$hash); bits=[random.getrandbits(64) for i in range(200)]; sys.stdout.write(struct.pack('Q'*len(bits), *bits)); print"`
hash2=`echo $hash | tr -cd "[:graph:]" | head -c ${1:-64}`
@Jach
Jach / NetworkServiceImpl1.java
Created August 4, 2011 19:02
Coding style comparison...
// ....
public RepositoryHolder getRepositories() throws AppException {
final String query = "select id, repo_url from localdb.sys_network.repositories";
List<Repository> repo_list = new ArrayList<Repository>();
Repository master = new Repository();
DB.execute(query, master, repo_list);
RepositoryHolder ret = new RepositoryHolder();
ret.repositories = repo_list;
@Jach
Jach / gist:1448054
Created December 8, 2011 18:58
Stuff from LOL translated into Clojure
; listing 1.4: group
(defn group [coll n]
(if (zero? n)
(throw (Exception. "zero length"))
(partition-all n coll)))
; listing 1.5: flatten
; built-in
; listing 1.6: fact-and-choose
@Jach
Jach / clipboard.py
Created December 21, 2011 13:32
System clipboard getter/setter
# Is this a stupid pattern?
def clipboard(text=None):
'''
Given no argument, returns the contents of the system clipboard or
None if empty.
Given an argument string, sets that as the value of the system clipboard and
returns the given string.
Note: The presence of calling this function will result in the system
clipboard being flushed on program termination.
@Jach
Jach / ai.clj
Created March 16, 2012 14:52
Recursive self-improving AI!
; pro-tip: run "java -jar clojure.jar ai.clj >> ai.clj" for infinite fun!
(println ((fn [x y] (list (quote println) (list x (list (quote quote) x) (inc y)))) (quote (fn [x y] (list (quote println) (list x (list (quote quote) x) (inc y))))) 1))