Skip to content

Instantly share code, notes, and snippets.

View edbond's full-sized avatar
🗽
Working from home

Eduard Bondarenko edbond

🗽
Working from home
View GitHub Profile
@edbond
edbond / mp3_dups.clj
Created February 24, 2011 21:17
mp3 duplicate search
(ns mp3dups.core
(:import (org.apache.commons.io FileUtils)
(java.io File)
(org.jaudiotagger.audio AudioFileIO)
(org.jaudiotagger.tag FieldKey)))
;; mp3data hash
;; [artist, title] -> mp3 filename
(def mp3data (atom {}))
@edbond
edbond / output
Created November 27, 2010 17:21
solution to euler 18 problem
problem18> (solve)
14 [4 62 98 27 23 9 70 98 73 93 38 53 60 4 23] [63 66 4 68 89 53 67 30 73 16 69 87 40 31]
13 (125 164 102 95 112 123 165 128 166 109 122 147 100 54) [91 71 52 38 17 14 91 43 58 50 27 29 48]
12 (255 235 154 150 140 179 256 209 224 172 174 176 148) [70 11 33 28 77 73 17 78 39 68 17 57]
11 (325 246 187 178 256 329 273 302 263 242 193 233) [53 71 44 65 25 43 91 52 97 51 14]
10 (378 317 231 321 354 372 393 354 360 293 247) [41 48 72 33 47 32 37 16 94 29]
9 (419 365 393 387 419 425 430 376 454 322) [41 41 26 56 83 40 80 70 33]
8 (460 434 419 475 508 470 510 524 487) [99 65 4 28 6 16 70 92]
7 (559 499 479 536 514 526 594 616) [88 2 77 73 7 63 67]
6 (647 501 613 609 533 657 683) [19 1 23 75 3 34]
@edbond
edbond / core.clj
Created November 21, 2010 14:19
fake emails file generator
(ns e.core
(:gen-class)
(:use faker.internet))
(defn make-n-emails-file
[filename n]
(spit filename
(apply str (interleave (take n (emails)) (repeat "\n")))))
(defn -main
@edbond
edbond / xor.clj
Created November 6, 2010 13:03
Xor macro in clojure, with tests
(ns xor
(:use clojure.test))
(defmacro xor
"Evaluates exprs one at a time, from left to right. If only one form returns
a logical true value (neither nil nor false), returns true. If more than one
value returns logical true or no value returns logical true, retuns a logical
false value. As soon as two logically true forms are encountered, no
remaining expression is evaluated. (xor) returns nil."
([] nil)
@edbond
edbond / game_of_life.clj
Created November 3, 2010 17:56
Clojure game of life
(ns clojure101.game_of_life
(:gen-class)
(:require [clojure.contrib.swing-utils :as swing]
[clojure.java.javadoc :as javadoc])
(:use [clojure.contrib.pprint :only [pprint]])
(:import [javax.swing JFrame JToolBar JButton]
[java.util EventObject]))
; (set! *warn-on-reflection* true)
@edbond
edbond / reset.rb
Created November 2, 2010 13:33
Reset rails logging in script/console, redirect to console
logger = Logger.new(STDOUT)
logger.level = Logger::DEBUG
RAILS_DEFAULT_LOGGER = logger
ActiveRecord::Base.logger = logger
ActionController::Base.logger = logger
ActiveSupport::Cache::MemCacheStore.logger = logger
ApplicationController.allow_forgery_protection = false
reload!
@edbond
edbond / w1e4.clj
Created October 5, 2010 16:18
clojure memoize
Non-memoize
Cleaning JVM allocations ...
Warming up for JIT ...
Estimating execution count ...
Running ...
Checking GC...
Cleaning JVM allocations ...
Finding outliers ...
Bootstrapping ...
Checking outlier significance
(clutch/with-db database
(clutch/ad-hoc-view
(clutch/with-clj-view-server
{:map (fn [doc] [[(:person doc) nil]])
:reduce (fn [key values _] nil)})
{:limit 5 :group true})))
# This is a monkey patch for MessageVerifier — I need to change Marshal.load to JSON
if defined?(ActionController::Flash::FlashHash)
class ActionController::Flash::FlashHash
def to_json(*args)
{}.merge(self).merge({:used => @used}).to_json
end
end
end
@edbond
edbond / gist:241074
Created November 23, 2009 13:41
Scribd
I am using rscribd (latest) to store and display private documents. I have no
problems displaying private docs but I need more security.
I added :secure_document => 1 to upload options hash and use
following code to display it:
var scribd_doc = scribd.Document.getDoc( doc_id, doc_key );
scribd_doc.addParam("use_ssl", true);
scribd_doc.grantAccess('4', '#{session[:session_id]}', signature);
scribd_doc.addParam( 'jsapi_version', 1 );
scribd_doc.write( 'embedded_flash' );