Skip to content

Instantly share code, notes, and snippets.

@tit
tit / getelementbyxpath.js
Last active December 27, 2021 10:45
Javascript => getElementByXPath
document.getElementByXPath = function(sValue) { var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); if (a.snapshotLength > 0) { return a.snapshotItem(0); } };
document.getElementsByXPath = function(sValue){ var aResult = new Array();var a = this.evaluate(sValue, this, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);for ( var i = 0 ; i < a.snapshotLength ; i++ ){aResult.push(a.snapshotItem(i));}return aResult;};
document.removeElementsByXPath = function(sValue) { var a = this.evaluate(sValue, this, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for ( var i = 0 ; i < a.snapshotLength ; i++ ) { a.snapshotItem(i).parentNode.removeChild(a.snapshotItem(i)); } };
@Boldewyn
Boldewyn / evaluate_404s
Created August 28, 2013 09:27
Use bash-foo to print all Apache log 404s in the order how often they appeared
#!/bin/bash
LOGFOLDER=/var/log/apache2
FIELD=7
HTTP_CODE=404
LOG_BASENAME=access.log
cd "$LOGFOLDER"
# print all zipped logfiles (suppressing errors)
@maxhoffmann
maxhoffmann / gist:7373563
Last active December 27, 2015 18:59
run local php server and open browser
# local PHP Server
server() {
url="localhost:${2:-8000}"
if [ -z "$1" ]; then
php -S $url & # run server in background
else
php -S $url -t $1 &
fi
sleep 0.3s # wait for server to start
@daytonn
daytonn / .colors
Created January 28, 2014 21:50
Bash Color functions
# Colors
end="\033[0m"
black="\033[0;30m"
blackb="\033[1;30m"
white="\033[0;37m"
whiteb="\033[1;37m"
red="\033[0;31m"
redb="\033[1;31m"
green="\033[0;32m"
greenb="\033[1;32m"
@NickBarreto
NickBarreto / iBooks popups which degrade nicely in other devices
Last active February 2, 2019 16:33
How to create popup footnotes in iBooks which degrade well for other EPUB3 readers
The only requirements for popup footnotes in iBooks are:
* Ebook has to be an EPUB3
* epub:type "noteref" and "footnote"
So you can link to a totally separate document, as you normally would for endnotes,
but include the attributes so the <a> link behaves differently in iBooks, instead triggering the popup.
Original reference link would look something like this (in a file called ch001.html):
<a epub:type="noteref" href="footnote.html#note1">1</a></div>
@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@rponte
rponte / get-latest-tag-on-git.sh
Last active July 4, 2024 10:55
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@JayPanoz
JayPanoz / portrait-caption.css
Last active September 7, 2018 15:45
Experimental CSS to get portrait-aspect-ratio image + caption on same page, on reflow
/* Current nugget */
/* This in your fallback CSS (for ePub 2) */
.portrait-caption {
height: 99%; /* must check if necessary */
margin: 1.5em 0;
page-break-before: auto;
}
.portrait-caption > img {
width: auto;
@JayPanoz
JayPanoz / broken-in-eBooks.md
Last active January 30, 2021 16:05
Here’s a list of fundamentals which are broken in eBooks’ Reading Systems

Broken in eBooks

I hate being ”that guy” but someone must do the dirty work and list all the basic stuff which eBooks’ Reading Systems break in reflow.

So, here’s the stuff you can’t rely upon… Brace yourself, nightmares are coming!

Important advice: make sure your demos/test-case files span several “pages” and don’t rely neither on the results you get on “document ready” nor on the results which are displayed in the first column, usually at the top of your xhtml file. I’ve checked a certain amount of demos for which those issues didn’t show up because of that. Problem is if you publish a tutorial/article and people don’t double-check by themselves, it may lead to catastrophes.

For your information…

@ctipper
ctipper / About.txt
Last active October 17, 2018 14:33
OSX app menu compatibility shim for JDK 9+ releases
Abstract:
Hooks existing preferences/about/quit functionality from an existing Java app into handlers for the Mac OS X application menu.
It is tailored to provide compatibility with the Java 10 releases so that an app may be built on other platforms.
This work was inspired by an OSX compatibility layer provided by Apple that used a different API. This is an otherwise original contribution and is a reimplementation using newer interface methods.
Usage: