This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if layout.nil? | |
| [...] | |
| inflater = LayoutInflater.from @context | |
| layout = inflater.inflate(R.layout.lazy_gallery_item, parent, false) | |
| layout.addView image | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Foo | |
| attr_accessor :bar | |
| def initialize | |
| @bar = 'init' | |
| end | |
| def fun | |
| lambda { "got: #{@bar}" } | |
| end | |
| def fun2 | |
| b = @bar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user> (fact 200) | |
| 788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000 | |
| user> (class (fact 200)) | |
| java.math.BigInteger | |
| user> (stirling 200) | |
| Infinity | |
| user> (class (stirling 200)) | |
| java.lang.Double |