Showing posts with label windows. Show all posts
Showing posts with label windows. Show all posts

Monday, June 29, 2015

Chocolatey - apt-get for windows

As a Windows user, I was quite envious of Linux/OS X tools like apt-get or brew... But not anymore!  I've just found the Chocolatey tool for Powershell which let's you easily find and install software on your Windows-powered PC.

Let's see an example:
Searching for Slack and installing afterwards





















This way you can maintain apps and versions on your PC using scripts.
If you want to check if there's an upgrade to any of your programs, just write:

choco upgrade all
If you want to give it a try yourself, visit https://chocolatey.org/  and follow the instructions

Tuesday, September 18, 2012

Powershell - the good and the bad. The story of a survivor.

Today's topic is Powershell - it's usefulness and weirdness.

It is the Microsoft super cool console which is used to provide command-line API for all of MS big products like Office, SQL Serveer, etc. It is build on top of .Net so every .Net class you write, you can take advantage of it in the command-line.

It has it's advantages:
- using objects and not strings for pipelining commands
- the .net framework
- ease-of-use - with just a few commands you can open up the Powershell world.
- very readable
- good help about_xxx articles

Let's start with the
Good Stuff

Pipelining is a powerful feature. You can pass multiple result objects from 1 command to the next one just like this:

How you delete everything inside a folder ?
Get-Item "c:\folder\" | Remove-Item -Force -Recurse #alias is dir or ls
How to see how to use a command ? What are its parameters? What does it do?
Get-Help "Get-Item" -Full  #alias is man or help 
What are the properties/methods of a process ?
Get-Process | Select-Object -First 1 | Get-Member #alias is gm

With just Get-Help (or man), Get-Member (or gm) and Get-Command (to list all available commands/functions/aliases) , you can do anything!


You'll use pipelining all the time! It's really cool!

Some nice hits are:
- filtering a collection of items by a property. Returns all folders with name ending with the string "project"
$folderList | ? { $_.Name -match ".*project" }
which is short way to write:
Foreach-Object $folder in $folderList | Where-Object {  $folder.Name -match ".*project"}

- doing a repetitive task on many objects. Display

$folderList = dir | ? {$_.GetType().Name -match ".*DirectoryInfo.*" }
$folderList | % { Write-Host "$($_.Name) - $($_.CreationTime)" }
- errors
When there is an error just get the automatic variable $Error (array of error objects) and check the last 5 errors $Error[0..5]


Main usage of Powershell is doing some quick check on something in the Microsoft infrastructure or writing a script to automate a routine tedious task like creating a report or killing all not-responding processes at the moment.
Overall system administrators will love it.
...

and here ends the good things... If you try to use it for something else, you'll hit many different obstacles:

Strange behaviour

Functions want to return something!

In fact, every function you call that returns an object, and the result is not saved in a variable, is automatically transfered as a result. OK, but when you have multiple such calls inside your function, these results are added into an array and here's the /unexpected behaviour/...
function myFunc(){
 Get-Process
 dir
}
$b = myFunc
$b.GetType()  --- #it says array

The other way to stop this from happening is to enclose the call with brackets and [void] the result like this:
 [void] (Get-Process)
The strange empty array

When comparing empty array to $null  with the comparison operator -eq (equals), doesn't return neither $true, nor $false...just ... nothing.

This is partially explained with the Powershell ability to auomatically flatten an array to its elements. When it's an empty array - the operation doesn't execute. But there's no error as well... or warning.

Try this:
@() -eq $null
and
$null -eq @()
Also if you are used to separate each function parameter with comma, you will have a hard time!

Using comma ( ,) will generate an array. Well, Powershell likes arrays a lot, and you will, too, but only after the initial struggle.


Using it for plain programming

Unfortunately, when you want to use it to code features, and even small frameworks, you hit

some obstacles like
- Visual Studio doesn't support it... at all! No other IDE with satisfying experience, too
- PowerShell ISE isn't feature-rich enough
- only suitable is Notepad++ with word completion and many macros along the way...
- no compile-time catching bugs like - unused variables, or undefined ones...


Unfinished or just plain broken features


Modules as Custom objects

As of Powershell v2, there is a new method to package commands (cmdlets) - modules (instead of snapins).

So you can import modules into the runspace or import them as CustomObject, which has
methods as the functions declared in the .psm1 file (module script file)

These CustomObjectModules are very buggy when it comes to multiple imports and generating exceptings...Trust me. The latter is very nasty...
I
magine writing a few modules which should use each other - common utils, etc. And then you have an exception. Now where exactly did the exception occur ? Try to get catch it with try-catch - the Error record contains only the row/execution line of your current module in development! Nothing about the inner exception or error stack... !! Which is not useful at all.

In order to be productive with these modules, I ended up writing my own ExceptionStackTrace building function which collected errors, line numbers, positioned the stack trace correctly, and stops when it reaches another stack trace (.Net one) which is descriptive enough...  Well, I'm sure it could have been done better, but it works stable enough and I like that it solved this problem which should have been handled by the Powershell Team!

Also nested imports fail from time to time with functions which cannot be found...
I am seriously, not going to use Modules as CustomObjects anymore... Too bad. Almost like Object-oriented programming... but with serious issues...

Remoting
While Powershell provides nice API for remote calls - Invoke-Command for executing single scriptblock and Enter-PSSession for interactive mode. They are thought quite nice, but unfortunately, the last few weeks I've come to the conclusion that they are quite fragile and I was often the observer of the following results:
- OutOfMemory Error
- Stopped execution without errors
- WinRM was not configured correctly errors pointing to articles in MSDN which weren't specific enough.


So basically here are my findings about Powershell Remoting:

- complex requirements for remote machine for the remoting to work. Not a single full guide for this.

- adding snapins remotely for machine with no Internet access - 2 minutes ! You have to turn off the Internet Options > Advanced > Security option to "Check for publisher's certificate invocation" and it will pass in seconds.

- remoting stops without any error or logs. Hard to debug. Could be missing configurations/rights, could be low memory

- slightly more complex remoting produces many errors. For example starting a new resource-hungry process on the remote machine results in OutOfMemory Error. Solved by increasing the memory per PowerShell property described at the end of the article.

- inconsistent behaviour - different errors for unchanged code

- lack of documentation for some of the features - only a few blog posts saved me a few hours/days

A few tips here:

- the remoting script you run should be as light as possible and should just execute a file/script located on the remote machine. This was you can lower remoting data transfers(logs, commands, variables, etc)

- for complex, time-consuming tasks use Invoke-Command xxxx -AsJob parameter. This way it will create invisible background thread, which will take even less resources. Actually, for my complex scenario , it proved to be the only working option...

Get-Item wsman:localhost\Shell\MaxMemoryPerShellMB 
Set-Item wsman:localhost\Shell\MaxMemoryPerShellMB 512 -Force

Conclusion:

Don't get me wrong. Using Powershell is overall an easy and straight-forward experience, but when you try something a bit more kinky and ... let's say that the 'fun' starts there.

Best regards,
Powershell-ill
Leni Kirilov

Tuesday, October 19, 2010

DevReach 18+19 October Sofia, Bulgaria (part6)

...continued

HTML 5 crash course


HTML 5 is connected with everything that is modern and flashy today. 
Introduction of iPad is in the same day as the HTML5 introduction.
Adobe vs Apple conflict.

"Apple is becoming the most important company in the US"

www.html5rocks.com - some tricks, a site recommended.

Browser vendors love HTML 5 because they don't want their products to be 'old'.
HTML 5 is pushed into the history.

HTML5 is not ready yet. It's good

The sad facts:

60% of Internet is used with IE6, IE5 and IE7 - they don't support HTML5.
60% Windows XP
15% still use IE 6.
91% of the browser users use Windows - they have the grip

