<commit_before><?xml version="1.0" encoding="utf-8"?>
<samples:AbsSample xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"
	xmlns:samples="samples.*">
	<mx:Script>
		<![CDATA[
			import mx.containers.Box;
			import mx.collections.ArrayCollection;
			import mx.controls.Image;
			import mx.messaging.SubscriptionInfo;
			import com.adobe.serialization.json.JSON;
			import mx.events.FlexEvent;
			import rx.ISubscription;
			import rx.IObservable;
			import rx.Observable;
			
			private var gisSubscription : ISubscription;
			
			private function getObservableJSON(request : URLRequest) : IObservable
			{
				return Observable.defer(Object, function():IObservable
				{
					try
					{
						var loader : URLLoader = new URLLoader();
						loader.load(request)
						
						return Observable.fromEvent(loader, Event.COMPLETE)
							.select(Object, function(s:String):Object { return JSON.decode(loader.data); })
							.take(1);
					}
					catch(error : Error)
					{
						return Observable.throwError(error, XML)
					}
					
					return null; // Grr compiler
				});
			}
			
			private function getGisUrlRequest(searchTerm : String) : URLRequest
			{
				var encodedSearchTerm : String = searchTerm; // TODO
				
				var urlRequest : URLRequest = new URLRequest();
				urlRequest.url ="http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" + 
					encodedSearchTerm;
					
				return urlRequest;
			}
			
			private function getImageObservable(searchTerm : String, thumbnails : Boolean) : IObservable
			{
				 return getObservableJSON(getGisUrlRequest(searchTerm))
				 	.selectMany(Object, function(result:Object) : IObservable
					{
						return Observable.returnValues(Object, result.responseData.results);
					})
					.select(Image, function(result:Object) : Image
					{
						var image : Image = new Image();
						image.toolTip = result.titleNoFormatting;
						
						var url : String = thumbnails
							? result.tbUrl
							: result.url;
						
						image.load(url);
						
						return image;
					});
			}
			
			private function preloadImages(observable : IObservable) : IObservable
			{
				return observable
					.selectMany(Image, function(image:Image) : IObservable
					{
						return Observable.fromEvent(image, Event.COMPLETE)
							.select(Image, function():Image { return image; })
							.take(1)
							.timeout(3000)
							.catchError(Observable.empty(Image));
					});
			}

			public override function setup() : void
			{
				imageContainer.removeAllChildren();
				
				var imageRequest : IObservable = getImageObservable(searchTermInput.text, 
					useThumbnailsCheckbox.selected);
				
				if (preloadImagesCheckbox.selected)
				{
					imageRequest = preloadImages(imageRequest);
				}
				
				gisSubscription = imageRequest.subscribeFunc(
					function(image : Image):void
					{
						imageContainer.addChild(image);
					},
					function():void
					{
						running = false;
					});
			}
			
			public override function teardown() : void
			{
				if (gisSubscription != null)
				{
					gisSubscription.unsubscribe();
					gisSubscription = null;
				}
			}
			
			private var images : ArrayCollection = new ArrayCollection();
		]]>
	</mx:Script>
	
	<mx:VBox width="100%" height="100%">
		<mx:HBox>
			<mx:Label text="Search term: " />
			<mx:TextInput id="searchTermInput" text="flowers" />
		</mx:HBox>
		<mx:HBox>
			<mx:Label text="Search term: " />
			<mx:CheckBox id="preloadImagesCheckbox" label="Preload images"
				toolTip="If checked images will appear in the order that they were loaded, not in their original order" />
		</mx:HBox>
		<mx:HBox>
			<mx:Label text="Search term: " />
			<mx:CheckBox id="useThumbnailsCheckbox" label="Use thumbnails" />
		</mx:HBox>
	
		<mx:HBox width="100%" height="100%" borderColor="#000000" id="imageContainer">
			
		</mx:HBox>
		<!--
		<mx:VBox id="imageContainer" width="100%" height="100%"/>
