Skip to content

Instantly share code, notes, and snippets.

View aurbano's full-sized avatar
🎯
ML

Alejandro U. Alvarez aurbano

🎯
ML
View GitHub Profile
@aurbano
aurbano / StringWildcardCompare.java
Last active August 29, 2015 13:57
String case insensitive comparison. It has wildcard search implemented, so for example to search for nodes containing NAME, use *name*
/**
* String case insensitive comparison. It has wildcard search implemented, so
* for example to search for strings containing NAME somewhere, use *name*.
* Strings that start with name and end with .txt use name*.txt
* @param str1 String that you will match against.
* @param str2 String to search for.
* @return True if found
*/
private boolean compareStrings(final String str1, final String str2){
String[] split = str2.toLowerCase().split("\\*");
@aurbano
aurbano / GoogleMaps_CenterCoordinates.js
Last active December 27, 2015 08:59
This is meant to be a browser bookmark. Add it and whenever you are seeing a Google Map you can use it to see the coordinates for the center of the map.
javascript:void(prompt('',gApplication.getMap().getCenter()));
@aurbano
aurbano / Safari iOS iframe file opener
Last active December 14, 2015 13:19
iOS file opener (pdf, ppt, doc) for iframes where Safari won't enable scroll or download. Store as a bookmark on Safari, it will open a new tab with the found files.
javascript:var%20regex%20%3D%20%2Fhttp%3A%5C%2F%5C%2F(.*)%5C.(pdf%7Cppt%7Cdoc)%2Fgi%3B%0Amatch%20%3D%20regex.exec(document.documentElement.innerHTML)%3B%0Avar%20sourceWindow%20%3D%20window.open(%22http%3A%2F%2F%22%2Bmatch%5B1%5D%2B%22.%22%2Bmatch%5B2%5D)%3B
@aurbano
aurbano / fast_distance.js
Last active January 14, 2020 10:54
JavaScript 2D distance in the usual way and a faster approximation
// Usual function
function distance(p1,p2){
var dx = p2.x-p1.x;
var dy = p2.y-p1.y;
return Math.sqrt(dx*dx + dy*dy);
}
// Faster approximation
function distanceApprox(p1,p2){
// Approximation by using octagons approach
var x = p2.x-p1.x;
@aurbano
aurbano / FirstCrush.js
Last active December 11, 2015 10:48
First Crush, makes already minified JS smaller, by @TpDown, code from http://js1k.com/2012-love/demo/1189
f='GNunescape(encodeURI)^},S M ^/2,B g=t=u=0,v={};Ky=2,z=M;y<=zy)Kh=0,l ^-y;h<lh)!v[e .substr(h,y)])K=1,f=h;~(f=5,f+y));)++,M=y;Ke @ v)(j=)>1 s=G*(j-1)-j-2;s>t||s==tj<u)t=s,u=j,g=e}X=g};Kd=1,F=[];d<127d)[email protected](d),!\']/.test!~5)F.p;F.sort(`a,bNa>b?1:a<b?-1:0}),Z";while((Y=F(B,X))a WX)%Y)+Y+X,Z=Y+Z;q W"\'^<aW\'"\')^?"\'":\'"\',Qfa.\\\\]/g,$&6RegExp(q,"g,"+q)";Ki @ gZe=fWg[i]),f=e%e;f)"},INdocum.getElemById},c.@sertAdjacHTMLbeforebeg@",["JS_cP8#box"De" #ed> Run?\' 8button" cr"Dr">\',"Cred_dPdivDi"></div>\']%"<br>)4r6onclick=` V=Ic6,S(V)4d6=Q4i6@nerHTML=V3V to "+Q3Q"4e6#edsetTimeoutQ)",0)}`function(_:"  cols99" rows12"D^.lengthW.split(P"></>\' N return Kfor(D id@in8@put type6.5a.@dexOf(e4,I3^+" +G(%.jo@(#checkvalue="replace(textarea.pop())v[e]=`a+q+/[\\r\\neval()+"B)(a);++if((e)"\\\\ushent ,\'< ){ =a&&")("';for(i in g=' #%34568@DKNPW^_`')e=f.split(g[i]),f=e.join(e.pop());eval(f)