working on it ...

Filters

Explore Public Snippets

Sort by

Found 4,640 snippets matching: resources

    public by JMichaelTX  199548  0  3  0

    JavaScript for Automation (JXA) Resources

    JavaScript for Automation (JXA) Resources: JXA Resources.md
    ### Other JXA Resources
    This is a list of the key resources I have found useful.  If you know of others, please post in a comment below, and I will add to this list.
    
    1. [JXA Release Notes in Yosemite 10.10](https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW1)
    2. [JXA Release Notes in El Capitan 10.11](https://developer.apple.com/library/prerelease/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-11.html)
    3. [JXA Cookbook Wiki](https://github.com/dtinth/JXA-Cookbook/wiki)
    4. [JXA: Getting Started with Javascript for Automation](http://www.macstories.net/tutorials/getting-started-with-javascript-for-automation-on-yosemite/)
    5. [2014 WWDC session video on JXA. (can view ONLY in Safari)](https://developer.apple.com/videos/wwdc/2014/?id=306)
    
    

    public by maindog  16045  1502  8  17

    javascript cheat for A Dark Room v1.3

    (can be used on chrome using the javascript console) After you get a hut and someone joins your village (not the builder) this code will provide you with a lot of wood, allowing you to build more huts, traps and other buildings once you have the resources. (does not purchase the buildings and for the mines you still have to find them on the map)
    /**
     * Module that registers the outdoors functionality
     */
    var Outside = {
    	name: "Outside",
    	
    	_GATHER_DELAY: 60,
    	_TRAPS_DELAY: 90,
    	_POP_DELAY: [0.5, 3],
    	
    	_INCOME: {
    		'gatherer': {
    			delay: 1,
    			stores: {
    				'wood': 10000
    			}
    		},
    		'hunter': {
    			delay: 1,
    			stores: {
    				'fur': 10000,
    				'meat': 10000,
    				'alien alloy': 10000,
    				'medicine': 10000
    			}
    		},
    		'trapper': {
    			delay: 1,
    			stores: {
    				'meat': 10000,
    				'bait': 10000,
    				'teeth': 10000,
    				'scales': 10000
    			}
    		},
    		'tanner': {
    			delay: 1,
    			stores: {
    				'fur': 100000,
    				'leather': 100000
    			}
    		},
    		'charcutier': {
    			delay: 1,
    			stores: {
    				'meat': 100000,
    				'wood': 100000,
    				'cured meat': 100000
    			}
    		},
    		'iron miner': {
    			delay: 1,
    			stores: {
    				'cured meat': 100000,
    				'iron': 100000
    			}
    		},
    		'coal miner': {
    			delay: 1,
    			stores: {
    				'cured meat': 100000,
    				'coal': 100000
    			}
    		},
    		'sulphur miner': {
    			delay: 1,
    			stores: {
    				'cured meat': 100000,
    				'sulphur': 100000
    			}
    		},
    		'steelworker': {
    			delay: 1,
    			stores: {
    				'iron': 100000,
    				'coal': 100000,
    				'steel': 100000
    			}
    		},
    		'armourer': {
    			delay: 1,
    			stores: {
    				'steel': 100000,
    				'sulphur': 10000,
    				'bullets': 100000
    			}
    		}
    	},
    	
    	TrapDrops: [
    		{
    			rollUnder: 0.5,
    			name: 'fur',
    			message: 'scraps of fur'
    		},
    		{
    			rollUnder: 0.75,
    			name: 'meat',
    			message: 'bits of meat'
    		},
    		{
    			rollUnder: 0.85,
    			name: 'scales',
    			message: 'strange scales'
    		},
    		{
    			rollUnder: 0.93,
    			name: 'teeth',
    			message: 'scattered teeth'
    		},
    		{
    			rollUnder: 0.995,
    			name: 'cloth',
    			message: 'tattered cloth'
    		},
    		{
    			rollUnder: 1.0,
    			name: 'charm',
    			message: 'a crudely made charm'
    		}
    	],
    	
    	init: function(options) {
    		this.options = $.extend(
    			this.options,
    			options
    		);
    		
    		if(Engine._debug) {
    			this._GATHER_DELAY = 0;
    			this._TRAPS_DELAY = 0;
    		}
    		
    		// Create the outside tab
    		this.tab = Header.addLocation("A Silent Forest", "outside", Outside);
    		
    		// Create the Outside panel
    		this.panel = $('<div>').attr('id', "outsidePanel")
    			.addClass('location')
    			.appendTo('div#locationSlider');
    		
    		//subscribe to stateUpdates
    		$.Dispatch('stateUpdate').subscribe(Outside.handleStateUpdates);
    		
    		if(typeof $SM.get('features.location.outside') == 'undefined') {
    			$SM.set('features.location.outside', true);
    			if(!$SM.get('game.buildings')) $SM.set('game.buildings', {});
    			if(!$SM.get('game.population')) $SM.set('game.population', 0);
    			if(!$SM.get('game.workers')) $SM.set('game.workers', {});
    		}
    		
    		this.updateVillage();
    		Outside.updateWorkersView();
    		
    		Engine.updateSlider();
    		
    		// Create the gather button
    		new Button.Button({
    			id: 'gatherButton',
    			text: "gather wood",
    			click: Outside.gatherWood,
    			cooldown: Outside._GATHER_DELAY,
    			width: '80px'
    		}).appendTo('div#outsidePanel');
    	},
    	
    	getMaxPopulation: function() {
    		return $SM.get('game.buildings["hut"]', true) * 4;
    	},
    	
    	increasePopulation: function() {
    		var space = Outside.getMaxPopulation() - $SM.get('game.population');
    		if(space > 0) {
    			var num = Math.floor(Math.random()*(space/2) + space/2);
    			if(num == 0) num = 1;
    			if(num == 1) {
    				Notifications.notify(null, 'a stranger arrives in the night');
    			} else if(num < 5) {
    				Notifications.notify(null, 'a weathered family takes up in one of the huts.');
    			} else if(num < 10) {
    				Notifications.notify(null, 'a small group arrives, all dust and bones.');
    			} else if(num < 30) {
    				Notifications.notify(null, 'a convoy lurches in, equal parts worry and hope.');
    			} else {
    				Notifications.notify(null, "the town's booming. word does get around.");
    			}
    			Engine.log('population increased by ' + num);
    			$SM.add('game.population', num);
    		}
    		Outside.schedulePopIncrease();
    	},
    	
    	killVillagers: function(num) {
    		$SM.add('game.population', num * -1);
    		if($SM.get('game.population') < 0) {
    			$SM.set('game.population', 0);
    		}
    		var remaining = Outside.getNumGatherers();
    		if(remaining < 0) {
    			var gap = -remaining;
    			for(var k in $SM.get('game.workers')) {
    				var num = $SM.get('game.workers["'+k+'"]');
    				if(num < gap) {
    					gap -= num;
    					$SM.set('game.workers["'+k+'"]', 0);
    				} else {
    					$SM.add('game.workers["'+k+'"]', gap * -1);
    					break;
    				}
    			}
    		}
    	},
    	
    	schedulePopIncrease: function() {
    		var nextIncrease = Math.floor(Math.random()*(Outside._POP_DELAY[1] - Outside._POP_DELAY[0])) + Outside._POP_DELAY[0];
        	Engine.log('next population increase scheduled in ' + nextIncrease + ' minutes');
        	Outside._popTimeout = setTimeout(Outside.increasePopulation, nextIncrease * 60 * 1000);
    	},
    	
    	updateWorkersView: function() {
    		var workers = $('div#workers');
    
    		// If our population is 0 and we don't already have a workers view,
    		// there's nothing to do here.
    		if(!workers.length && $SM.get('game.population') == 0) return;
    
    		var needsAppend = false;
    		if(workers.length == 0) {
    			needsAppend = true;
    			workers = $('<div>').attr('id', 'workers').css('opacity', 0);
    		}
    		
    		var numGatherers = $SM.get('game.population');
    		var gatherer = $('div#workers_row_gatherer', workers);
    		
    		for(var k in $SM.get('game.workers')) {
    			var workerCount = $SM.get('game.workers["'+k+'"]');
    			var row = $('div#workers_row_' + k.replace(' ', '-'), workers);
    			if(row.length == 0) {
    				row = Outside.makeWorkerRow(k, workerCount);
    				
    				var curPrev = null;
    				workers.children().each(function(i) {
    					var child = $(this);
    					var cName = child.attr('id').substring(12).replace('-', ' ');
    					if(cName != 'gatherer') {
    						if(cName < k && (curPrev == null || cName > curPrev)) {
    							curPrev = cName;
    						}
    					}
    				});
    				if(curPrev == null && gatherer.length == 0) {
    					row.prependTo(workers);
    				} 
    				else if(curPrev == null)
    				{
    					row.insertAfter(gatherer);
    				} 
    				else 
    				{
    					row.insertAfter(workers.find('#workers_row_' + curPrev.replace(' ', '-')));
    				}
    				
    			} else {
    				$('div#' + row.attr('id') + ' > div.row_val > span', workers).text(workerCount);
    			}
    			numGatherers -= workerCount;
    			if(workerCount == 0) {
    				$('.dnBtn', row).addClass('disabled');
    				$('.dnManyBtn', row).addClass('disabled');
    			} else {
    				$('.dnBtn', row).removeClass('disabled');
    				$('.dnManyBtn', row).removeClass('disabled');
    			}
    		}
    		
    		if(gatherer.length == 0) {
    			gatherer = Outside.makeWorkerRow('gatherer', numGatherers);
    			gatherer.prependTo(workers);
    		} else {
    			$('div#workers_row_gatherer > div.row_val > span', workers).text(numGatherers);
    		}
    		
    		if(numGatherers == 0) {
    			$('.upBtn', '#workers').addClass('disabled');
    			$('.upManyBtn', '#workers').addClass('disabled');
    		} else {
    			$('.upBtn', '#workers').removeClass('disabled');
    			$('.upManyBtn', '#workers').removeClass('disabled');
    		}
    		
    		
    		if(needsAppend && workers.children().length > 0) {
    			workers.appendTo('#outsidePanel').animate({opacity:1}, 300, 'linear');
    		}
    	},
    	
    	getNumGatherers: function() {
    		var num = $SM.get('game.population'); 
    		for(var k in $SM.get('game.workers')) {
    			num -= $SM.get('game.workers["'+k+'"]');
    		}
    		return num;
    	},
    	
    	makeWorkerRow: function(name, num) {
    		var row = $('<div>')
    			.attr('id', 'workers_row_' + name.replace(' ','-'))
    			.addClass('workerRow');
    		$('<div>').addClass('row_key').text(name).appendTo(row);
    		var val = $('<div>').addClass('row_val').appendTo(row);
    		
    		$('<span>').text(num).appendTo(val);
    		
    		if(name != 'gatherer') {
    		  $('<div>').addClass('upManyBtn').appendTo(val).click([10], Outside.increaseWorker);
    			$('<div>').addClass('upBtn').appendTo(val).click([1], Outside.increaseWorker);
    			$('<div>').addClass('dnBtn').appendTo(val).click([1], Outside.decreaseWorker);
    			$('<div>').addClass('dnManyBtn').appendTo(val).click([10], Outside.decreaseWorker);
    		}
    		
    		$('<div>').addClass('clear').appendTo(row);
    		
    		var tooltip = $('<div>').addClass('tooltip bottom right').appendTo(row);
    		var income = Outside._INCOME[name];
    		for(var s in income.stores) {
    			var r = $('<div>').addClass('storeRow');
    			$('<div>').addClass('row_key').text(s).appendTo(r);
    			$('<div>').addClass('row_val').text(Engine.getIncomeMsg(income.stores[s], income.delay)).appendTo(r);
    			r.appendTo(tooltip);
    		}
    		
    		return row;
    	},
    	
    	increaseWorker: function(btn) {
    		var worker = $(this).closest('.workerRow').children('.row_key').text();
    		if(Outside.getNumGatherers() > 0) {
    		  var increaseAmt = Math.min(Outside.getNumGatherers(), btn.data);
    			Engine.log('increasing ' + worker + ' by ' + increaseAmt);
    			$SM.add('game.workers["'+worker+'"]', increaseAmt);
    		}
    	},
    	
    	decreaseWorker: function(btn) {
    		var worker = $(this).closest('.workerRow').children('.row_key').text();
    		if($SM.get('game.workers["'+worker+'"]') > 0) {
    		  var decreaseAmt = Math.min($SM.get('game.workers["'+worker+'"]') || 0, btn.data);
    			Engine.log('decreasing ' + worker + ' by ' + decreaseAmt);
    			$SM.add('game.workers["'+worker+'"]', decreaseAmt * -1);
    		}
    	},
    	
    	updateVillageRow: function(name, num, village) {
    		var id = 'building_row_' + name.replace(' ', '-');
    		var row = $('div#' + id, village);
    		if(row.length == 0 && num > 0) {
    			row = $('<div>').attr('id', id).addClass('storeRow');
    			$('<div>').addClass('row_key').text(name).appendTo(row);
    			$('<div>').addClass('row_val').text(num).appendTo(row);
    			$('<div>').addClass('clear').appendTo(row);
    			var curPrev = null;
    			village.children().each(function(i) {
    				var child = $(this);
    				if(child.attr('id') != 'population') {
    					var cName = child.attr('id').substring(13).replace('-', ' ');
    					if(cName < name && (curPrev == null || cName > curPrev)) {
    						curPrev = cName;
    					}
    				}
    			});
    			if(curPrev == null) {
    				row.prependTo(village);
    			} else {
    				row.insertAfter('#building_row_' + curPrev.replace(' ', '-'));
    			}
    		} else if(num > 0) {
    			$('div#' + row.attr('id') + ' > div.row_val', village).text(num);
    		} else if(num == 0) {
    			row.remove();
    		}
    	},
    	
    	updateVillage: function(ignoreStores) {
    		var village = $('div#village');
    		var population = $('div#population');
    		var needsAppend = false;
    		if(village.length == 0) {
    			needsAppend = true;
    			village = $('<div>').attr('id', 'village').css('opacity', 0);
    			population = $('<div>').attr('id', 'population').appendTo(village);
    		}
    		
    		for(var k in $SM.get('game.buildings')) {
    			if(k == 'trap') {
    				var numTraps = $SM.get('game.buildings["'+k+'"]');
    				var numBait = $SM.get('stores.bait', true);
    				var traps = numTraps - numBait;
    				traps = traps < 0 ? 0 : traps;
    				Outside.updateVillageRow(k, traps, village);
    				Outside.updateVillageRow('baited trap', numBait > numTraps ? numTraps : numBait, village);
    			} else {
    				if(Outside.checkWorker(k)) {
    					Outside.updateWorkersView();
    				}
    				Outside.updateVillageRow(k, $SM.get('game.buildings["'+k+'"]'), village);
    			}
    		}
    		
    		population.text('pop ' + $SM.get('game.population') + '/' + this.getMaxPopulation());
    		
    		var hasPeeps;
    		if($SM.get('game.buildings["hut"]', true) == 0) {
    			hasPeeps = false;
    			village.addClass('noHuts');
    		} else {
    			hasPeeps = true;
    			village.removeClass('noHuts');
    		}
    		
    		if(needsAppend && village.children().length > 1) {
    			village.appendTo('#outsidePanel');
    			village.animate({opacity:1}, 300, 'linear');
    		}
    		
    		if(hasPeeps && typeof Outside._popTimeout == 'undefined') {
    			Outside.schedulePopIncrease();
    		}
    		
    		this.setTitle();
    
    		if(!ignoreStores && Engine.activeModule === Outside && village.children().length > 1) {
    			$('#storesContainer').css({top: village.height() + 26 + 'px'});
    		}
    	},
    	
    	checkWorker: function(name) {
    		var jobMap = {
    			'lodge': ['hunter', 'trapper'],
    			'tannery': ['tanner'],
    			'smokehouse': ['charcutier'],
    			'iron mine': ['iron miner'],
    			'coal mine': ['coal miner'],
    			'sulphur mine': ['sulphur miner'],
    			'steelworks': ['steelworker'],
    			'armoury' : ['armourer']
    		};
    		
    		var jobs = jobMap[name];
    		var added = false;
    		if(typeof jobs == 'object') {
    			for(var i = 0, len = jobs.length; i < len; i++) {
    				var job = jobs[i];
    				if(typeof $SM.get('game.buildings["'+name+'"]') == 'number' && 
    						typeof $SM.get('game.workers["'+job+'"]') != 'number') {
    					Engine.log('adding ' + job + ' to the workers list');
    					$SM.set('game.workers["'+job+'"]', 0);
    					added = true;
    				}
    			}
    		}
    		return added;
    	},
    	
    	updateVillageIncome: function() {		
    		for(var worker in Outside._INCOME) {
    			var income = Outside._INCOME[worker];
    			var num = worker == 'gatherer' ? Outside.getNumGatherers() : $SM.get('game.workers["'+worker+'"]');
    			if(typeof num == 'number') {
    				var stores = {};
    				if(num < 0) num = 0;
    				var tooltip = $('.tooltip', 'div#workers_row_' + worker.replace(' ', '-'));
    				tooltip.empty();
    				var needsUpdate = false;
    				var curIncome = $SM.getIncome(worker);
    				for(var store in income.stores) {
    					stores[store] = income.stores[store] * num;
    					if(curIncome[store] != stores[store]) needsUpdate = true;
    					var row = $('<div>').addClass('storeRow');
    					$('<div>').addClass('row_key').text(store).appendTo(row);
    					$('<div>').addClass('row_val').text(Engine.getIncomeMsg(stores[store], income.delay)).appendTo(row);
    					row.appendTo(tooltip);
    				}
    				if(needsUpdate) {
    					$SM.setIncome(worker, {
    						delay: income.delay,
    						stores: stores
    					});
    				}
    			}
    		}
    		Room.updateIncomeView();
    	},
    	
    	updateTrapButton: function() {
    		var btn = $('div#trapsButton');
    		if($SM.get('game.buildings["trap"]', true) > 0) {
    			if(btn.length == 0) {
    				new Button.Button({
    					id: 'trapsButton',
    					text: "check traps",
    					click: Outside.checkTraps,
    					cooldown: Outside._TRAPS_DELAY,
    					width: '80px'
    				}).appendTo('div#outsidePanel');
    			} else {
    				Button.setDisabled(btn, false);
    			}
    		} else {
    			if(btn.length > 0) {
    				Button.setDisabled(btn, true);
    			}
    		}
    	},
    	
    	setTitle: function() {
    		var numHuts = $SM.get('game.buildings["hut"]', true);
    		var title;
    		if(numHuts == 0) {
    			title = "A Silent Forest";
    		} else if(numHuts == 1) {
    			title = "A Lonely Hut";
    		} else if(numHuts <= 4) {
    			title = "A Tiny Village";
    		} else if(numHuts <= 8) {
    			title = "A Modest Village";
    		} else if(numHuts <= 14) {
    			title = "A Large Village";
    		} else {
    			title = "A Raucous Village";
    		}
    		
    		if(Engine.activeModule == this) {
    			document.title = title;
    		}
    		$('#location_outside').text(title);
    	},
    	
    	onArrival: function(transition_diff) {
    		Outside.setTitle();
    		if(!$SM.get('game.outside.seenForest')) {
    			Notifications.notify(Outside, "the sky is grey and the wind blows relentlessly");
    			$SM.set('game.outside.seenForest', true);
    		}
    		Outside.updateTrapButton();
    		Outside.updateVillage(true);
    
    		Engine.moveStoresView($('#village'), transition_diff);
    	},
    	
    	gatherWood: function() {
    		Notifications.notify(Outside, "dry brush and dead branches litter the forest floor");
    		var gatherAmt = $SM.get('game.buildings["cart"]', true) > 0 ? 50 : 10;
    		$SM.add('stores.wood', gatherAmt);
    	},
    	
    	checkTraps: function() {
    		var drops = {};
    		var msg = [];
    		var numTraps = $SM.get('game.buildings["trap"]', true);
    		var numBait = $SM.get('stores.bait', true);
    		var numDrops = numTraps + (numBait < numTraps ? numBait : numTraps);
    		for(var i = 0; i < numDrops; i++) {
    			var roll = Math.random();
    			for(var j in Outside.TrapDrops) {
    				var drop = Outside.TrapDrops[j];
    				if(roll < drop.rollUnder) {
    					var num = drops[drop.name];
    					if(typeof num == 'undefined') {
    						num = 0;
    						msg.push(drop.message);
    					}
    					drops[drop.name] = num + 1;
    					break;
    				}
    			}
    		}
    		var s = 'the traps contain ';
    		for(var i = 0, len = msg.length; i < len; i++) {
    			if(len > 1 && i > 0 && i < len - 1) {
    				s += ", ";
    			} else if(len > 1 && i == len - 1) {
    				s += " and ";
    			}
    			s += msg[i];
    		}
    		
    		var baitUsed = numBait < numTraps ? numBait : numTraps;
    		drops['bait'] = -baitUsed;
    		
    		Notifications.notify(Outside, s);
    		$SM.addM('stores', drops);
    	},
    	
    	handleStateUpdates: function(e){
    		if(e.category == 'stores'){
    			Outside.updateVillage();
    		} else if(e.stateName.indexOf('game.workers') == 0
    		          || e.stateName.indexOf('game.population') == 0){
    			Outside.updateVillage();
    			Outside.updateWorkersView();
    			Outside.updateVillageIncome();
    		};
    	}
    };

    public by lbottaro  4376  1  7  0

    How to fetch Internet Resources Using urllib2 in python

    urllib2 is a Python module for fetching URLs (Uniform Resource Locators). It offers a simple interface, based on the urlopen function. This method is capable of fetching URLs using a variety of different protocols. In this example you can see a specific exception handlers for HTTPError and URLError.
    import os, urllib2
    
    def getURLResult():
        try:      
            intRes = urllib2.urlopen("http://your_URL")
        except urllib2.HTTPError, e:
            print "HTTPError Error: " + str(e.code) 
        except urllib2.URLError, e:
            print "URLError Error: " + str(e.reason) 
        print "ok"

    public by marksimon232  3010  1  6  2

    iPhone Application Development Resources

    http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/assignments/Assignment%206_2.pdf
    https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Introduction/Introduction.html
    http://www.agileinfoways.com/technical-expertise/mobile-applications-development/iphone/
    https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/index.html
    http://www.stanford.edu/class/cs193p/cgi-bin/drupal/

    public by marksimon232  2423  4  6  0

    AVAILABLE PYTHON RESOURCES

    http://www.agileinfoways.com/technical-expertise/python-development/
    https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
    http://stackoverflow.com/questions/70577/best-online-resource-to-learn-python
    http://pythonbooks.revolunet.com/
    http://www.agileinfoways.com/technical-expertise/python-development/
    http://resources.arcgis.com/en/communities/python/
    http://labs.physics.dur.ac.uk/computing/resources/python.php

    public by vdt  253  0  3  0

    resources for job applicants

    resources for job applicants: job_applicant_resources.md
    Hello!
    
    Here are some resources that I've used in my recent job search for full-stack web development positions. 
    Feel free to share.
    
    
    what questions to ask
    ---------------------------
    * https://jvns.ca/blog/2013/12/30/questions-im-asking-in-interviews is a good starting point to come up with questions to ask potential employers
    
    
    where to find tech companies
    --------------------------------
    * https://www.crunchbase.com/#/home/index was THE search engine for finding tech companies based on criteria
    * www.hired.com (where I ultimately found the place where I'm working at now, i love the transparent salary data)
    * https://angel.co for early-stage tech startups
    
    
    statistics on tech companies
    ---------------------------------
    * hired.com's annual reporto on market rate salaries: 
    https://hired.com/blog/highlights/hired-releases-second-annual-global-state-salaries-report/
    * ALL of hired.com's blog posts are well-researched, well-written
    
    
    algorithms interview prep
    ---------------------------------
    * https://www.interviewcake.com/ InterviewCake interactive in-browser questions
    * http://blog.gainlo.co/ has nice blog posts going in-depth on specific algorithms topics
    
    
    random apps
    ---------------------------------
    * MixMax: a gmail inbox plugin. Lots of features. The most useful feature for me was calendar scheduling for interviews.
    * any reminder app to alert me that I have N minutes before my next interview meeting and amount of traffic to get there
    
    

    public by guantalamo56  84  0  4  -2

    UWP: Get an image from local resources

    Build an Image object from local resources. The image should be stored as content in the Assets folder of the project.
    public static Image ImageFromName(this string imageName)
    {
    	if (imageName == null)
    		return null;
    	if (!imageName.StartsWith("ms-appx:///Assets/"))
    		imageName = "ms-appx:///Assets/" + imageName;
    	return new Image
    	{
    		Source = new BitmapImage(new Uri(imageName, UriKind.RelativeOrAbsolute))
    	};
    }				

    public by cghersi  21976  168  9  4

    How to run unit tests created with MS Visual Studio without installing Visual Studio

    Do you want to run your unit tests on your staging server? Surely you don't want to make your staging environment "dirty" by installing Visual Studio. I'm also not comfortable with installing the Test Agent. And perhaps you don't have the resources to use Visual Studio Online Continuous Integration stuff... It's not a problem of licenses. We don
    1) From C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow (copy all content of the folder):
    Extensions (folder)
    ActivateApplication.exe
    EntityFramework.dll
    extension.vsixmanifest
    Microsoft.TeamFoundation.TestPlatform.Client.dll
    Microsoft.TestTools.Cpp.targets
    Microsoft.VisualStudio.MSTest.TestWindow.dll
    Microsoft.VisualStudio.TestPlatform.BuildTasks.dll
    Microsoft.VisualStudio.TestPlatform.Client.dll
    Microsoft.VisualStudio.TestPlatform.Common.dll
    Microsoft.VisualStudio.TestPlatform.Core.dll
    Microsoft.VisualStudio.TestPlatform.Fakes.dll
    Microsoft.VisualStudio.TestPlatform.ObjectModel.dll
    Microsoft.VisualStudio.TestPlatform.TestExecutor.Core.dll
    Microsoft.VisualStudio.TestPlatform.Utilities.AppContainer.dll
    Microsoft.VisualStudio.TestPlatform.Utilities.dll
    Microsoft.VisualStudio.TestPlatform.Utilities.PhoneAppContainer.dll
    Microsoft.VisualStudio.TestWindow.Core.dll
    Microsoft.VisualStudio.TestWindow.CppUnitTestExtension.dll
    Microsoft.VisualStudio.TestWindow.dll
    Microsoft.VisualStudio.TestWindow.Interfaces.dll
    Microsoft.VisualStudio.TestWindow.pkgdef
    Microsoft.VisualStudio.TestWindow.VSTest.dll
    msdia120typelib_clr0200.dll
    TestWindowProvideCodeBase.pkgdef
    vstest.console.exe
    vstest.console.exe.config
    vstest.discoveryengine.exe
    vstest.discoveryengine.exe.config
    vstest.discoveryengine.x86.exe
    vstest.discoveryengine.x86.exe.config
    vstest.executionengine.clr20.exe
    vstest.executionengine.clr20.exe.config
    vstest.executionengine.exe
    vstest.executionengine.exe.config
    vstest.executionengine.x86.clr20.exe
    vstest.executionengine.x86.clr20.exe.config
    vstest.executionengine.x86.exe
    vstest.executionengine.x86.exe.config
    
    2) From C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC:
    vcvarsall.bat (put this file into a sufolder named "vc")
    
    3) From C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies:
    Microsoft.VisualStudio.QualityTools.Sqm.dll
    
    4) From C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0:
    Microsoft.VisualStudio.QualityTools.ExecutionCommon.dll
    
    5) For these files you need to use copy command from a DOS prompt, and then copy from c:/tmp to your staging folder: 
    copy C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Resource\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Resource.dll c:\tmp
    copy C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Common\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Common.dll c:\tmp
    copy C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel.dll c:\tmp
    copy C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.UnitTestFramework\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll c:\tmp
    

    public by sherazam  3006  0  6  1

    How to Create Thumbnails from PSD Files inside .NET Applications

    // Enter here the actual content of the snippet.         
    // Creating Thumbnails from PSD Files
    
    //[C# Code Sample]
    
    //Load a PSD in an instance of PsdImage
    using (Aspose.Imaging.FileFormats.Psd.PsdImage image = (Aspose.Imaging.FileFormats.Psd.PsdImage)Aspose.Imaging.Image.Load(sourceFilePath))
    {
        //Iterate over the PSD resources
        foreach (var resource in image.ImageResources)
        {
            //Check if the resource is of thumbnail type
            if (resource is Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)
            {
                //Retrieve the ThumbnailResource
                var thumbnail = (Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)resource;
                //Check the format of the ThumbnailResource
                if (thumbnail.Format == Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailFormat.kJpegRGB)
                {
                    //Create a new BmpImage by specifying the width and heigh
                    Aspose.Imaging.FileFormats.Bmp.BmpImage thumnailImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(thumbnail.Width, thumbnail.Height);
                    //Store the pixels of thumbnail on to the newly created BmpImage
                    thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData);
                    //Save thumbnail on disc
                    thumnailImage.Save("D:\\test.bmp");
                }
            }
        }
    }
     
    //[VB.NET Code Sample]
    
    'Load a PSD in an instance of PsdImage
    Using image As Aspose.Imaging.FileFormats.Psd.PsdImage = CType(Aspose.Imaging.Image.Load(sourceFilePath), Aspose.Imaging.FileFormats.Psd.PsdImage)
    	'Iterate over the PSD resources
    	For Each resource In image.ImageResources
    		'Check if the resource is of thumbnail type
    		If TypeOf resource Is Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource Then
    			'Retrieve the ThumbnailResource
    			Dim thumbnail = CType(resource, Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)
    			'Check the format of the ThumbnailResource
    			If thumbnail.Format = Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailFormat.kJpegRGB Then
    				'Create a new BmpImage by specifying the width and heigh
    				Dim thumnailImage As New Aspose.Imaging.FileFormats.Bmp.BmpImage(thumbnail.Width, thumbnail.Height)
    				'Store the pixels of thumbnail on to the newly created BmpImage
    				thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData)
    				'Save thumbnail on disc
    				thumnailImage.Save("D:\test.bmp")
    			End If
    		End If
    	Next resource
    End Using
    
    

    public by cghersi @ PLAT.ONE  3622  2  6  0

    How to consume JMS frames directly incoming from devices in PLAT.ONE

    This class can be used and modified to manage the JMS frames incoming in real time from the PLAT.ONE JMS Broker. The edgeware component of PLAT.ONE, that manages a set of devices, retrieves the information from the devices and publishes those information onto some JMS topics. This class represents a client that subscribes to those topics and is not
    package one.plat.extensions;
    
    import java.util.List;
    
    import helloworldservice.HelloWorldServiceImpl;
    
    import com.abodata.plat1.frames.dataTypeCode;
    import com.abodata.plat1.frames.serviceTypeCode;
    import com.abodata.plat1.jms.IDirectAMQConsumer;
    import com.abodata.plat1.jms.INetworkSubscriber;
    import com.abodata.plat1.jms.Interest;
    import com.abodata.plat1.jms.InterestType;
    import com.abodata.plat1.jms.MsgFormat;
    import com.abodata.plat1.jms.SIPCInterface;
    import com.abodata.plat1.logger.Plat1Logger;
    import com.abodata.plat1.network.addressing.NodeIdentifier;
    import com.abodata.plat1.network.node.data.Measure;
    import com.abodata.plat1.network.node.data.ParsedMeasurePayload;
    import com.abodata.plat1.network.node.data.PositionPayload;
    import com.abodata.plat1.queues.frames.BaseHeader;
    import com.abodata.plat1.queues.frames.Frame;
    import com.abodata.plat1.queues.frames.NextHeader;
    import com.abodata.plat1.queues.frames.Payload;
    import com.abodata.plat1.queues.frames.WSNDataHeader;
    import com.abodata.plat1.queues.frames.WSNnodeHeader;
    import com.abodata.plat1.ws.velocity.IProxyNetwork;
    
    public class DirectConsumer implements IDirectAMQConsumer, INetworkSubscriber {
    
    	private static final Plat1Logger log = new Plat1Logger(DirectConsumer.class);
    	
    	private InterestType[] interests = new InterestType[] {	
    			//get data from the field / devices
    			new InterestType(serviceTypeCode.doryService, dataTypeCode.dataPosition, false, this),
    			new InterestType(serviceTypeCode.doryService, dataTypeCode.dataAbsPosition, false, this),
    			new InterestType(serviceTypeCode.doryService, dataTypeCode.parsedDataReport, false, this), 
    
    			//check new networks
    			new InterestType(serviceTypeCode.wsnLifeService, dataTypeCode.event),	
    		};
    	
    	public void startConnection() {
    		log.warn("Start connection towards broker");
    		try {
    			HelloWorldServiceImpl.getAMQFactory().startConnection(getClass(), 
    					new Interest[] { 
    						new Interest(BaseHeader.BROADCAST_NETWORKID, serviceTypeCode.wsnLifeService, dataTypeCode.event, 
    									"", MsgFormat.XML, null, false) });
    			
    			HelloWorldServiceImpl.getAMQFactory().subscribeToNets(this, HelloWorldServiceImpl.getAPI().DB_GetVisibleNetworks());
    
    			
    			log.warn("Connection successfully opened!");
    		} catch (InstantiationException e) {
    			log.error("Cannot subscribe to nets due to " + e, e);
    		} catch (Exception e) {
    			log.error("Cannot subscribe to nets due to " + e, e);
    		}
    	}
    	
    	public void stopConnection() {
    		getSIPC().ipcClosePipe();
    		HelloWorldServiceImpl.getAMQFactory().remove(getClass());
    	}
    
    	@Override
    	public void consume(Frame frame) {
    		//filter unwanted frames:
    		BaseHeader bh = frame.getBHeader();
    		switch(bh.getDataType()) {
    		case parsedDataReport:
    			NextHeader header = frame.getNextHeader();
    			if ((header != null) && (header instanceof WSNDataHeader)) {
    				Payload p = frame.getPayload();
    				if ((p != null) && (p instanceof ParsedMeasurePayload))
    					manageDataFrame(bh, (WSNDataHeader)header, (ParsedMeasurePayload)p);
    			}
    			break;
    			
    		case dataPosition:
    		case dataAbsPosition:
    			NextHeader headerPos = frame.getNextHeader();
    			if ((headerPos != null) && (headerPos instanceof WSNnodeHeader)) {
    				Payload p = frame.getPayload();
    				if ((p != null) && (p instanceof PositionPayload))
    					managePositionFrame(bh, (WSNnodeHeader)headerPos, (PositionPayload)p);
    			}
    			break;
    			
    		default: //nothing to do here...
    			break;
    		}
    	}
    	
    	private void manageDataFrame(BaseHeader bh, WSNDataHeader header, ParsedMeasurePayload p) {
    		NodeIdentifier nodeID = header.getNodeId(); //device that sent the new data
    		
    		//which data configuration has been received (e.g. High=6 - Low=0 => OpMode)
    		int objIDHigh = header.getObjectIdHigh();
    		int objIDLow = header.getObjectIdLow();
    			
    		//actual value(s) of the data, with timestamp and unit(s) of measure.
    		//There can be several data associated to a single configuration, but usually there's just one information (m.getRank() = 1)
    		Measure m = p.getMeasure();	
    		
    		// do some stuff...
    	}
    	
    	private void managePositionFrame(BaseHeader bh, WSNnodeHeader header, PositionPayload p) {
    		NodeIdentifier nodeID = header.getNodeId(); //device that sent the new position
    		float[] coords = p.getCoords(); //new coordinates
    		
    		//whether those coordinates are absolute (latitude, longitude, quote), or relative (with respect to a known origin)
    		boolean isAbsCoords = bh.getDataType() == dataTypeCode.dataAbsPosition; 
    		
    		// do some stuff...
    	}
    
    	@Override
    	public InterestType[] getInterests() {
    		return interests;
    	}
    
    	@Override
    	public SIPCInterface getSIPC() {
    		return HelloWorldServiceImpl.getSIPC();
    	}
    	
    	@Override
    	public boolean isAbleToConsumeFrames() { return true; }
    	
    	@Override
    	public void consume(String arg0) {} //not used
    	@Override
    	public void consume(byte[] arg0) {} //not used
    	@Override
    	public boolean isAbleToConsumeBinaryMsg() {	return false; }
    	@Override
    	public boolean isAbleToConsumeTextMessages() { return false; }
    }            
    • Public Snippets
    • Channels Snippets