Silverlight updates are quicker - they are pushed with automatic updates with Windows.

In his oppinion "Html 5 > 4"

www.html5test.com - test the browser about html5 support
Chrome - 217 + 10 bonus
IE8 - 27 + 0 bonus
Opera 10.61 - 159 + 7 bonus

Microsoft will never get 100% for ACID3 test because they don't want to support SVG fonts.

Syntax:
HTML5 template is with a DTD... nobody validates it with a DTD. "A pain in the ass" - quote.
AJAX was never specified.... they reverse-engineered it.
HTML5 has a spec - that makes it a lot different. The error behaviour consistent.

He simplified the HTML5... - charset, language, DTD validation - cleaner.

New semantic tags:
Old way - meaningless IDs for "div" tag
Google statistics : code.google.com/webstats about names of ID
They took the statistics and used the mostly used words and make them special words. They made the best practices rules in HTML5.

WebMatrix - interesting free tool for building web sites. Part of the WebPlatform. It's a direct competitor to PHP.
Razor + MVC  --- "in a 6 months will be the hottest thing"

"Microsoft's primary goals this year - Azure, IE9 and HTML5"

Modernizer - javascript lib for audio
html5shim .code.google.com -- javascript for adding HTML5 tags to IE6 (which doesn't support it)

html5 - audio tag
html5boilerplate - best add-on pack for html5

"Silverlight version of video is adaptive to the broadband width"

Google created a site to refer to for fonts instead of distribute them in your own site as a local copy.

L.K. 

Monday, October 18, 2010

DevReach 18+19 October Sofia, Bulgaria (part2)

...continued

Internet Explorer 9
Roman Russev from Microsoft Slovakia is speaking about it.
fast / clean / secure / interoperable

He takes notice of the new open policy of Microsoft - the open beta releases of Win7, IE etc

Interesting features are like pinning pages from IE directly to the taskbar of Windows7.


Visual Studio 2010 Light Switch
It's all about data and screens.
It's a tool for not-developers to create business applications - making it easier.

First step - "choose a language, you can decide how are you going to deploy it later"
Next step - describe the data for the application

It looks very point-n-click.

Next step - building a screen. Just adding a template hooks the data with the look.
Many out-of-the-box stuff added like - search bar, ribbon, tabs etc...

Looks pretty nice to have all these and not work hard to implement them.


L.K.

Wednesday, August 25, 2010

Dell Inspiron 1520 bugs

First of all I want to say that I'm very happy with my 2-year-old Dell laptop and his performance. This little piece of hardware (3 kg isn't that small...) has been very useful for me, writing some homeworks for the university, studying, chatting, even flirting, and of course preparing some projects connected with  Java, CPP and Python.

Anyway, but there are some flaws and I'll comment on a few of them

- strange noise

From time to the laptop starts beeping in a disturbing way... as if there is a flake of dirt in the CPU and the CPU's reading heads are registering it and the fast movement produces the squeaking sound ! Of course, that's not it, because CPU's units don't have moving parts... May be it's something in the HDD ... I hope not because I don't want lost bytes/files/hard-drives problem. It was a frightening sound the first few times, but I got used it .... because it happens quite often. May be once a month. And I'm using my notebook everyday...

- blue/black screen of death

I suppose this is due to my Windows 7 (and before was XP), but the message I got is always for a hardware malfunction and a memory dump is created. This has happened 4-5 times for these 2 years. Not good. But there was the moment I played Starcraft and it got it quite often... so may be it's a software glitch... Nevertheless it's not a
pleasant experience.

- I use Hibernate
I'm not using restart very often. I'm always hibernating and I can justify that this feature is GREAT! What hibernate does is save the state of all programs on your HDD (requires some free HDD space) and shuts down completely very quickly.
+ no power consumption compared to sleep
+ faster shut down compared to restart/shut down
+ faster start compared to restart/ shut down + start
+ all programs are already loaded and waiting for you!

People, use hibernate! Saves time and it's very nice.

A few more tricks help reduce the performance degradation:
- use programs like CCleaner to uninstall unused programs; clean registry; turn off start-up applications
- use defragmenters - your HDD becomes so unordered (fragmented) that a simple song play with Winamp makes your HDD heads travel looong distances and degrade performance. Of course all the small and constantly created/deleted files that a browser makes are "helping" for the situation. 

- DVD malfunction

In today's epoch of very fast Internet connection people need less and less CDs or DVDs storages, so basically I have almost never used my DVD and it's all in dust now. Well I tried to clean it, being careful with the lenses etc but the read speed is very low. But again may be it's a common problem when not using a device.

 - light up/down the Laptop screen on Windows 7

 When using FN+up and FN+down the display sometimes doesn't dim itself on all possible levels (8 levels of gray may be). For example 4-5 levels are active and the screen stays dark... Then you have to find the "Adjust brightness" option in Windows and using the software slider to move it and then it seems it resets which level how much darkness must set and then it manages to be from full dark to full light again...
Again this could be just a driver issue.
Later I found this to be connected with the Power plan chosen and with the cable of my AC adapter charger. When I unplug it and then plug it again, it fixes.

- Home button next to Power button

OK what's good is this button to me when I don't have Home Media Station or what was its name (a Dell software) because my laptop had not a single bit set when I bought it - completely empty (as I wanted it) and now it seems I cannot adjust what the button should do - for example open an Opera browser would be great... I'm very disappointed because I used some forum discussions solutions to setup my PC but... I failed...
Actually that was on my Win XP and now I'm going to try on Win7. Wish me luck!

//edit
I managed to set my Home Media Station button to Winamp :) Finally, I can use all buttons on my notebook.
I used this forum discussion to manage and configure the button :  link 

Leni Kirilov

Monday, May 24, 2010

JDK 1.6 installation problems

Today's topic is Java Developers' Kit.

I've had a peculiar problem with JDKs.  I wanted to install the latest version of JDK 1.6 update 18 at the time, but I also wanted to have JDK 1.5 so that I test my application with different compilers and runtime environments.

However there was some sort of problem with it (the source of it, I am unaware till this day) that caused my Windows  unable to detect my successful installation. I checked that on this special site java.com

I could also check it with an applet in a page - it said that I need to install java...

1. First idea - reinstall
I thought that my register was messed-up and ran CCleaner to clean it. That didn't help.

I decided to reinstall it and here's my first surprise:
After the successful uninstall and running CCleaner again (just to be sure), and decided to reinstall the JDK
I've got a very "funny" error message (something like this - I don't remember the correct caption):

"Installer has detected that you have JDK installed. Do you want to repair/reinstall it?"
If you click NO - the installer shuts down.
If you click YES - the following message appears:

"You don't have JDK installed on your machine!"

Holly shit ! Isn't that just a bit contradicting...

Obviously, the algorithm at the beginning isn't the same as the one at the end...

2. Second idea - install older version
OK. I cannot override this incorrect installation. So let's try to downgrade it a bit.
I decided to try JDK 1.6 update 17. When I run it it said:

"You have already installed a higher version of JDK" - installation finished!

Thank you very much, smart installer!

3. Third idea - ask Google
"OK stop trying to be a smart ass. There has to be somebody with the same problem that has a solution!" 
 was my thought.
Yeah, right... After many hours of searching and "smart solutions", none of them helped me.
I intend not to list them here... just too many and very customized...

One of them seemed promising to me.
Google helped me find a tool and step-by-step solution.

4. Forth idea - clean up registry 
I absolutely had no other choice than to try and clean my registry.

Including backing up my registry and using a free tool called "JavaRA"  that could help me maintain my system and Java versions and updates very well... well I tried it and it didn't help... I was very disappointed but maybe my expectations were just too great.


5. No idea - desperation
I was quite desperate that my JDK ws not correctly installed. My applets weren't working. Eclipse stopped working at a certain moment. NetBeans - too. I even had to use system restore... a total disaster.

And I just migrated to Windows 7 Pro 64bit version... which seemed nice for user but apparently not for JAVA users... Using Win XP I didn't have such problems (although I think I had a similar problem a few years ago).
...
but I had a workaround!!

6. The workaround  - JDK 1.7 unofficial!
Well, I was lucky I accidentally installed JDK1.7 which is still unofficial and doesn't overwrite the latest JDK 1.6. So when I installed and played around with PATH and JAVA_HOME variables and Eclipse and NetBeans configurations, I was able to continue with my Java project development.
But I was still unsatisfied, because this is just a workaround !

A developer must never be satisfied with a mere workaround!

Tuesday, May 18, 2010

Laptop battery preservation tips

I've made some research regarding laptop Lithium-Ion batteries, because I was concerned, that if I don't use it properly, I might damage the battery of my brand new laptop

I've find a few nice resources with plenty of explanation in the Internet but nobody said his/her suggestion was the true thing. So I decided to try a few strategies myself out.

Here's my story and make your own conclusions out of it:

----
I bought a Dell Inspiron 1520 back in 2008 September. It has a 9-cell battery Lithium-Ion.

It was said to be possible to work for 3 hours with normal usage on "power management settings" and I have tried it and it proved to be true. And I wanted to keep it this way for as long as possible.

I mainly use my laptop as a "desktop laptop" and it's constantly plugged to the AC adapter.
  • The idea was to discharge the battery to 30-50% and put it in a cold place (refrigerator) - this way it is supposed to be best preserved for a long time.
I decided to remove the battery and stick with purely AC power, but after a few accidental power cable plug-out ... I decided it's not such a good idea. The UPS feature is essential! 


The next idea proved to be more successful. I've put reminders every 2 weeks to use my laptop on battery only and drop it just under 50% of charge. This is somewhat of an exercise for the battery and it doesn't "forget" how to charge/decharge.
  • I put 2 week reminders in Google Calendar to use laptop on battery only till 50% battery capacity.

CONCLUSION:
I have used this technique for the last 24 months. I'm using these days the laptop more on battery only and it survives more than 2:30 hours. That is with slightly dimmed screen and power settings ON, Windows 7 and wireless put on. I'm using it as if it's on AC power.

So I think this little technique has helped me.
Comparison with a friend of mine using a Sony laptop only on AC power and now he says it manages to keep it on battery for about an hour. What a difference!


