{{error}}
{{(quickSearchResults.length>10)?'10+':(quickSearchResults.length)}} {{(quickSearchResults.length==1)?'result':'results'}}
{{result.title}} {{result.timeStamp | mysql2ymd }}
I am sorry, no such article was written yet.
Scriptless Angular toggle snippet
Not really scriptless - Angular runs the script.
No need to define variable in scope.
1 files attached: angularScriptlessToggle.html
angularScriptlessToggle.html
<table class='table table-bordered table-hover table-condensed table-compressed table-striped' style='width:auto; float:right'>
				<caption ng-click='toggleSummaryTable = !toggleSummaryTable'>Summary aggregate</caption>
				<thead ng-show='toggleSummaryTable'>
					<tr>
						<th ng-repeat='header in logData.summary.headers'>{{header}}</th>
					</tr>
				</thead>
				<tbody ng-show='toggleSummaryTable'>
					<tr ng-repeat='record in logData.summary.data'>
						<td ng-repeat='header in logData.summary.headers'>{{record[header]}}</td>
					</tr>
				</tbody>
			</table>
regular expression custom jQuery selector
1 files attached: jQuery.matches.js
jQuery.matches.js
var REGEXP_CACHE = {};

jQuery.expr[":"].matches = function (obj, index, meta, stack) {
    var expression = meta[3];
    var regexp = REGEXP_CACHE[expression] = REGEXP_CACHE[expression] || new RegExp("^" + expression + "$", "gim");
    var jElem = jQuery(obj);
    return (regexp.test((String(jElem.text())).trim()))
        || (regexp.test((String(jElem.val())).trim()))
        || (regexp.test((String(jElem.attr("placeholder"))).trim()))
};
sQuery - DOM proximity relevance
sQuery - easier way to identify HTML objects by jQuery CSS selectors. Identification based on DOM proximity relevance.
1 files attached: sQuery.js
sQuery.js
building an animation in R based on images from a folder
1 files attached: animationDraft.r
animationDraft.r
captures="\\\\raspberrypi\\hdd500gb\\surveillance\\captures"
cameras <- c('Poarta','Curte')
for(camera in cameras){
  #print(camera)
  #print(list.files())
  cameraFolder<-paste(captures,camera,sep="\\")
  print(cameraFolder)
  cameraDays <- list.files(cameraFolder)
  print(cameraDays)
  for(cameraDay in cameraDays){
    cameraImages<-list.files(paste(captures,camera,cameraDay,sep="\\"))
    print(length(cameraImages))
    firstHourImages<-(cameraImages[Vectorize(function(x){substr(x,8,11)<"0030"})(cameraImages)])
    firstHourImages<-rapply(list(firstHourImages),function(x){magick::image_read(paste(captures,camera,cameraDay,x,sep="\\"))})
    animation<-magick::image_animate(magick::image_join(firstHourImages))
    magick::image_write(animation,paste("c:\\users\\dragosmateis\\desktop\\ccc",camera,cameraDay,sep="_"),format = )
    #print(firstHourImages)
  }
}
2017-02-21
How to hide Spock stack traces when running tests written in Groovy.
2 files attached: IgnoreStackraceElements.groovy MyException.java
IgnoreStackraceElements.groovy
static {
        StackTraceUtils.addClassTest({ String className ->
            if (className.startsWith("org.spockframework.")) return false;
            return null;
        });
    }
MyException.java
import org.codehaus.groovy.runtime.StackTraceUtils;
public class MyException extends RuntimeException {
    public MyException(String message, Object... suppressed) {
        super(message);
        for (Object t : suppressed)
            if (t instanceof Throwable) this.addSuppressed(StackTraceUtils.deepSanitize((Throwable) t));
        StackTraceUtils.deepSanitize(this);
    }
}
Scala JSON Comparator
4 files attached: JsonComparator.scala left.json right.json output.txt
JsonComparator.scala
import scala.io.Source
import scala.util.parsing.json._

