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
license: mit |
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
// Which HTML element is the target of the event | |
function mouseTarget(e) { | |
var targ; | |
if (!e) var e = window.event; | |
if (e.target) targ = e.target; | |
else if (e.srcElement) targ = e.srcElement; | |
if (targ.nodeType == 3) // defeat Safari bug | |
targ = targ.parentNode; | |
return targ; | |
} |
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
// Add mousePosition on the Canvas element | |
(function () { | |
function mousePosition(event) { | |
var totalOffsetX = 0, | |
totalOffsetY = 0, | |
coordX = 0, | |
coordY = 0, | |
currentElement = this, | |
mouseX = 0, | |
mouseY = 0; |
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
import javax.script.Invocable; | |
import javax.script.ScriptEngine; | |
import javax.script.ScriptEngineManager; | |
import javax.script.ScriptException; | |
import java.io.InputStreamReader; | |
public class JavascriptBeautifierForJava { | |
// my javascript beautifier of choice | |
private static final String BEAUTIFY_JS_RESOURCE = "beautify.js"; |
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
public class MyServiceImpl extends DeviceServiceGrpc.DeviceServiceImplBase { | |
@Override | |
public StreamObserver<GetLocationRequest> getLocations(StreamObserver<GetLocationResponse> responseObserver) { | |
RequestBridge<GetLocationRequest> request = new RequestBridge<>(); | |
ResponseBridge response = new ResponseBridge((ServerCallStreamObserver) responseObserver); | |
request.map(this::doGetLocation) | |
.subscribe(response); | |
return request; | |
} |
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
In file MyApp/store/Menu.js | |
Ext.define('MyApp.store.Menu', { | |
extend: 'Ext.data.Store', | |
requires: [ | |
'MyApp.model.menu.Root' | |
], | |
model: 'MyApp.model.menu.Root', |
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
//return an array of objects according to key, value, or key and value matching | |
function getObjects(obj, key, val) { | |
var objects = []; | |
for (var i in obj) { | |
if (!obj.hasOwnProperty(i)) continue; | |
if (typeof obj[i] == 'object') { | |
objects = objects.concat(getObjects(obj[i], key, val)); | |
} else | |
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not) | |
if (i == key && obj[i] == val || i == key && val == '') { // |
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
/** | |
* A variant of the JSON reader. Instead of reading arrays, where each record in the array field | |
* has an 'id' property, it reads objects - aka associative arrays. The key of the entry will be the | |
* array. | |
* | |
* So where the JSON reader would like data like this: | |
* [ { id: '1', property: 'foo' }, { id: '2', property: 'bar' } ] | |
* | |
* the associative reader likes data like this: | |
* { '1': { property: 'foo' }, '2': { property: '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
/** | |
* Perform a deeply recursive reduce on a set of JSON, or a JSON-encodable Object hierarchy. | |
* | |
* @param {Array|Object} collection | |
* @param {Function} fn | |
* @param {*} memo | |
* @return {*} | |
*/ | |
function deepReduce(collection, fn, memo) { |