krypted.com

Tiny Deathstars of Foulness

WordPress has an app. That means there’s an API to normalize communication using a predictable programmatic interface. In this case, as with many others, that’s done using a standard REST interface to communicate. The easiest way to interact with any API is to just read some stuff from the server via curl. You can feed curl the URL to the API by using your URL followed by /wp-json – as follows, assuming a URL of http://www.krypted.com:

curl http://www.krypted.com/wp-json

To view header information:

curl -s -D - http://www.krypted.com -o /dev/null

In the below example we’ll ask for a list of posts by adding /wp/v2/posts to the URL:

curl http://www.krypted.com/wp-json/wp/v2/posts

You’ll see a list of some posts in the output along with a little metadata about the posts. You can then grab an ID and ask for just that post, using a post ID of 48390:

curl http://www.krypted.com/wp-json/wp/v2/posts/48390

You can also see revisions that have been made to a post by appending the URL with /revisions

curl http://www.krypted.com/wp-json/wp/v2/posts/48390/revisions

You can see comments with the comments route:

curl http://www.krypted.com/wp-json/wp/v2/comments

Or pages with the pages route:

curl http://www.krypted.com/wp-json/wp/v2/pages

Or users with the users route:

curl http://www.krypted.com/wp-json/wp/v2/users

Or media that has been uploaded with the media route:

curl http://www.krypted.com/wp-json/wp/v2/media

And the output of each can be constrained to a single item in that route by providing the ID of the item, which shows additional metadata about the specified item. And there are routes for categories, tags, etc.

There’s also some good stuff at https://github.com/WP-API such as https://github.com/WP-API/Basic-Auth which is a plugin that allows you to auth against the API.

curl --user admin:krypted http://www.krypted.com/wp-json/users/me

Not only can you look at user information, you can also add and remove posts. You would add by doing a -X followed by a POST and then feeding a file with the –data option

curl --user admin:password -X POST http://www.krypted.com/wp-json/posts --data @post.json

The output would then include the ID of your new post to wordpress. In the following example, we’ll get rid of the post we were looking at earlier using -X and DELETE in the URL, assuming a username of admin, a password of krypted, and a post ID of 48390:

curl --user admin:krypted -X DELETE http://www.krypted.com/wp-json/posts/48390

If successfully deleted the response would be as follows:

{
“message”:”Deleted post”
}

To dig in deeper, check out http://v2.wp-api.org/reference/posts/ where the whole schema is documented. You can also use the https://github.com/WP-API GitHub site to access a command called wp (as well as PHP, node, and java clients) that can be run at the command line for simple scripting interfaces. This could allow you to, for example, simply backup posts to json files, etc.

Also, it’s worth noting that various plugins will require their own interface (note there’s no themes or plugins route), such as woocommerce, interfacing with http://gerhardpotgieter.com/2014/02/10/woocommerce-rest-api-client-library/ or https://woocommerce.github.io/woocommerce-rest-api-docs/.

July 14th, 2017

Posted In: WordPress

Tags: , , , , , , , ,

A great new feature of Apple Configurator 2 is the command line interface for Apple Configurator: cfgutil. Go ahead and click on the Apple Configurator 2 menu and select Install Automation Tools from the menu.

Screen Shot 2015-10-01 at 2.55.05 PM

When prompted,

Screen Shot 2015-10-01 at 2.55.09 PM

Once installed, you’ll find cfgutil at /usr/local/bin/cfgutil.

October 27th, 2015

Posted In: Apple Configurator, iPhone

Tags: , , , , ,

When I was just getting started with AngularJS, I found jsfiddle.net, a site that allows you to enter some code and run it straight from a browser. So, what do you do first: Hello World of course. This one with a little input twist…

<!DOCTYPE html>
<html ng-app>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body>
Enter Your Name:
<input type="text" ng-model="name" />
<h1>Hello {{ name }}</h1>
</body>
</html>

Screen Shot 2015-09-08 at 1.58.35 PM

September 8th, 2015

Posted In: Java

Tags: , , , , ,