object JsonComparator {
  def compare(left: Any, right: Any, path: java.lang.String = ""): List[String] = (left, right) match {
    case (l: Number, r: Number) => if (l == r) Nil else s"$path: $l != $r" :: Nil
    case (l: String, r: String) => if (l == r) Nil else s"$path: $l != $r" :: Nil
    case (l: Set[_], r: Set[_]) => if (l == r) Nil else s"$path: $l != $r" :: Nil
    case (l: List[_], r: List[_]) =>
      if (l == r) Nil
      else if (l.length != r.length) s"$path.length: ${l.length} vs. ${r.length}" :: Nil
      else l.indices.toList.filter(it => l(it) != r(it)).flatMap(it => compare(l(it), r(it), s"$path[$it]"))
    case (l: Map[String, _], r: Map[String, _]) =>
      if (l == r) Nil
      else if (l.size != r.size) s"$path.count: ${l.size} != ${r.size}" :: Nil
      else if (l.keySet != r.keySet) s"$path.keys: ${l.keySet} != ${r.keySet}" :: Nil
      else l.keySet.toList.filter(it => l(it) != r(it)).flatMap(it => compare(l(it), r(it), s"$path/$it"))
    case _ =>
      s"$path: $left[${if (left == null) left else left.getClass}] vs. $right[${if (right == null) right else right.getClass}]" :: Nil
  }

  def main(args: Array[java.lang.String]): Unit = {
    val left = JSON.parseFull(Source.fromResource("left.json").mkString)
    val right = JSON.parseFull(Source.fromResource("right.json").mkString)
    compare(left.get, right.get).foreach(println)
    compare(left.get, left.get).foreach(println)
  }
}
left.json
{"node1": [1, 2, ["q","w"], "e"], "node2": {"node3": "value4","null": null}, "node3": 3, "node4": 4, "node5": 5.5}
right.json
{"node1": [1, "3", ["q", "w", 0], "e"], "node2": {"node3": "value4", "null": "null"}, "node3": "3", "node4": 4, "node5": 5.6}
output.txt
/node1[1]: 2.0[class java.lang.Double] vs. 3[class java.lang.String]
/node1[2].length: 2 vs. 3
/node3: 3.0[class java.lang.Double] vs. 3[class java.lang.String]
/node2/null: null[null] vs. null[class java.lang.String]
/node5: 5.5 != 5.6
More compact of generic node filtering in browser
"abc" - shows only those containing "abc".
"abc def" - shows only those containing both, "abc", and "def".
"abc !def" - shows those containing "abc" and do not contain "def".
"ab|cd !ef|gh" - shows those that contain "ab" or "cd" and don't contain "ef", either "gh".
1 files attached: filterNodes.js
filterNodes.js
function filterNodes(jQuerySet,value){
	let strContainsAnyOf=(haystack,needle)=>!needle.every(it=>haystack.indexOf(it)<0)
	var count=0;
	value=String(value).toUpperCase();
	var values=value.split(" ").map(it=>unescape(it)).filter(it=>it!='').filter(it=>it!='!');
	let expectations={}
	for(let value of values)
		(value[0]=='!')?(expectations[value.substr(1)]=false):expectations[value]=true;
	for(let node of jQuerySet.toArray()){
		var nodeValue=(''+node.innerHTML).toUpperCase().replace(/<[^>]+>/g, '');
		var visible=true;
		for(let value in expectations)
			if(expectations[value]!=strContainsAnyOf(nodeValue,value.split("|")))visible=false;
		$(node)[['hide','show'][1&visible]]();
		count+=visible;
	}
	return count;
}
Browser singletons - how to ensure a script is loaded only once
Browser singletons - how to ensure a script is loaded only once
1 files attached: require_once.js
require_once.js
window[Symbol.for('d1702070851-LESS loaded')]||addResource("//cdnjs.cloudflare.com/ajax/libs/less.js/2.5.1/less.min.js","js");
	window[Symbol.for('d1702070851-LESS loaded')]=true;
How to simply add less scripts to the web pages (without server-side compilation)
2 files attached: headerManipulation.js sample.js
headerManipulation.js
function createNode(nodeName,attributes){
	var node=document.createElement(nodeName);
	for(var k in attributes)
		node.setAttribute(k,attributes[k]);
	document.getElementsByTagName('head')[0].appendChild(node);
}
function addResource(path,extension){
	if(extension=='css')return createNode('link',{rel:'stylesheet',type:'text/css',href:path});
	if(extension=='js')return createNode('script',{src:path});
	if(extension=='less')return createNode('link',{rel:'stylesheet',type:'text/less',href:path});
	throw "Extension not supported: "+extension;
}
sample.js
addResource('https://w01bagdc/chromeExtension/<%domain%>.less','less');
addResource("//cdnjs.cloudflare.com/ajax/libs/less.js/2.5.1/less.min.js","js");
Simple function to select an HTML node on clicking (works on Chrome)
Simple function to select an HTML node on clicking (works on Chrome)
1 files attached: selectText.js
selectText.js
function selectText(element) {
    var selection = window.getSelection();
    var range = document.createRange();
    range.selectNodeContents(element);
    selection.removeAllRanges();
    selection.addRange(range);
}