Skip to content

Instantly share code, notes, and snippets.

@pbakondy
pbakondy / play.js
Last active June 7, 2021 22:08
Play with Object.prototype.toString.call()
// under Google Chrome 36
Object.prototype.toString.call([])
// "[object Array]"
Object.prototype.toString.call(function(){})
// "[object Function]"
Object.prototype.toString.call({})
// "[object Object]"
Object.prototype.toString.call(null)
// "[object Null]"
@pbakondy
pbakondy / ieversion.js
Created August 18, 2014 11:39
Get IE version
// determine Internet Explorer version
// add class 'ieX' to html
window.ieVersion = (function() {
var ddm = document.documentMode;
var html = document.documentElement;
if (Math.round(ddm) === ddm){
if (html.classList) {
html.classList.add('ie' + ddm);
} else {
html.className += ' ie' + ddm;
rem Count lines of the recursively found XML files
rem You can rename *.xml to anything else
@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%t in ('dir /s /b *.xml') do (
for /f "tokens=* delims= " %%a in (%%t) do (
set /a N+=1
)
)
rem print timestamp (valid for Hungarian language settings)
rem result: 2014.08.29. 13:48:52
set datecode=%date:~0,4%.%date:~5,2%.%date:~8,2%. %time:~0,2%:%time:~3,2%:%time:~6,2%
echo %datecode%
<!--
Apply CDATA tags in XSLT
-->
<xsl:template match="/">
<DOCUMENT>
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:apply-templates />
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</DOCUMENT>
</xsl:template>
@pbakondy
pbakondy / rsaEncrypt.js
Created September 17, 2014 14:57
RSA Encrypt with forge
/**
* RSA Encrypt a String with Public Key
*
* @uses forge encryption library
* @param <String> text - string to encode
* @param <BigInteger> modulus - public key modulus
* @param <BigInteger> exponent - public key exponent
* @return <String> - encoded string in hex
*/
function RSAEncrypt(text, modulus, exponent) {
@pbakondy
pbakondy / parseUrl.js
Last active January 5, 2016 10:12
Parse URL
// Parse URL
// References:
// http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
// https://github.com/angular/angular.js/blob/c94329a891a1c082567c490ccf58ba8592b464ad/src/ng/urlUtils.js
(function() {
window.parseUrl = function(url) {
var href = url,
a = document.createElement('a');
if (document.documentMode) {
a.setAttribute('href', href);
/*
* Note: this code is for Angular.js v1.3 or earlier
* In Angular.js v1.4+ you can use angular.merge()
*
* Extends the destination object `dst` by copying all of the properties from the `src` object(s)
* to `dst`. You can specify multiple `src` objects.
* @param {Boolean} deep If true, the merge becomes recursive (optional aka deep copy)
* @param {Object} dst Destination object.
* @param {Object} src Source object(s).
* @returns {Object} Reference to `dst`.
@pbakondy
pbakondy / consecutive.js
Last active August 29, 2015 14:09
Angular directive to check consecutive characters
var app = angular.module('myApp', []);
app.directive('consecutive', function () {
return {
require: 'ngModel',
restrict: 'A',
priority: 50,
link: function(scope, elem, attrs, ctrl) {
if (!ctrl) return;
@pbakondy
pbakondy / example.java
Created April 14, 2015 08:21
How to return boolean value in a cordova android plugin
// How to return boolean value in a cordova android plugin
public class ExampleClass extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("test")) {
try {
boolean result = testAction();
callbackContext.sendPluginResult(new PluginResult(Status.OK, result));
} catch (Exception e) {}