Piece of advice:
This strategy helped me, but can be harmful for your laptop and/or battery ! Do this on your own risk!
(I'm obliged to write this... )

L.K.

Sunday, May 16, 2010

Skype timestamp bug

Hello

I will now tell you more about the Skype bug I recently discovered. It's pretty easy to reproduce it.

All you need is a Skype chat conversation that has entries let's say, for the last 15 minutes.
And now you go to your clock time/date of your Windows (haven't tried it for Linux but I guess the result will be the same) and change it 15 minutes to the past.

Now you chat some more! The strange thing you should notice is that your 'new' entries are put between your other chat entries! This happens simply because they are ordered with key the time these entries are made.

So if you are chatting with Skype and decide to play with your clock , you will notice this strange behaviour.

ADVICE:
Don't change your clock settings unless you want your chat history scrambled. The Skype folks should document this somewhere.

L.K.

Saturday, May 15, 2010

Windows 7 Pro 64bit bugs

Hi, again,

I'm sharing my findings regarding Windows 7. I'm using Win7 Pro edition 64 bit, free for the students of my university. I thought that it's very well made and bug-free - all those open beta testing must have improved the new Microsoft OS.
It is indeed very good and a perfect successor of Win XP (I skip the unsuccessful experiment Vista), but I've found a few bugs - some very hard to find, others - hard to miss!

1. Navigation with "Back button" in Control panel.

Basically the case is the following:
- you enter the new Control Panel design - one can see some groups of settings in the center and some quick shortcuts on the left side. If you move your mouse over these links, a hand-cursor appears and if you click them, you are transferred to the corresponding menu.
How to see the bug?
- just click on a clickable content in the window (center part) and you should get to another place in the control panel.
- try to move your mouse over the left section with the quick links.
- click the BACK <-   arrow and you are back to the starting point.
- if you try to point over the quick links on the left again, some of them make the cursor change shape to hand, some of them not!
- if you click on some of these that don't make the cursor transform to hand , you will experience the bug - you are just sent to another menu, which doesn't correspond to the name of what you clicked!!! Absolutely without any reason... You can click XXX menu and get sent to YYY submenu... unpredictable feature is something one must try to avoid as best as possible.
The others that make the hand appear work OK...


2. Connection timeout leads to memory leak.

If you are using LAN network to connect to the Internet and you connect to your provider via PPPoE, you can experience this problem.

If your provider is down, but you try to connect nevertheless, it tells you something like "provider is down, try reconnect in 90 seconds" and the countdown starts...
If you have clicked "Automatic reconnect" on your connection settings, than your OS will keep repeating this for as long as you have setup... and I have set up something like 1000 - how could I predict that something wrong could happen:

- After 30-60 minutes of non-stop redialing, if you check task manager and see resources , you will notice that the process, which manages the redialing is consuming almost 1.8 GB of RAM !!! And continues growing...
Later I saw that the OS became absolutely non-responsive and even the mouse couldn't move... I haven't seen a problem like this for a long time... when you close the process, you can continue with your work, but of course very disturbing... and many nerves were wasted until I found the reason behind this.

My Internet provider had such problems for 2 days straight and I experienced this three times! I am very certain this is the reason. And I have enough RAM - 3 GB is more than enough for Win 7- 1.0 GB is taken up at start up.

CONCLUSION
- I have disabled "Automatic reconnect"
- I don't use quick links on the left, because they don't work in Control Panel (could be so elsewhere too...)
- I have created two bug reports to Microsoft site - no response and I don't expect.

For everybody who wants to report a bug to Microsoft Windows, you can do so here:
http://mymfe.microsoft.com/Windows%207/Feedback.aspx?formID=195
(I've spent quite some time to find this link - use it! 30 minutes now and a few hours in the past)

http://blog.hznet.nl/2009/03/can-i-still-send-feedback-with-windows-7-rc/
try this link - I have not tried this but it could work

So report whatever you see so that Windows 7 is better.
This is valid for every other software that you use!

L.K.

Wednesday, May 12, 2010

Just a reminder for my future posts

I'll write about the following topics in no particular order, unless somebody says explicitly that they are interested in a topic and I'll post it ASAP.

I'd like to remind myself to document my thoughts regarding these topics:

These topics will follow:
  • JDK 7 new features
    • what I like
    • what I don't like 
  • JDK 1.6 installation problems
    • hints how to solve the problems 
  • Sony PRS-600 Touch - my brand new reader (and all the fuss regarding getting it)
    • review
    • some hints, tips and tricks 
    • problems 
    • conversion tools 
  • Windows 7
    • connecting to network
    •  control panel (Back) button navigation
  • some bugs of my Dell Inspiron Laptop
    • DVD
    • strange noise 
  • Eclipse debugging
  • NetBeans 6.8 bugs
    • swing editor bugs - needs to be reported
    • main class problem
  • Laptop battery preservation  tips
    • because what I have done so far has proven me right - thoughts from experience
  • Internet Browsers
    • Opera thoughts
    • Chrome
    • Firefox
    • IE
  • Google Chrome OS
  • Android
  • Skype time stamp bug 
  • HDD partitioning problems
    • how not to make your data inconsistent because of pure mistake or lack of knowledge
  •  Test-Driven Development

    L.K.