Skip to content

Instantly share code, notes, and snippets.

def self.cache_dir(c:Context):File
@cache_dir ||= File.new(c.getCacheDir, "lazy_image_cache")
@cache_dir.mkdirs unless @cache_dir.exists
@cache_dir
end
def self.purgeDiskCache(c:Context):void
thread = Thread.new do
# 8 hours
oldest_acceptable = System.currentTimeMillis - long(28800000)
@abscondment
abscondment / image_display.mirah
Created April 1, 2011 16:37
LazyImageView refresh
def setSrcUrl(url:String):void
@src_url = url
@path = File.new(cache_dir, "" + @src_url.hashCode + ".jpg").getCanonicalPath
end
def load:void
unless @loaded || @src_url.nil? || @path.nil?
AsyncDownload.new(Handler.new(self), @src_url, @path)
end
end
def onItemSelected(parent:AdapterView, view:View, pos:int, id:long)
unless @textView.nil?
photo_map = Map(LazyGalleryAdapter(parent.getAdapter).getItem pos)
if photo_map.containsKey('caption')
@textView.setText String(photo_map.get('caption'))
@textView.setVisibility View.VISIBLE
else
@textView.setVisibility View.INVISIBLE
end
end
if layout.nil?
[...]
inflater = LayoutInflater.from @context
layout = inflater.inflate(R.layout.lazy_gallery_item, parent, false)
layout.addView image
end
def getView(pos:int, convertView:View, parent:ViewGroup)
layout = RelativeLayout(convertView)
image = LazyImageView(nil)
url = String(Map(getItem pos).get('src'))
if layout.nil?
image = LazyImageView.new(@context, R.drawable.placeholder)
image.setScaleType(ImageView.ScaleType.FIT_XY)
image.setLayoutParams Gallery.LayoutParams.new(@oneeighty,@oneeighty)
image.setBackgroundResource(R.drawable.gallery_background)
def update_from_json(json:String)
begin
data = JSONArray.new json
data.length.times do |i|
photo_json = data.getJSONObject(i)
@photos.add {'caption' => photo_json.getString('caption'), 'src' => photo_json.getString('src')}
end
rescue JSONException => e
Log.e 'LazyGalleryAdapter', 'Could not load JSON', e
end
@abscondment
abscondment / gist:897860
Created April 1, 2011 07:41
Using the lazy-gallery components.
gallery = Gallery(findViewById R.id.lazy_gallery)
# Make sure the GallerySelectionListener is only
# triggered when the gallery is stopped on an image.
gallery.setCallbackDuringFling false
# Create our adapter
gallery_adapter = LazyGalleryAdapter.new self
# When the current item is clicked, create a toast with its caption.
this = self
class Foo
attr_accessor :bar
def initialize
@bar = 'init'
end
def fun
lambda { "got: #{@bar}" }
end
def fun2
b = @bar
(defn stirling-big [#^Integer n]
(.multiply
(BigDecimal. (Math/sqrt (* 2 Math/PI n)))
(.pow (.divide (BigDecimal. n)
(BigDecimal. Math/E)
java.math.MathContext/DECIMAL128)
n java.math.MathContext/DECIMAL128)))
user> (fact 200)
788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000
user> (class (fact 200))
java.math.BigInteger
user> (stirling 200)
Infinity
user> (class (stirling 200))
java.lang.Double