Skip to content

Instantly share code, notes, and snippets.

@pithyless
pithyless / integer.rb
Created March 24, 2014 10:50
Ruby Integer::MAX and Integer::MIN
class Integer
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 16
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
p Integer::MAX #=> 4611686018427387903
p Integer::MAX.class #=> Fixnum
p (Integer::MAX + 1).class #=> Bignum
@pithyless
pithyless / gist:3386424
Created August 18, 2012 12:08
Convert FLAC to ALAC/AAC on a Mac
Step 1: install flac via Homebrew
brew install flac
Step 2: decode FLAC to AIFF
cd path/to/directory/with/files/to/convert
for i in *.flac; do
flac -d --force-aiff-format "$i"
done
@pithyless
pithyless / import-vars.cljc
Last active September 1, 2021 19:07
A CLJC version of potemkin/import-vars
(ns my.util.namespace
#?(:cljs (:require-macros [my.util.namespace]))
(:require
#?(:clj [potemkin :as potemkin])))
(defmacro cljs-import-vars [& syms]
(let [unravel (fn unravel [x]
(if (sequential? x)
(->> x
@pithyless
pithyless / i18n-impl.cljs
Last active June 24, 2021 09:49 — forked from isaksky/i18n-impl.cljs
Handling translations in ClojureScript
(ns front.utilities.i18n-impl
(:require [front.i18n]))
(defn build-domain-index [text-vec]
(let [by-msgid (atom (transient {}))
by-msg (atom (transient {}))]
(doseq [{:keys [s_message s_message_id] :as text} text-vec]
(when-not (clojure.string/blank? s_message_id)
(swap! by-msgid assoc! s_message_id text))
(when-not (clojure.string/blank? s_message)
@pithyless
pithyless / gist:1547408
Created January 1, 2012 14:02
jQuery set Headers for $.ajax
// jQuery Headers support for $.ajax
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Accept","application/json");
}
type: "POST",
url: "/article",
processData: false,
@pithyless
pithyless / ken-burns.css
Created February 18, 2012 22:56 — forked from thierryk/ken-burns.css
Ken Burns effect (styling images with panning and zooming effects)
/**
* See: http://www.css-101.org/articles/ken-burns_effect/css-transition.php
*/
/**
* Styling the container (the wrapper)
*
* position is used to make this box a containing block (it becomes a reference for its absolutely positioned children). overflow will hide part of the images moving outside of the box.
*/
@pithyless
pithyless / keybase.md
Created February 21, 2020 16:25
keybase.md

Keybase proof

I hereby claim:

  • I am pithyless on github.
  • I am pithyless (https://keybase.io/pithyless) on keybase.
  • I have a public key ASAXUfguy_endzUnkeC8v1Gc1dOmBl6wgRunTYVSyUlnOAo

To claim this, I am signing this object:

@pithyless
pithyless / quality.rake
Created January 1, 2012 13:14 — forked from steveklabnik/quality.rake
My new favorite Rake task
require 'flog'
require 'flog_task'
require 'flay'
require 'flay_task'
require 'roodi'
require 'roodi_task'
FlogTask.new :flog, SOME_NUMBER_HERE, %w[app lib]
FlayTask.new :flay, OTHER_NUMBER_HERE, %w[app lib]
RoodiTask.new 'roodi', ['app/**/*.rb', 'lib/**/*.rb']
@pithyless
pithyless / either.rb
Created March 27, 2012 14:44
Chaining Either for Ruby
# A chainable Either monad for Ruby
#
# Examples
#
# Either.right('s') >> proc { |s| Either.right(s + '-1') } >> proc { |s| Either.right(s + '-2') }
# #=> #<Either @left=nil, @right="s-1-2">
#
# Either.right('s') >> proc { |s| Either.left('error!') } >> proc { |s| Either.right(s + '-2') }
# #=> #<Either @left='error!', @right=nil>
#
@pithyless
pithyless / Model_and_Form_Validations.md
Created September 13, 2011 22:49
Django Field Notes

Model + Form validations

Some of Django's choices on how to handle data integrity are wrong, or at the very least, unexpected to the uninitiated developers. I'm not here to pass judgement; like many people, I'd just like to get back to doing real work. Some notes on how to stay safe in Django:

What should I know?

  • Django now has both Form validations and Model validations
  • Django used to only have Form validations
  • Form’s is_valid() performs model validation automatically
  • full_clean() is never actually called by Django (see ticket #13100)