-->		
		<mx:Box height="80%" width="100%" visible="{showCode}" includeInLayout="{showCode}">
			<mx:TextArea height="100%" width="100%" fontFamily="Courier New">
				<mx:htmlText>
	<![CDATA[
var interval : IObservable = Observable.interval(500);
var bufferedInterval : IObservable = interval.bufferWithCount(5);

intervalSub = interval.subscribeFunc(function(i:uint):void
{
	intervalLabel.text = i.toString();
});

bufferedSub = bufferedInterval.subscribeFunc(function(indexes : Array):void
{
	bufferedIntervalLabel.text = indexes.join(", ");
});
	]]>
				</mx:htmlText>
			</mx:TextArea>
		</mx:Box>
	</mx:VBox>
	
	
</samples:AbsSample><commit_msg>Updated GIS sample<commit_after><?xml version="1.0" encoding="utf-8"?>
<samples:AbsSample xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"
	xmlns:samples="samples.*">
	<mx:Script>
		<![CDATA[
			import mx.containers.Box;
			import mx.collections.ArrayCollection;
			import mx.controls.Image;
			import mx.messaging.SubscriptionInfo;
			import com.adobe.serialization.json.JSON;
			import mx.events.FlexEvent;
			import rx.ISubscription;
			import rx.IObservable;
			import rx.Observable;
			
			private var gisSubscription : ISubscription;
			
			public override function setup() : void
			{
				imageContainer.removeAllChildren();
				
				var imageRequest : IObservable = getImageObservable(searchTermInput.text, 
					useThumbnailsCheckbox.selected);
				
				if (preloadImagesCheckbox.selected)
				{
					imageRequest = preloadImages(imageRequest);
				}
				
				gisSubscription = imageRequest.subscribeFunc(
					function(image : Image):void
					{
						imageContainer.addChild(image);
					},
					function():void
					{
						running = false;
					},
					function(e:Error):void
					{
						errorLabel.text = e.message;
					});
			}
			
			private function preloadImages(observable : IObservable) : IObservable
			{
				return observable
					.selectMany(Image, function(image:Image) : IObservable
					{
						return Observable.fromEvent(image, Event.COMPLETE)
							.select(Image, function():Image { return image; })
							.take(1)
							.timeout(3000)
							.catchError(Observable.empty(Image));
					});
			}
			
			private function getImageObservable(searchTerm : String, thumbnails : Boolean) : IObservable
			{
				 return getObservableJSON(getGisUrlRequest(searchTerm))
				 	.selectMany(Object, function(result:Object) : IObservable
					{
						return Observable.returnValues(Object, result.responseData.results);
					})
					.select(Image, function(result:Object) : Image
					{
						var image : Image = new Image();
						image.toolTip = result.titleNoFormatting;
						
						var url : String = thumbnails
							? result.tbUrl
							: result.url;
						
						image.load(url);
						
						return image;
					});
			}
			
			private function getObservableJSON(request : URLRequest) : IObservable
			{
				return Observable.defer(Object, function():IObservable
				{
					try
					{
						var loader : URLLoader = new URLLoader();
						loader.load(request)
						
						return Observable.fromEvent(loader, Event.COMPLETE)
							.select(Object, function(s:String):Object { return JSON.decode(loader.data); })
							.take(1);
					}
					catch(error : Error)
					{
						return Observable.throwError(error, Object)
					}
					
					return null; // Grr compiler
				});
			}
			
			private function getGisUrlRequest(searchTerm : String) : URLRequest
			{
				var encodedSearchTerm : String = searchTerm; // TODO
				
				var urlRequest : URLRequest = new URLRequest();
				
				urlRequest.url ="http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" + 
					encodedSearchTerm;
					
				return urlRequest;
			}
			
			public override function teardown() : void
			{
				if (gisSubscription != null)
				{
					gisSubscription.unsubscribe();
					gisSubscription = null;
				}
			}
			
			private var images : ArrayCollection = new ArrayCollection();
		]]>
	</mx:Script>
	
	<mx:VBox width="100%" height="100%">
		<mx:Label id="errorLabel" text="" color="#FF0000" />
		<mx:HBox>
			<mx:Label text="Search term: " />
			<mx:TextInput id="searchTermInput" text="flowers" />
		</mx:HBox>
		<mx:HBox>
			<mx:Label text="Search term: " />
			<mx:CheckBox id="preloadImagesCheckbox" label="Preload images"
				toolTip="If checked images will appear in the order that they were loaded, not in their original order" />
		</mx:HBox>
		<mx:HBox>
			<mx:Label text="Search term: " />
			<mx:CheckBox id="useThumbnailsCheckbox" label="Use thumbnails" />
		</mx:HBox>
	
		<mx:HBox width="100%" height="100%" borderColor="#000000" id="imageContainer">
			
		</mx:HBox>
		<!--
		<mx:VBox id="imageContainer" width="100%" height="100%"/>
