Linux: Run a process as daemon in background from SSH

When a process supports daemon mode, you can either run it in a screen instance or init.d script.

If you had to kill off a rogue daemon and need to start it again via SSH, you can restart the daemon with a very simple addition to the command:

For example you have /bin/daemon_process with the parameters "--daemon --log-path=~/logs/blah/"

You can execute it with:

/bin/daemon_process --daemon --log-path=~/logs/blah &

The extra & at the end makes it spit output to the current terminal, but it wont wait for the daemon to finish.

Source

Android: Issues with opening files in Cyanogen Mod 7

Some people contacted me with problems trying to open files in my CodePeeker app on CM7. The OI File Manager built into the CFW is returning something unexpected, causing the app to fail in opening files.

This resulted in a few "1 star - DOES NOT WORK" ratings...

This is MADNESS! Why!?

The reasoning behind this is because OpenIntent's OI File Manager wasn't returning data according to the Android specifications.

They've written a small blurb about it and provided the backward compatible code here.

I didn't realise this but apparently I've covered a neater version of the code in a previous post.

If you ever need to test it, install the app on your emulator. The old version of OI File Manager v1.1.4 can be found on Google Code.

Testing

You can test the normal behaviour with File Expert, a great app for browsing files. Astro File Manager sucks with ads + confusing user interface. You can grab the APK for the emulator here.

srvgq
Crisis averted!

Sources

Python: Make transparent areas in PIL image to white (or any other solid opaque colour)

I had some issues with transparent PNG images causing some strange effects when resized and saved with Python's PIL Image library.

image image

image image

As you can see, those jarring effects are hard to ignore.

The issue was I was ignoring the alpha channel during conversion and PIL didn't quite know what to do with it.

It is a bit more work, but the results speak for themselves. Even the GIF image quality was improved after using this method!

image image
You'll have top view them at 100% to see the difference.

Update 6/12/14:

I found a better way of colouring the images which had NO loss in quality (updated code above)

345_shirt_438cef451b28326350794f77d38fe83d_B 345_shirt_438cef451b28326350794f77d38fe83d

(Shirt design "Majin Power!" by ddjvigo)

You can easily see which one is rendered with the new code as the difference is quite noticeable.

There was a bug which replaced the whole pixel with white, which is wrong because it could be any other colour with transparency < 255.

(Here's the old code if anyone was wondering)

Sources

Django: Set datetime.now() in a Form

A tricky little devil this one. For instance, you've got a "created" date in your form and you need it to be set to the current date whenever the page is displayed.

So immediately you go and do this

class SomeForm(forms.Form):
test_datetime = forms.SplitDateTimeField(initial = datetime.datetime.now())

First load, sweet it works. But load the page again, and you'll realise the date is still the same! FUUUUUUUUU!

1283775594667

It seems that the initial date/time is resolved when the server is first initiated. So, how do we fix that?

Easy!

class SomeForm(forms.Form):
test_datetime = forms.SplitDateTimeField(initial = datetime.datetime.now)

Can you spot the difference?

uhERp

Just remove the () from now(). That's it! If we pass it a function, it'll evaluate it on display.

PostgreSQL: Fix for "Error connecting to the server: server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request."

image

Error connecting to the server: server closed the connection unexpectedly

This probably means the server terminated abnormally before or while processing the request.

If you're running Windows, PostgreSQL and you've seen this, it's probably driving you bonkers!

No matter what programming language you use, what interface library or even the default client, you'll get this damn cryptic error!

Thankfully, the solution is simple. Postgre is fine, your setup is not broken.

NOD32

If you've got Nod32 antivirus, then it is known to have some incompatibility issues. Apparently you have to find "postmaster.exe" and add it to the exclusions list.

That can be done via "Setup" > "Advanced Setup Tree" > "Antivirus and Spyware" > "Exclusions" > "Add".

NetLimiter

Otherwise, you'll also have issues if you have NetLimiter.

image

I'm still rocking the old v1.30 so these instructions will vary with the newer ones.

  • Find the "postgres.exe" entry
  • Click on the "Info" tab at the bottom
  • Click "Ignore all traffic"

This worked like magic for me, so I hope it helps you too!

7386_1df8

Now back to practicing things that matter, like walking on air!
PS. SHE IS HOT!

Sources

PostgreSQL: Alter table field CHAR length

So the annoying thing about character fields is that they have a limit.

When you try to save the row and the data is too long, it'll fail.

So to increase the limit, run this query:

ALTER TABLE tablename
ALTER COLUMN url TYPE varchar(500),
ALTER COLUMN description TYPE varchar(300);

That's it! The fields url/description will now have the lengths of 500/300 respectively and maintain the original data.

notsochewyballoonsp1
BOOM! Headshot!

Source

django: Filter by field value in row on model

A bit hard to describe in words, but easier in an example.

Say for instance I have these values in my database table.

id | rowA | rowB
----------------
1  | 3    | 1
2  | 3    | 2
3  | 3    | 3
4  | 3    | 4
5  | 3    | 5

To find the rows where rowA >= rowB, you just use the F class.

from django.db.models import F
Model.objects.filter(rowA__gte=F('rowB'))

So easy but never crossed this before!

0D00v

Source

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog