krypted.com

Tiny Deathstars of Foulness

Given the increased reliance on XML in scripts and exchanging data, a number of different solutions leverage XML traversal options to get all the things done. We frequently use path to bring a file into a script or program, or accept input from STDIN. The most basic task that we then perform is simply selecting an item from that file or STDIN and then variabalizing it. One common tool that we use here is Path. XPath calls these objects nodes, and uses path expressions to select these nodes. A path expression is the path along the xml input that is followed to find a piece of data.

There are some pretty standard wildcards the can be used with xpath, where node() watches any node, * matches any element node, @* matches any attribute node, helping to constrain output.

Supported expressions include:

  • node: This is a text input that identifies the name of a node to start a relative search from – for example site would select all nodes in a structure with the name site
  • . Identifies the current node (kinda’ like pwd in a shell)
  • .. Starts at the parent of the current node – for example,
  • / Starts traversal from the root node – for example, /computer would select any nodes that falls underneath
  • /computer meaning that these are absolute paths
  • // Identifies the nodes in an XML structure that match a selection wherever they may be – for example
  • //computer would select all nodes that contain //computer and search for other expressions below those that you may identify such as: ‘xpath //computer/general/mac_address’
  • //* Selects everything
  • //computer/* Selects all the child element nodes of everything that starts with computer
  • @ Select an attribute in an XML structure – for example ‘xpath //computer/general/@’
  • [1] This predicate selects the first item (or whatever number is identified, so xpath
  • //computer[3]/general/mac_address would return with the mac address of the third computer
  • [@PATTERN] Constrains found sets, so ‘xpath //computer/general/[@mac_address]’ identifies all computers with an actual mac_address attribute
  • //[@PATTERN=VALUE] Constrains a found set to all items where the attribute contains the value, so ‘xpath //computer/general/[@mac_address=00]’ identifies all computers with an actual mac_address attribute that has the value of 00
  • //[@*] Selects only items with something in an attribute (non-null), so ‘xpath //computer/general/[@mac_address=@*] (btw, rather than use an =, you can use > or <)
  • | creates compound matches. So ‘xpath //computer/general/mac_address | //computer/general/name’ would grab the mac_address and name of every computer
  • [last()] Identifies the last item, so ‘xpath //computer[last()]/general/mac_address’ would return the last computer’s mac address
  • [last()-2] placing a negative number after the parenthesis identifies descending orders from the end of a found set – for example, //computer[last()-2] Selects the second to last computer

Overall, as you can see xpath really makes traversing XML structures simple. Other tools and languages have their own ways, but most are similar in syntax.

November 15th, 2016

Posted In: Mac OS X, Mac OS X Server, Ubuntu

Tags: , , , , ,

I bet you thought this would be the article where I showed you how to make your computer curse more. Well, language can mean much more than that. In fact, Apple has dedicated a whole binary to switching your default language in OS X, in languagesetup. This command, located at /usr/sbin/languagesetup, is capable of changing the default language used by a system to a number of different languages. There are other ways to accomplish this, but none quite so easy. To get started, note that there are two ways to run languagesetup. The first is interactively, which I mostly use to figure out what I actually want to do with it. The second is using a standard command prompt, which I use for scripting.

Let’s start with the interactive. Simply run the command with no operators/verbs/whatevers:

languagesetup

This outputs a list of the languages that can be used in this way. Note that number 7 is Spanish.

WARNING: root access required to change system language
1) Use English for the main language
2) Utiliser le français comme langue principale
3) Deutsch als Standardsprache verwenden
4) 以简体中文作为主要语言
5) 以繁體中文作為主要語言
6) 主に日本語を使用する
7) Usar español como idioma principal
8) Usa l’italiano come lingua principale
9) Gebruik Nederlands als hoofdtaal
10) 주 언어로 한국어 사용
11) Usar português do Brasil como idioma principal
12) Usar o português europeu como idioma principal
13) Brug dansk som hovedsprog
14) Käytä pääkielenä suomea
15) Bruk norsk som hovedspråk
16) Använd svenska som huvudspråk
17) Сделать русский язык основным языком системы
18) Użyj polskiego jako języka głównego
19) Ana dil olarak Türkçe’yi kullan
20) استخدام اللغة العربية كلغة رئيسية
21) เลือกภาษาไทยเป็นภาษาหลัก
22) Vybrat češtinu jako hlavní jazyk
23) Magyar kiválasztása alapértelmezett nyelvként
24) Seleccioneu el català com a idioma principal
25) Odaberite hrvatski kao glavni jezik
26) Επιλέξτε Ελληνικά ως την κύρια γλώσσα
27) בחר/י עברית כשפה ראשית
28) Selectați româna ca limbă principală
29) Vybrať slovenčinu ako hlavný jazyk
30) Вибрати українську основною мовою
31) Gunakan Bahasa Indonesia sebagai bahasa utama
32) Gunakan Bahasa Melayu untuk bahasa utama
33) Sử dụng Tiếng Việt làm ngôn ngữ chính
34) Utilizar español de México como el idioma principal