-->		
		<mx:Box height="80%" width="100%" visible="{showCode}" includeInLayout="{showCode}">
			<mx:TextArea height="100%" width="100%" fontFamily="Courier New">
				<mx:htmlText>
	<![CDATA[
public override function setup() : void
{
	imageContainer.removeAllChildren();
	
	var imageRequest : IObservable = getImageObservable(searchTermInput.text, 
		useThumbnailsCheckbox.selected);
	
	if (preloadImagesCheckbox.selected)
	{
		imageRequest = preloadImages(imageRequest);
	}
	
	gisSubscription = imageRequest.subscribeFunc(
		function(image : Image):void
		{
			imageContainer.addChild(image);
		},
		function():void
		{
			running = false;
		});
}

private function preloadImages(observable : IObservable) : IObservable
{
	return observable
		.selectMany(Image, function(image:Image) : IObservable
		{
			return Observable.fromEvent(image, Event.COMPLETE)
				.select(Image, function():Image { return image; })
				.take(1)
				.timeout(3000)
				.catchError(Observable.empty(Image));
		});
}

private function getImageObservable(searchTerm : String, thumbnails : Boolean) : IObservable
{
	 return getObservableJSON(getGisUrlRequest(searchTerm))
	 	.selectMany(Object, function(result:Object) : IObservable
		{
			return Observable.returnValues(Object, result.responseData.results);
		})
		.select(Image, function(result:Object) : Image
		{
			var image : Image = new Image();
			image.toolTip = result.titleNoFormatting;
			
			var url : String = thumbnails
				? result.tbUrl
				: result.url;
			
			image.load(url);
			
			return image;
		});
}

private function getObservableJSON(request : URLRequest) : IObservable
{
	return Observable.defer(Object, function():IObservable
	{
		try
		{
			var loader : URLLoader = new URLLoader();
			loader.load(request)
			
			return Observable.fromEvent(loader, Event.COMPLETE)
				.select(Object, function(s:String):Object { return JSON.decode(loader.data); })
				.take(1);
		}
		catch(error : Error)
		{
			return Observable.throwError(error, Object)
		}
		
		return null;
	});
}

private function getGisUrlRequest(searchTerm : String) : URLRequest
{
	var encodedSearchTerm : String = searchTerm;
	
	var urlRequest : URLRequest = new URLRequest();
	
	urlRequest.url ="http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" + 
		encodedSearchTerm;
		
	return urlRequest;
}
	]]>
				</mx:htmlText>
			</mx:TextArea>
		</mx:Box>
	</mx:VBox>
	
	
</samples:AbsSample>
{'fraction_non_alphanumeric': 0.13009305266961785, 'fraction_numerical': 0.011563826903966032, 'mean_word_length': 3.2774343122102008, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 2, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3745123', 'n_tokens_mistral': 4581, 'n_tokens_neox': 3466, 'n_words': 655}