Page 14 of 43

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 18, 2012 6:03 pm
by Anonymously Famous
I should really brush up on my Java.

Re: Programming, computers, etc. [Serious]

Posted: Sat Apr 21, 2012 12:39 am
by Anonymously Famous
Did something cool with Python today.

Scenario: We delivered a set of 100 or so files (with subdirectories and the works) to a client in UTF-8. They ask for it in "Unicode." I ask for clarification, since UTF-8 is Unicode. They clarify. They want all of the characters that are outside of ASCII to be escaped the Java way - that is, \uhhhh, where h is a hexadecimal digit.

First thought: How am I going to do that? AHHH!

Python to the rescue. It has it built in (with one minor modification)! For 8-bit characters outside of ASCII, it automatically escapes with \xhh. For characters that take more bits than that, it uses \uhhhh.

Here's my very short solution, with comments: (# indicates the beginning of a comment)

Code: Select all

src = r'root folder' #This had the location of the set of files

import os
from os.path import join
import codecs

for root, dirs, names in os.walk(src): #This loops through all of the directories and subdirectories.
    for name in names: #This loops through all of the files in the current directory.
        #r+ lets me read and write from the files. b basically means that the returns are conserved.
        with codecs.open(join(root,name), 'rb+', 'UTF-8') as a:
            #get the file contents in UTF-8, encode in ASCII, and replace characters outside of the ASCII range.
            #In one line.
            temp = a.read().encode('ascii', 'backslashreplace').replace('\\x', '\\u00') #The magic line.
            a.seek(0) #Reset the file cursor to the beginning.
            a.write(temp) #Overwrite the previous file content with the updated content.
print "Done!"

Re: Programming, computers, etc. [Serious]

Posted: Tue Apr 24, 2012 12:55 pm
by atomtengeralattjaro
Character encoding is a bitch. Nice job though.

My firefox has a weird issue.. but only on one profile.
It fails to load certain CSS files on some sites. For example on last.fm, or on http://www.bbc.co.uk/news/ . I've tried running a clean firefox profile (with the -p command line parameter), and it works fine, also they all work fine on any other browser. I've tried disabling my addons one by one, and even tried disabling combinations of them, and nothing worked. It's like the profile is corrupted somehow(?). I've even tried loading the css directly, simply http://cdn.last.fm/css/css/214220/master.css doesn't load in my firefox (file not found), while the very same url loads in everything else.
I'm using comodo dragon again. I like it, but the bookmark management is a little difficult. Otherwise it's a decent and fast browser.

edit: of course cleaning the cache and everything with CCleaner fixed it.
I still think it's a stupid thing.

Re: Programming, computers, etc. [Serious]

Posted: Tue Apr 24, 2012 3:14 pm
by Anonymously Famous
Glad you got it fixed. Bugs like that can be a pain to figure out.

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 25, 2012 11:33 am
by atomtengeralattjaro
i still haven't figured it out, I just fixed it.

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 25, 2012 3:26 pm
by Anonymously Famous
Good point.

The other day I fixed a problem with my wife's iTunes by clearing out her cookies in Safari. Go figure.

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 25, 2012 5:27 pm
by atomtengeralattjaro
Maybe clearing the cookies could cure cancer?

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 25, 2012 6:21 pm
by Anonymously Famous
I'll take care of the chocolate chip ones.

So... I've been spending some time on the Python FaceBook page...

The following is a modified form of something I put up on FaceBook last night:
I really shouldn't spend too much time helping people out with programming on FaceBook pages. Sooner or later, I find myself cranking out answers to someone else's homework assignment... :| Tip: If the question says "I can't use *insert the name of a widely used standard function here*," it's probably homework. Tread with caution.

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 25, 2012 7:10 pm
by atomtengeralattjaro
I just found your facebook page. Now I know all about you. You should be unsettled about this.

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 25, 2012 8:39 pm
by Anonymously Famous
I figured you might do that. There are some things available to the public, but not a whole lot.

Should I be on the lookout for strange friend requests?

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 25, 2012 8:44 pm
by atomtengeralattjaro
No, I'm not facebooking. I just have a fake profile that I can use for stalking people occasionally finding information about stuff only posted on facebook.

Re: Programming, computers, etc. [Serious]

Posted: Wed Apr 25, 2012 11:46 pm
by assdef
Is your profile picture that of a submarine?

Re: Programming, computers, etc. [Serious]

Posted: Thu Apr 26, 2012 2:39 pm
by atomtengeralattjaro
no..

Re: Programming, computers, etc. [Serious]

Posted: Thu Apr 26, 2012 2:54 pm
by Anonymously Famous
Why not?

Re: Programming, computers, etc. [Serious]

Posted: Fri Apr 27, 2012 2:35 am
by gh0st
(sorry to interrupt anyones topic) has anyone here programmed an arduino? just wondering what code i should learn

Re: Programming, computers, etc. [Serious]

Posted: Fri Apr 27, 2012 6:13 am
by Anonymously Famous
From here, here and here, it looks like it's C/C++, in the form of a Wiring project. It looks like it does try to simplify things.

Re: Programming, computers, etc. [Serious]

Posted: Mon Apr 30, 2012 8:48 pm
by Dreams
arduino
Sounds like a narwhal.
Anyways.... I recently got almost-scammed when I tried to get Ubuntu, and I got a site that tried to get me to pay for it. :(

Re: Programming, computers, etc. [Serious]

Posted: Mon Apr 30, 2012 9:14 pm
by atomtengeralattjaro
:o that would require skill.. pretty hard to miss ubuntu.com

oh wait.. it seems it threw me a nice big error.. some drupal crap. Maybe it got compromised earlier.

Re: Programming, computers, etc. [Serious]

Posted: Mon Apr 30, 2012 9:19 pm
by Dreams
Unlikely. The real site is ubuntu.net or something like that.

Re: Programming, computers, etc. [Serious]

Posted: Mon Apr 30, 2012 10:48 pm
by Anonymously Famous
According to Google, it's www.ubuntu.com.

Cool! For a really user-friendly way to install Ubuntu, there's even an Ubuntu Windows installer!