Skip to content

Instantly share code, notes, and snippets.

View joewiz's full-sized avatar

Joe Wicentowski joewiz

  • Arlington, Virginia
View GitHub Profile
@adamretter
adamretter / ant-show-deps.xqy
Created September 25, 2017 15:03
XQuery to display the dependencies tree of an Ant target
(:~
: XQuery to display the dependencies of an Ant target.
:
: There are two modes of operation:
: 1) Display all targets and immediate dependencies, specified by $project-file
: 2) Show a tree of a single targets dependencies, this happens when $target-name is set as well.
:
: External parameters:
: $project-file The initial Ant file to start parsing from (imports will be expanded)
: $target-name If specified we examine only a single target and produce a tree of all dependencies (recursively)

Technical details for https://stackoverflow.com/a/44169445/6730571

Details of investigation:

On a base system, /usr/bin/java is a symlink that points to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java, which is an Apple wrapper tool that locates and executes the actual java.

(Do not touch anything in those 2 system directories. It should actually be impossible due to "System Integrity Protection" anyway.)

If you don't have Java installed, attempting to execute java will open a dialog that invites you to install it.

@ismyrnow
ismyrnow / mac-clear-icon-cache.sh
Created May 5, 2017 19:28
Clear the icon cache on a Mac when you start seeing generic icons in Finder or the Dock
sudo rm -rfv /Library/Caches/com.apple.iconservices.store; sudo find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rfv {} \; ; sleep 3;sudo touch /Applications/* ; killall Dock; killall Finder
@CliffordAnderson
CliffordAnderson / anonymizer.xqy
Created March 10, 2017 21:01
Fold Left for Anonymizing Names
xquery version "3.1";
(: The credit for this idea goes to Joe Wicentowski :)
let $sentence := "The men attending the meeting were Mr. Anderson, Mr. Wicentowski, and Mr. Jones. The women attending were Ms. French, Ms. Ryder, and Ms. Callon."
let $names := ("Anderson", "Jones", "French")
let $replace := function($sentence as xs:string?, $name as xs:string) as xs:string? {fn:replace($sentence, $name, "Smith")}
return fn:fold-left($names, $sentence, $replace)
@jnovack
jnovack / bluetooth.sh
Created January 18, 2017 15:38
Control Bluetooth Daemon through Command Line OSX
#read the current pref, returns '0' for off and '1' for on.
defaults read /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState
#set bluetooth pref to off
sudo defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState 0
#set bluetooth pref to on
sudo defaults write /Library/Preferences/com.apple.Bluetooth.plist ControllerPowerState 1
#kill the bluetooth server process
@CliffordAnderson
CliffordAnderson / 01-lookup-words
Last active January 19, 2017 16:00
Looking up words in the OED with XQuery
xquery version "3.1";
let $word := "person"
let $request :=
<http:request href="https://od-api.oxforddictionaries.com/api/v1/entries/en/{$word}" method="get">
<http:header name="app_key" value="###"/>
<http:header name="app_id" value="###"/>
</http:request>
return http:send-request($request)
@xokomola
xokomola / example-table.xml
Created December 21, 2016 14:43
Create ODS Spreadsheet with XQuery and BaseX
<tables>
<table name="Sheet 1">
<thead>
<tr>
<td>A</td>
<td>B</td>
<td>C</td>
</tr>
</thead>
<tbody>
@ubermichael
ubermichael / normalize.xq
Created December 9, 2016 19:38
Normalize unicode by calling java native functions in eXist 2.2 where normalize-unicode() doesn't work.
xquery version "3.0";
(:
Sadly, the eXist 2.2 normalize-unicode() function is broken. So we call out
to the java one.
:)
declare namespace normalizer = "java:java.text.Normalizer";
declare namespace form = "java:java.text.Normalizer$Form";
declare function local:normalize($string as item()) as xs:string {
@CliffordAnderson
CliffordAnderson / convert-from-base-10.xqy
Last active December 30, 2016 02:43
Convert from Base 10
xquery version "3.1";
(: Converts positive integers between base 10 and base 2-10 :)
declare function local:convert-base($num as xs:integer, $base as xs:integer) as xs:integer*
{
if ($num > 0 and ($base gt 1 and $base lt 11))
then local:join-nums((local:convert-base($num idiv $base, $base), $num mod $base))
else ()
};
xquery version "1.0-ml";
declare namespace p = "http://www.mycompany.com";
declare option xdmp:mapping "false";
(:~
Returns z-score for the specified confidence value
For confidence values not in the lookup table,