Latest Posts in Software Development

Re: in Python

The problem is that your html variable is just a string containing this value
and not the actual HTML code ... the library that you have imported urllib2 .. use it to get the code from that page
Read urllib2
and also the example from there ..

import urllib2
response = urllib2.urlopen('')
html =

also.. should this >>> re.findall(r'<p>(.+),/p>', html)
be >>> re.findall(r'<p>(.+)</p>', html)?
and I am not sure if you read the link I gave you earlier about regular expression but the . matches any character including space. The + stands for that get all character that match the pattern stated which in our case was the . representing any character between <li></li> as in get all characters that match the pattern, as if it was only . without + it will simply return a single character that matches the pattern

Re: in Python

I tried this for testing:

>>> import urllib2
>>> import re
>>> html = ''
>>> re.findall(r'<p>(.+),/p>', html)

But the output was:


I tried other tags too but all outputs was [], what's the problem?

Re: in C

im sorry i've forgotten to add the testcases and alocate function . i've added them above .

Re: in C#

I'd just escape it:

string[] items = str.Split(new char[] { '°', '\''});
in C

i want to implement a kind of malloc and free function for a course project , now i have done something but i dont know whats the problem with access violation in this line :

head->next = (struct block_meta *) allocate(sizeof(struct block_meta));

