Monday, May 27, 2019

decode encoded characters javascript

function decodeHtml(html) {
    var txt = document.createElement("textarea");
    txt.innerHTML = html;
    return txt.value;
}

javascript strip html from text

myString.replace(/<(?:.|\n)*?>/gm, '');

Friday, May 17, 2019

Tuesday, May 14, 2019

json pretty print with browser

JSON.stringify(obj, null, 2)

json read object to association list elisp

(setq result
(let ((json-key-type 'string))
(json-read-object)))

Using OAuth for a simple command line script to access Google's api

https://martinfowler.com/articles/command-line-google.html

Add blogger post from command line with python

create credentials:

https://developers.google.com/identity/protocols/OAuth2InstalledApp

create OAuth client ID, for consent screen add just a title, then create an Other type key and copy its client id and secret


install the python client library:

https://developers.google.com/api-client-library/python/apis/blogger/v3


use the sample to test the api with your credentials:

https://github.com/googleapis/google-api-python-client/tree/master/samples/blogger


the first time calling the sample you are presented with your consent screen for approval, give approval and from then on you can use the python api to perform operations:

https://developers.google.com/resources/api-libraries/documentation/blogger/v3/python/latest/

Thursday, May 9, 2019

ublock filter specific url only

Example:

||www.reddit.com/r/politics/^$document

emacs lisp count unique lines in region, sort results by count, elisp


(let (items)
  (dolist (item (split-string (buffer-substring (region-beginning) (region-end)) "\n"))
    (let ((match (assoc item items)))
      (if match
          (setcdr match (1+ (cdr match)))
        (push (cons item 1) items))))

  (pp (sort items (lambda (x y) (< (cdr x) (cdr y))))))