Get power consumption on iMac - swift

I want to read out and log my iMacs power consumption. Anybody has an idea how I can do that.
Swift, Shell or Ruby would be great!
Thanks a lot,
André

It sounds like you're talking about a non-laptop that doesn't use a battery, so there isn't nearly as much useful power usage information available as you might be able to get for a laptop that does use a battery.
But either way, if this were my problem I'd start writing a Swift app or a command line tool that incorporates the IOKit framework, which has a few header files with useful information, such as IOPowerSources.h and IOPSKeys.h.
More detail can be seen in the "Hardware Access Options" section of this Apple documentation.

Related

How to connect HC-05 to MSP430

I am trying to use Bluetooth module HC-05 with MSP430 by Texas Instrunments.
I want the bluetooth module to collect data wirelessly from an android phone via bluetooth. Can anyone please help me?
You will find an answer and the end. But first I need to write a few introducing words.
You are new to SO and, you might wonder why no one answered your question.
If I should guess: IMHO there could be two main reasons for this.
Your question is not specific enough:
What kind of TI MSP430 do you intend to use? I suppose you use a launchpad G2(?).
What have you tried so far? You can not expect someone else to invest some time if you did not try so solve your problem yourself. Perhaps it easy, if you only try. The people here love to help, but they expect you to be interested in the problem.
What is your backgroud: Are you a programmer but do not know how to connect the hc05 to the MSP or are you fit in electronics and connecting MCUs? Are you a complete beginner?
There are so much cases and I would not have the time to handle all.
I used google to search "MSP430 HC-05" and found a lot of usefull stuff. The first hit is a project working with a Energia IDE, a HC-05 module, a G2-Launchpad and even an Android phone. I and probably other people do not understand why you did not try to search the internet for information.
Ok! enough wise words! ;-)
Here is the promised answer:
You find an example project with the following URL: http://www.electronicwings.com/ti-launchpad/hc-05-bluetooth-module-interfacing-with-msp-exp430g2-ti-launchpad
More results can be found: including (Youtube) Videos
- Keywords: HC-05 MSP430
Please try to work with that material and feel free to ask furter questions here.
But please be sure to be a bit more specific. (Code examples, error messages, your configuration and hardware and what you've tried so far.)
Cheers PPK

is there a popular open source NSLog replacement that handles enabling only in DEBUG and different log levels?

Is there a well known / popular NSLog replacement/approach that many iPhone developers are using?
That is one that handles ensuring debug type logging only appears in debug states (macros etc), and support for different log levels (DEBUG, WARN, INFO, ERROR etc)?
I understand there may not be loads of work in implementing this but am curious to know if there is popular download a lot of iPhone developers are using that already solves this.
I use Marcus Zarra's prefix.pch. it used to be at http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/ but the website is down now, was copied to this gist
It doesn't have as many levels as you want, but it gives you enough of an idea of how you would do it.
CocoaLumberjack is a simple yet powerful logging utility. With a few lines of code you can send all your log statements to the console or a file, or both. Or even to a database.
Plus it's fully customizable. For example, you can customize how many levels there are.
https://github.com/CocoaLumberjack/CocoaLumberjack
https://github.com/CocoaLumberjack/CocoaLumberjack
seems active even now (May 2011).

Self modifying code - iPhone

After reading this wikipedia article :
http://en.wikipedia.org/wiki/Self-modifying_code
I am wondering if this technique has been done on iPhone.
Thanks
Thierry
A standard iPhone application is unable to set a memory page as executable. So, it's impossible to modify your own code or generate code at runtime (ie.: Just In Time compilation).
A jailbroken device will allow you to have such pages though.
Not allowed by apple, and I believe it's physically prevented, the code space can't be modified, and code cannot run from the data space. (Jailbreaking could fix this however)
Three things that are most trecherous:
Connectors that corrode
Recursive algorithms
And self modifying code
-- traditional programmer's chanty
Self modifying code is the easiest and surest way to make code behavior completely unpredictable. It's something that is interesting academically but it is seldom a practical tool.
As near as I can tell, it's primary use is to wreak vengeance on an employer when you know you're going to be fired.

Any good library or software for queue networks simulation?

I have been trying to make work EZSIM with no luck, which is a software to build discrete event simulators in a graphical DOS environment. In this software, my simulator and many others (of the other people in the course I'm taking) don't work, but teacher's simulator (and examples of the downloaded files) does work.
So, I began to distrust of the software.
Do you know any software that resolves the same kind of problems but really works? It will be good if it is free, or I can download an evaluation copy or something like that.
If you don't know any software, do you know any library which might work? Preferably in C#, Ansi C, Java or Delphi.
This may be more than what you're looking for, but check out NS2. It's the standard for open source network simulations, and will allow you to simulate all kinds of network layer behavior.
I've also used JUNG in the past. It's very flexible, although it also doesn't offer much out of the box.
I used Möbius in my computer systems analysis class. It is free for educational use (which sounds like what you're doing). It's a Java GUI which generates C++ code.
The R package queuecomputer. queuecomputer is a computationally efficient method for simulating queues with arbitrary arrival and service times. There is a submitted paper on arXiv describing the algorithm used in the package. Examples can be found within the arXiv paper and the vignette. A web app based on the package is available at https://ace-ebert.shinyapps.io/queue_simulator_mmk/ .

Pitfalls of developing for iPhone

Are there any guidelines on pitfalls to avoid while developing iPhone applications?
Sure, thousands. The same is true for any software development. Unfortunately, the easiest way to enumerate them is to write them down on a sheet of paper while waiting for a friendly soul to release you from the one you just fell into.
However:
Don't try to reinvent the wheel. The iPhone API is very complete -- you just have to LOOK for the facility you need. Things are NOT always implemented the way you would expect. Read the guides, carefully. Look at the tutorials and analyze how they work. (Try changing a line here or there in the tutorial to see what difference the change makes.) The single biggest mistake I have made in 1 year of iPhone development is not trying hard enough to find the iPhone way of doing something.
Don't ignore memory management; master it early and often. Use the Object Allocation and Leaks tools in Instruments to check for memory leaks frequently. I'd recommend checking after you complete each feature or view; more often than that if you keep finding bugs. Eventually you may understand it so well you can stop doing this.
Don't just use the default build settings. Play around with them to understand what they do. Figure out certification and distribution. GET INTO THE DEVELOPER PROGRAM QUICKLY -- it can take a while to push through that pipeline. [ AND when you get that notification that you need to renew, get it on instantly -- there have been problems with that process. ]
Don't neglect to read the Human Interface Guidelines (HIG) carefully. If they say not to do something -- DON'T DO IT. Apple will reject applications that misuse their iconography.
Don't stint on marketing. Yes, the App Store puts your app in front of millions of people... In theory. But the odds of getting front-paged are slim. There are a lot of great apps on the App Store that haven't sold much because no one knows about them.
Don't rest on your laurels. If a new technology comes out, find out if it makes your job easier; if it does, take the time to learn it. Personal example: I'm just now trying to switch from SQLite-based data management to Core Data, because I was in a hurry at the time I started my most recent project; now I wish I had slowed down and thought about it.
Don't go into your design thinking (for example) "How do I implement my concept with a table view?" It's true that table views are natural for many informational and utility applications, but don't be constrained. Instead, think about what users will want to be able to do, how you can make it easier for them -- put things together that will be used together, etc. If you've never explored the concept of Use Cases, read up on them.
Don't hesitate to build composite views. Many of the questions I have seen here on Stack Overflow have to do with putting a toolbar at the top of a table, or having an image in the background of a text field. I understand the desire to do things the easy way, and as I state in #1 above, if there is an easy way, use it. But in many cases the solution is just to layer a couple of views with appropriate placement and transparency.
Think about what might be Apple-approved from the start.
App Rejected is one of several useful sites to help understand Apple's mostly undocumented standards. (One more.) (A previous question on app store rejection reasons.)
A few quick examples:
Using a UIWebView can get your app a 17+ rating.
Coding with an undocumented/private API = rejected
Version number < 1.0 might= rejected
Not enough feedback about network success/fail = rejected
Too much network use = rejected
Clearly limited free version vs full version = rejected
The word 'iPhone' in the app name = rejected
The above links contain many more examples, and more details about those examples.
Don't neglect the programming guides. While the documentation is quite extensive, the programming guides contains a veritable trove of useful tips and "insider" information that simply cannot be gleaned from reading method definitions. I spend just as much time reading the guides for a technology (say, Core Data) as I do actually implementing it.
Don't assume you know what a method does. If you have any degree of doubt about the functionality of a method, it is well worth your time to go look it up in the documentation to verify.
Wonderful examples from #Amagrammer above.
I would love to add that the first place to start is iPhone development is Photoshop. This is still the best advice I can give to anyone who is starting out. I now use OmniGraffle because it has awesome stencil templates.
What I find is that even for super simple app's, draw up your prototype and look for usability issues and work flow issues. It is 100x quicker to redraw your app than re-code it. I have fallen into this trap numerous times and now actually draw up some pretty simple functionality to see what it will look and feel like.
This advice will save you 10s maybe even 100s of hours in hopefully getting your app right first time and getting you to think through what the issues are. Throwing away code sucks and I have done it not because the code was bad but because it made the usability or solution worse. I think the best of us end up throwing code away and prototyping your design definitely will help in having to RTFM for something you did not have to build in the first place.
If you don't have an great designer, and can't do great design by yourself, then don't even start iPhone app development. This rule only applies if you want/need to make money with your apps.