i'd be glad if someone can help me fix it or even if someone have any better idea for implementing this , ( cause obviously my implementation has a lot of problems) . thanks

    #include <stdlib.h>
    #define DATA_SEG_SIZE 65536
    void* allocate(int size);

    char data_seg[DATA_SEG_SIZE];
    char* heap_top = data_seg;
    char* stack_top = data_seg + DATA_SEG_SIZE - 1;

    struct block_meta
        unsigned char size;
        struct block_meta *next;
        void* block_ptr;
    struct block_meta * first, *head;

    void* search_for_free(int size)
        head = first;
        while ( head != NULL )
            if ( head->size == size )
                return head->block_ptr;
                head = head->next;
        return NULL;
    void free_allocated(void* ptr, int size)
        head = first;
        if(head == NULL){
            first = (struct block_meta *) allocate(sizeof(struct block_meta));
            head = first;
        else if(head->next == NULL){
            head->next = (struct block_meta *) allocate(sizeof(struct block_meta));
            head = head->next;
        head->size = size;
        head->block_ptr = ptr;
        head->next = NULL;
    void* allocate(int size) 
    if ( search_for_free(size) != NULL )
        return search_for_free(size);
    else if ( heap_top >= stack_top )
        return NULL;
    heap_top += size;
    return (heap_top - size);

   int main()
    int *num;
    int *p;
    free_allocated(num, 8 * sizeof(char));
    p = (int *) allocate(8 * sizeof(char));
    free_allocated(p, 8 * sizeof(char));
    p = (int*) allocate(50*sizeof(char));
    return 0;
Solved in C#

I have strings representing an angle, of the format ddd°mm'ss''.
I want to get to the three constituents: degrees, minutes and seconds.
I first chopped off the seconds like this:
angleString = "ddd°mm'ss''";
string str = angleString.Substring(0, angleString.Length - 2);
Then I tried to do this, to get to the degrees,minutes and seconds:
string[] items = str.Split(new char[] { '°', '''});
But it gave an error on the ' character, saying: "empty char literal".
I solved by using this:
string[] items = str.Split(new char[] { '°', char.Parse("'") });
I find this rather clumsy.
It would be great if anyone over here can come up with a better way.
Could not find a solution elsewere. :o)

Re: in Python

I think the program should create a backup of itself before attempting to rewrite itself and restore the backup if anything goes wrong. It would be a minimal security feature if one wants to develop this.
IMHO, the main issue is that it is not very useful. A more standard procedure is that a program rewrites a configuration file and that this file is loaded when the program is executed. It is more robust, and it permits to reload the configuration file once it has been updated. Here reloading would mean restarting the program.

Re: in Java

I sense a non-argument here! If the goal is to write the simplest Java code then use a set. If this is a beginners exercise in arrays and algorithms then Slavi's algorithm with stultuske's addendum. My guess is that it's the beginner's version.

News Story: in Java

Addressing last weeks Securi-Tay conference hosted by the Abertay Ethical Hacking Society in Scotland, Stephen Tomkinson from the NCC Group detailed how Blu-ray players can do more than play videos; they can open up a new attack surface for the hacker. Tomkinson demonstrated a new tool that had been released in order to enable the investigation of embedded network devices, and used the network exposed features on a common Blu-ray player as an example. He showed how an innocent looking Blu-ray disc can actually circumvent sandboxes and present the hacker with control of the underlying systems. Of course, that innocent looking Blu-ray disc was anything but; it was highly malicious. The disc itself, by combining a number of vulnerabilities discovered in Blu-ray players, was able to both detect the player it was inserted in and then launch a platform specific malicious executable. It also played a movie, to do otherwise would be a tad suspicious. The full technical background is published here but essentially the rich features of Blu-ray interactivity are built using a Java variant called BD-J, this both user interfaces and embedded applications to be structured as Xlets which can be thought of as akin to web Applets. Tomkinson and his team managed to circumvent the JVM SecurityManager controls and gain access to the underlying OS.

Troy Gill, manager of security research at AppRiver, says that while exploits are interesting in as far as showing how seemingly harmless functionality can be leveraged to run malicious executables, avoiding the threat is quite simple. "You could start by disabling Autoplay, uninstall PowerDVD and avoiding DVD's from unknown origins" he advises, continuing "although it could potentially be used as one additional attack vector for a hacker who is trying various methods to breach a specific network, given the fairly straightforward defense, I do not see this becoming a very widespread issue." Tim Erlin, director of security and risk at Tripwire, warns that the problem here is that it is all too easy for the average consumer to "forget that the Blu-Ray player sitting next to their TV is really a full-fledged computing platform and member of their home network. While we talk about the Internet of Things as the future, we shouldn't ignore the embedded devices we've already adopted into our lives. There's a massive supply chain for the production of Blu-Ray discs, and while there are a number of security features in place, it's worth considering how a compromise early in the chain might allow for distribution of malware at scale via discs themselves. This is a threat model that has national security implications, both for attacks at scale and targeted attacks at specific individuals."

in Python

One day I got to wondering if it was possible to get a Python script to modify itself. After a few searches I found this solution that I present here. I did not write this code, but feel that it should be "paid forward" so others know that it is possible, and how to accomplish it. Basically the script reads itself into a variable, then REs the timestamp line which is then replaces with a new one. Next the modified code is saved back down. I could actually see a genetic algo modding itself as it goes so that it writes an optimal version of itself at the end. Pretty cool.

import sys, os, importlib, inspect, locale, time, re, inspect, datetime
from datetime import datetime
locale.setlocale(locale.LC_ALL, '') # Set the locale for your system 'en_US.UTF-8'
    # Main #
def main():
        # Main Code
            # Print the time it is last run
    lastrun = 'Tue Mar  3 03:17:46 2015'
    print("This program was last run at: <<%s>>.") %(lastrun)

            # Read in the source code of itself
    srcfile = inspect.getsourcefile(sys.modules[__name__]) ## Gets module name and path then extracts and stores file name and path.
    print("DEBUG srcfile: %s") %(srcfile) # DEBUG
    f = open(srcfile, 'r') ## Open connections to source file in "r" mode and stores connection in "f".
    src = ## Reads source file code into "src" variable.
    f.close() ## Closes file connection.

            # modify the embedded timestamp
    timestamp = datetime.ctime(
    match ="lastrun = '(.*)'", src)
    if match:
        src = src[:match.start(1)] + timestamp + src[match.end(1):]
            # write the source code back
    f = open(srcfile, 'w')

Software Development Tag Cloud