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 / 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)e=Str@g.fromCharCode(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)
@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 / 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 / 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 / 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 / print_json.php
Last active August 29, 2015 13:57
PHP implementation of print_r to allow customization of the results
<?php
function print_json($json) {
if (is_array($json) || is_object($json)) {
echo "<table width=100%>";
$type = 'Array';
if(is_object($json)) $type = 'Object';
echo '<tr><td colspan=2 style="background-color:#333333;">
<strong><font color=white>'.$type.'</font></strong>
</td></tr>';
foreach ($json as $k => $v) {
@aurbano
aurbano / AndroidEmulatorLaunch.bat
Last active August 29, 2015 13:58
Android Emulator launch batch script using a proxy and a custom AVD
@ECHO OFF
ECHO Launching Emulator
ECHO Using AVD: AVD_for_4_WVGA_Nexus_S
emulator -avd "AVD_for_4_WVGA_Nexus_S" -verbose -http-proxy "http://20.42.128.36:8080" -netfast -gpu on -no-boot-anim -noaudio
PAUSE
@aurbano
aurbano / neo4j-pathFiltering.cypher
Last active December 5, 2016 15:06
Neo4j: Return paths that contain only 1 node with a given property
// Match all the paths you are interested in, store them as p
// then set n.property to the appropriate value.
// the final 1 means how many nodes with that property/value you want in the paths
MATCH p=(c)-[:REL_TYPE*]-(n)
WHERE LENGTH(FILTER(n IN EXTRACT(n IN nodes(p) | n) WHERE n.property = "value"))=1
RETURN DISTINCT n
@aurbano
aurbano / demo.html
Last active August 18, 2016 15:39
jQuery Draggable bring to front
<script type="text/javascript">
$('.drag').bind('click',function(){ bringFront($(this), '.drag'); });
</script>
@aurbano
aurbano / demo.php
Last active August 29, 2015 14:06
Display all files in folder
<?php
include('displayFiles.php');
displayFiles('pictures');