Skip to content

Instantly share code, notes, and snippets.

View t0r0X's full-sized avatar

Victor t0r0X

View GitHub Profile
@t0r0X
t0r0X / jq-cheetsheet.md
Created November 30, 2022 11:52 — forked from olih/jq-cheetsheet.md
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@t0r0X
t0r0X / show-seconds.ps1
Last active September 21, 2022 08:09
Enable the display of current time "seconds" part in Windows system tray clock, by changing the registry settings with PowerShell commands.
# Kudos @ Christian S.
# Changes might need restarting the Windows desktop ("explorer.exe") or logging out and back in, or rebooting the computer.
# query, might fail if key does not exist
Get-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowSecondsInSystemClock
# enable
New-ItemProperty -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced -Name ShowSecondsInSystemClock -PropertyType DWord -Value 1
# disable
@t0r0X
t0r0X / JNAWindowsRegistry.java
Created September 20, 2022 12:23 — forked from software-mariodiana/JNAWindowsRegistry.java
Accessing the Windows registry via Java, using JNA.
import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.WinReg;
/*
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
@t0r0X
t0r0X / jq-json-array-length.sh
Last active August 10, 2022 19:26
Determine JSON array length, handling errors
# See https://stedolan.github.io/jq/manual/
echo '{}' | jq 'if isempty(. | arrays) then "error" else . | arrays | length end'
# error
echo '[]' | jq 'if isempty(. | arrays) then "error" else . | arrays | length end'
# 0
echo '{}' | jq 'if isempty(. | arrays) then "input not an array"|halt_error(1) else . | arrays | length end'
# input not an array
@t0r0X
t0r0X / jqPlay.md
Created May 12, 2022 22:32 — forked from nikolay-n/jqPlay.md
jqPlay snippets collected using google and github search
@t0r0X
t0r0X / jq.test
Created May 12, 2022 22:32 — forked from diafour/jq.test
jq fromjson or tostring problem
try (tonumber) catch ("Should catch error")
"a20"
"Should catch error"
# Tests are groups of three lines: program, input, expected output
# Blank lines and lines starting with # are ignored
#
# Simple value tests to check parser. Input is irrelevant
#
@t0r0X
t0r0X / yk-tech.2020-01-09.md
Created May 12, 2022 22:31 — forked from wxgeorge/yk-tech.2020-01-09.md
Yukon Tech Collective January 2020 meetup notes

We investigated the tool jq.

Wes first encountered this as a query tool for JSON. Our probing with the tool lead us to believe that it is much more than this.

This author intends to investigate JSONPath in the future, as it feels targetted specifically at querying. jq is capable of arbitrary JSON transformations. There is also JMESpath which is described as query language for JSON (this author was under the impression JMESpath was also capable of JSON transformations, albeit a more limited set than jq allows for the expression of)

First we needed some JSON. @ryanagar noted the considerable breadth of Yukon GIS data. With the help of a query builder, we were able to pull down a blob, and the task for the group was to investigate it's structure w

@t0r0X
t0r0X / jq.md
Created May 12, 2022 22:30 — forked from thewheat/jq.md
@t0r0X
t0r0X / div.md
Created March 19, 2022 21:22
macOS stuff
  • Update software:

    • softwareupdate --all --install
    • softwareupdate --all --install --force
  • Install command line tools:
    sudo xcode-select --install

@t0r0X
t0r0X / jq generate sql.md
Last active November 30, 2022 13:32 — forked from ipbastola/jq to filter by value.md
JQ to filter JSON by value

Generate SQL statements, with placeholders like ^ for open parenthesis, ~ for closed parenthesis, and ! for ', because jq does not honor all escapes. Therefore requires post-processing with search & replace:

cat  .../data.json | \
  jq -r '.[] | ["insert into person^version, created_timestamp, modified_timestamp, extern, vorname, nachname, kennung, org_unit, telefonnummer, raumnummer, geburtsdatum, anschrift, eintrittsdatum, ausweis_nummer, ausweis_ablaufdatum, anmerkungen, firma_id~ values ^1, systimestamp, systimestamp, !Y!, !", .vorname, "!, !", .nachname, "!, !", .kennung, "!, !", .email, "!, !", .organisation, "!, !", .telefonnummer, "!, !", (.raumnummer|tostring), "!, !", .geburtsdatum, "!, !!, !", .beginntermin, "!, !", .ausweisNummer, "!, !", .ausweisGueltigkeit, "!, !!, ", (1|tostring), "~;"] | add' | \
  tr -d '"' | tr "^~!" "()'" \
  > .../V1.0.0_2__init-testdata.sql