At this point, you could just use the number 7 key (if we were root) and switch the default language of the system to Spanish. But, we’re going to go ahead and do that in a non-interactive fashion, using the langspec option:

sudo languagesetup -langspec 7

Or to switch it back, note that English is first:

sudo languagesetup -langspec 1

November 30th, 2015

Posted In: Mac OS X, Mass Deployment

Tags: , , , , , , ,

Learn some stuff! For Free!

There are so many resources available for learning these days that it’s hard to keep track of it all, or to find the things that are actually worth doing. So I decided to make a list of some of my favorites:

  1. Code Academy: Using Code Academy, you can learn a little JavaScript, HTML/CSS, jQuery, Ruby, Python and PHP. There are also projects for the web and integrating with APIs so you can hook into YouTube and Twitter. Screen Shot 2014-02-20 at 9.47.16 AM
  2. Duolingo.com: Learn a real language, like Spanish, Italian, German, Portuguese or French at this site, which has digestible chunks of lessons that you can use to get ready for that next work or personal trip, or just to make sure you continue to know more of a foreign language than your kid does when they come home from school.Screen Shot 2014-02-20 at 9.55.39 AM
  3. Learn Code the Hard Way: Free books? Learn to write Python, Ruby, C, SQL and even some regular expressions! Screen Shot 2014-02-20 at 10.25.41 AM
  4. Rails for Zombies: Learn Rails as a game. A nice, fresh approach to programming. You should know a little Ruby first, so check out tryruby.org or Learn Ruby the Hard Way first.Screen Shot 2014-02-20 at 10.24.49 AM
  5. Ted Talks: I didn’t really get these until I started to watch them. There’s over 1,600 Ted talks and counting. Want to learn about leadership, work-life balance, conducting an orchestra or how to motivate, this is your place. It’s a wealth of information from some very amazing people and what I now consider to be one of the best treasures online.Screen Shot 2014-02-20 at 10.19.58 AM
  6. Nike Training Club: Actually, the whole Nike experience, from Nike+ (Running, FuelBand, Kinect) to the skating app are awesome. But the Nike Training Club sports a collection of videos and workouts that are sure to push even the most fit to their limits. Screen Shot 2014-02-20 at 10.22.45 AM
  7. Make Games With Us: Learning programming doesn’t have to be boring. This site looks at building iPhone games. Screen Shot 2014-02-20 at 10.31.37 AM
  8. Stanford on iTunes: A lot of universities and other institutions have put a lot of content on iTunes U. But the quality of some of the Stanford lectures is IMHO) amongst the best! Check out what they have to offer, and search iTunes U for any other topic your heart may desire.Screen Shot 2014-02-20 at 10.34.17 AM

May 20th, 2014

Posted In: Articles and Books

Tags: , , , ,