When you run a kill command to stop a process from bash or the javax.realtime.POSIXSignalHandler class, you’re sending what’s known as a POSIX signal to the process. These signals can be called via their numeric representations or the signal (e.g. with the -s option of the kill command). Signals include the following:

  • 1: SIGHUP – Close the controlling terminal when the controlling process dies
  • 2: SIGINT – Send a keyboard interrupt
  • 3: SIGQUIT – Quit from a keyboard/terminal
  • 4: SIGILL – Terminate illegal instruction with a core dump and don’t restart
  • 5: SIGTRAP – Send a trace/break trap (with core dump)
  • 6: SIGABRT – Process an abort signal
  • 7: SIGEMT – Send the signal when emulator traps happen
  • 8:SIGFPE – Terminate floating point errors (erroneous arithmetic operations) with a core dump
  • 9: SIGKILL – Kill a signal outright (kill cannot be ignored)
  • 10: SIGBUS – Terminate access (some portion of a memory object) with a core dump
  • 11: SIGSEGV – Terminate with a core dump – Invalid memory reference
  • 12: SIGSYS – Bad system call
  • 13: SIGPIPE – Terminate and write on the pipe
  • 14: SIGALRM – Timed kill of a signal
  • 15: SIGTERM – Software termination of a signal
  • 16: SIGUSR1 – User defined signal 1, with SIGUSR2 as user defined signal 2
  • 17: SIGTERM – Software termination of a signal
  • 18: SIGCHLD – Child status change
  • 19: SIGPWR – Send the signal when the system encounters a power failure
  • 20: SIGWINCH – Send the signal to a process when the window changes
  • 21: SIGURG – Ignore signal, high bandwidth data
  • 22: SIGIO – Terminate pollable event
  • 23: SIGSTOP – Stop executing (cannot be ignored or caught by an exception)
  • 24: SIGTSTP – Terminate a stop signal.
  • 25: SIGCONT – If stopped, continue executing a process
  • 26: SIGTTIN – Background process is attempting to read
  • 27: SIGTTOU – Background process is attempting to write
  • 28: SIGVTALTM – Expired virtual timer
  • 29: SIGPROF – Terminate Profiling timer
  • 30: SIGXCPU – Past the CPU time limit, terminate with a core dump
  • 31: SIGXFSZ – Past the file size limit, terminate with a core dump
  • 32: SIGWAITING – Suspend execution of the process until a defined signal is sent
  • 33: SIGLWP – Send when the implementing threading requires a signal
  • 34: SIGFREEZE – Deprecated
  • 35: SIGTHAW – Deprecated
  • 36: SIGCANCEL – Deprecated
  • 37: SIGLOST – Send the signal when encountering a lost file lock

To put these in practice, let’s use the kill command from bash, with the -s option followed by SIGTERM and then the pid number:

sudo kill -s SIGTERM 20341

July 5th, 2015

Posted In: Mac OS X, Mac Security

Tags: , , , , , ,

When you accidentally paste a code block in the wrong place…

May 13th, 2015

Posted In: Product Management, Programming

Tags: , ,

There’s another new conference in town! Well, not my town, but Vancouver. MacDev Ops is a hot topic. One that will only increase in the coming years. Thanks to Mat X and Brian Warsing for bringing about a brilliant conference.

Screen Shot 2015-03-23 at 10.43.50 PM

The conference will be held on June 19, 2015 and is an easy $99 if you sign up soon. Also, submit a talk if DevOps is your thing. They’re looking to bring the following topics to the table:

  • Puppet, Chef and other automation from Desktop to Cloud and back
  • Software deployment with Munki and AutoPkg: the app ecosystem surrounding it
  • Cool tools: demo of awesome Mac Admin projects from GitHub
  • DevOps: How to adopt Automation and Best practices in IT operations
  • Dev skills: workshops on Ruby, Git, Python, Javascript for Mac Admins
  • MDM: Profiles and Mac configuration management in the cloud

This is sure to be a good one. Check it out here!

March 23rd, 2015

Posted In: Mac OS X, Programming, Unix

Tags: , , , , , , , , , ,

Merry Christmas and to all a good night!

<html>
<head>
<title>Merry Christmas</title>
<script type="text/javascript">
function MerryChristmas()
{
   alert ("Merry Christmas!");
}
</script>
</head>
<body>
<a href="javascript:MerryChristmas()">MerryChristmas</a>
</body>
</html>

December 24th, 2014

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

Tags: , , , ,

Qlogic fibre channel switches are about the most common I see in Xsan environments. A common frustration when managing a Qlogic switch is that the Java runtime used to manage the switch is blocked from most OS X systems by default. But it’s pretty easy to get into them with a couple of minor adjustments.

To get started, first download and install the latest Java from here. Once installed, open System Preferences on your Mac and then open the Java Preferences. Here, click on the Security tab.

Screen Shot 2014-03-17 at 10.43.11 AM

Click Edit Site List… In the pop-up, click Add and enter http:// followed by the name or IP address of your switch.

Screen Shot 2014-03-17 at 10.42.45 AM

Click on OK to commit your changes. Then access the switch address from Firefox (what I use for these) or whatever browser you prefer. Because the switch has a self-signed certificate, you’ll be prompted with a  security warning. Here, click the checkbox for “I accept the risk and want to run this application” and then click on the Run button.

Screen Shot 2014-03-17 at 10.40.21 AM

You’ll then be prompted by another Security Warning dialog. This one is indicating that the Java applet is potentially unsafe. Because we somewhat trust Qlogic, click Don’t Block. You’ll have to click this one every time you access the switch.

Screen Shot 2014-03-17 at 10.43.48 AM

The switch interface then opens and you can manage your switch as needed.

Screen Shot 2014-03-17 at 10.45.20 AM

Enjoy.

March 24th, 2014

Posted In: Xsan

Tags: , , , , , , ,

I am releasing the Xsan Monitor that I’ve mentioned as alpha code.  There are still some updates I may do but for now I’m putting it out there for those who feel this is the kind of thing they can take use of.  Basically, it’s a Dashboard Widget that can run on an Xsan client or metadata controller.  When running it will display the CPU and RAM statistics of the Xsan processes.  If it’s the kind of thing you could use then please feel free to give it a test drive and let me know what you think at cedge@318.com or krypted@mac.com.  

Xsan Monitor is available on the Apps page of krypted.com.

February 2nd, 2009

Posted In: Xsan

Tags: , , , , , , ,

http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html

February 9th, 2005

Posted In: VMware

Tags: , , ,