chriswelborn 63

@sa_2, on line 282 you mixed single quotes with double quotes. The syntax highlighting shows it right here:

cout<<'  \t\t¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥\n\n\n";

Next time start a new question, so more people can help you.

ddanbe commented: Nice +15

chriswelborn 63

It's been a while since I messed with VB, but I can't find anything that sticks out as far as the overflow situation. It's hard to read anything the way you're building those queries. I'm pretty sure that they're prone to SQL injection anyway. Have you looked at prepared statements? So the user can't just enter 2016-22-13'); DROP TABLE Employee_Information; into txtDateOfHire?

Can you print some kind of stack trace, showing exactly where the error takes place?

chriswelborn 63

@jayamkoko, you may have better luck posting a new question that describes your problem. This question was already marked as 'solved'. I think I may be the only one receiving updates on this question, and there are people far better than me with C# that could help you. I'm not sure if you mean a String.toCharArray() conversion (which would still be XML), or getting at the raw image data. Anyway, a new 'unsolved' question may help you get the answer that you are looking for.

chriswelborn 63

This will never end because you are appending to lista_cosas while iterating over it. I'm not really sure what you were trying to figure out, but this code will run (and create 1024 Cosa's):

lista_cosas=[]
class Cosa():
    def __init__(self,color):
        self.color=color

    def __repr__(self):
        return 'Cosa({!r})'.format(self.color)

    def operacion(self):
        global lista_cosas
        if self.color=="verde":
            lista_cosas.append(Cosa("azul"))
        else:
            lista_cosas.append(Cosa("verde"))
c=Cosa("verde")
lista_cosas.append(c)
print('Initial: {!r}'.format(lista_cosas))
for _ in range(10):
    for cosa in lista_cosas[:]:
        cosa.operacion()

print('After: {!r}'.format(lista_cosas))
print('Length: {}'.format(len(lista_cosas)))

chriswelborn 63

I think it would help if you weren't shadowing the cosa name in your for loop. Classes should use CamelCase, to distinguish them from function names and other stuff. Instantiating a class is like calling a function, so if you are instantiating a Cosa, and not trying to call a Cosa instance (like in the loop), it should work. print(repr(cosa)) should tell you which you are dealing with.

chriswelborn 63

This would probably fail miserably if you landed on a page like: example.com/zippedapplication.tar.gz

It assumes the response is encoded plain text with possible gzip compression, not gzipped binary data.

chriswelborn 63

The data is compressed with gzip. I tested it with:

$ curl http://stores.ebay.com/honesty-seller-ly9999 > bad_data
$ file bad_data
      bad_data: gzip compressed data, from FAT filesystem (MS-DOS, OS/2, NT)

The site is served with the header Content-Encoding: gzip, which isn't correct unless you request it with a Accept-encoding: gzip. Anyway, this is a very minimal example of automatically decompressing pages like this. I'm using Python 3 and urllib (which differs from Python 2's urllib a little):

from gzip import GzipFile
from io import BytesIO
from urllib import request

def get_url(url):
    """ Open a url and return it's response.
        If the response is compressed using gzip, then decompress it.
    """
    # I haven't included any error handling here.
    con = request.urlopen(url)
    data = con.read()
    if con.headers.get('content-encoding', None) == 'gzip':
        # Server says the data is gzipped, use a bytes stream with GzipFile.
        fd = BytesIO(data)
        # The fileobj keyword is important.
        # We want a file object, not a file name.
        return GzipFile(fileobj=fd).read()

    # Not compressed, return normal response.
    # In Python 3 this is still encoded, and needs to be decoded
    # with the correct encoding (utf-8?).
    return data

response = get_url('http://stores.ebay.com/honesty-seller-ly9999')
print(response.decode())

That is enough to get the correct data out of that page.

chriswelborn 63

It looks like you are hard coding each possible answer. It would take pages to exhaust every possibility. Maybe try splitting the input on -, and parsing the two values you need (using strsep() and sscanf()). Once you have the two values, you can calculate whatever value you need.

chriswelborn 63

..Commenting to move from 'Unanswered.'

In the future, you may want to provide more information (such as a small example of what you have tried so far). For now, this article will help you learn how to ask smart questions to get smart answers:

How To Ask Questions The Smart Way

chriswelborn 63

..Commenting to move from 'Unanswered.'

In the future, you may want to provide more information (such as a small example of what you have tried so far). For now, this article will help you learn how to ask smart questions to get smart answers:

How To Ask Questions The Smart Way

chriswelborn 63

..Commenting to move from 'Unanswered.'

In the future, you may want to provide more information (such as a small example of what you have tried so far). For now, this article will help you learn how to ask smart questions to get smart answers:

How To Ask Questions The Smart Way

chriswelborn 63

..Commenting to move from 'Unanswered.'

In the future, you may want to provide more information (such as a small example of what you have tried so far). For now, this article will help you learn how to ask smart questions to get smart answers:

How To Ask Questions The Smart Way

chriswelborn 63

..Commenting to move from 'Unanswered.'

In the future,you may want to provide more information (such as a small example of what you have tried so far). For now, this article will help you learn how to ask smart questions to get smart answers:

How To Ask Questions The Smart Way

chriswelborn 63

I was about to post this same message. It opens automatically when I load a page, and that's neat, but closing it only lasts for thirty seconds or so. I thought it was a new message when it opened the second time. I guess it just wanted to be open.

chriswelborn 63

This was posted in the wrong forum (looking for Software Development -> Java). I'm posting to remove from 'Unanswered'.

chriswelborn 63

Put the form on your page with an id (let's say 'contactForm') and css set to 'display: none', so it's easily accessible with javascript but initially hidden. Make your "show form" button/link/whatever with an onclick event (there are multiple ways to do this):

<a href='#contactForm' onclick='javascript: show_form();'>
    E-mail me.
</a>

Here is one way to implement show_form(). There are lots though. If you are already using some framework, they probably have a cross-browser way of doing this (such as jQuery's $('#contactForm').toggle() and $('#contactForm').css({'display': 'block'})):

function show_form() {
    var frm = document.getElementById('contactForm');
    frm.style.display = 'block';
}

Your cancel button will also need to be handled, so that clicking the button hides the form.

var cancelbtn = document.getElementById('cancel');
cancelbtn.onclick = function () {
    var frm = document.getElementById('contactForm');
    frm.style.display = 'none';
}

Here is an ugly jsfiddle displaying the behavior. I would suggest studying up on JavaScript if you're not already in the process.

tobyITguy commented: helpful. +3

chriswelborn 63

What is the content and type of cfg.project["samples"][0]["files"]["bam"]? A Tuple/List/Set/Dict? Maybe stepping through a debugger, or even a simple debug-print would help you see what you are getting, or why you're not getting what you think you should.

testdata = cfg.project['samples'][0]['files']
print('Actual files content:')
print('{!r}'.format(testdata))

print('Actual bam content:')
print('{!r}'.format(testdata['bam']))

Also, there are a lot of lists being concatenated here, I guess to build up command-line arguments. Command line args are fickle at times, and could possibly be broken by the concatenation (or concatenating in a certain order). I'm reaching here, but it's possible.

chriswelborn 63

This ID generator depends on enough time elapsing between calls. I can see that running this kind of code in a fast loop could make duplicates:

for (int i = 0; i < 10; i++) {
    Console.WriteLine (DateTime.Now.ToString ("hh-mm-ss.ffff"));
}

Output:

05-16-12.2358
05-16-12.2779
05-16-12.2780 // <- Many duplicates are created.
05-16-12.2780
05-16-12.2780
05-16-12.2780
05-16-12.2780
05-16-12.2780
05-16-12.2780
05-16-12.2781

It could also be a problem elsewhere. If you can guarantee enough time has passed between calls, and it's impossible to generate duplicate IDs (like my code above), then it could be the way that the IDs are written to the database. They may be generated only once, but written twice.

chriswelborn 63

This question is difficult to understand. I don't think the wall of output text helps. Maybe you could word it differently, or provide a little pseudo-code to help us understand what exactly you are trying to do?

What are the comparisons? A file?

What does "takes that to [metadata][phenotype][embryo]" mean? (what does "takes that to" mean in python?)

"samples -> files -> bam which is the input"..input to what?

A lot have people have viewed your question, but I think the wording is making it hard to help.

chriswelborn 63

All three of these options are working for me:

Plain echo "string" > file:

read -p "What is your variable: " WHATIS

echo "This should be a bunch of lines
I want this \"variable\" to be embedded
it is $WHATIS" > ./test.txt

cat with HEREDOC and variable expansion:

read -p "What is variable 2?: " WHATIS2

cat > ./test.txt <<EOF

This should be a bunch of lines
I want this "variable" to be embedded
it is $WHATIS2

EOF

cat withHEREDOC and variable substitution/expansion:

read -p "What is variable 3?: " WHATIS3

cat > ./test.txt <<EOF

This should be a bunch of lines
I want this "variable" to be embedded
it is ${WHATIS3}

EOF

Using ${var} instead of $var is for when you want the variable name separated from other content (like echo "${myvar}s are cool"), or when you are actually doing some extra substitution (like echo "${myvar:-mydefault}"). It doesn't hurt to use ${}, but it's not necessary.

chriswelborn 63

What is the actual problem? Is there a traceback when you run it? You say:

while p is less than the length of the list...

..which is basically describing what your code does. Can you give me a more general explanation? Like "I want to shift the ordinance of every character in a string."? I see some patterns here that can be shortened:

This:

n = 0
number = []
while n<8:
    random_number = chr(random.randint(33, 126))
    print(random_number)
    n = n + 1
    characters = ord(random_number)
    number.append(characters)

Could be written much cleaner as (untested):

# A list of 8 random character ordinances (numbers)
numbers = [random.randint(33, 126) for _ in range(8)]

Which is also easy to work with when building strings or whatever:

# That same list converted to characters
actualchars = [chr(n) for n in numbers]

# That character list as a string.
actualstring = ''.join(actualchars)

# All in one go (using a generator)
randomstring = ''.join((chr(random.randint(33, 126)) for _ in range(8)))

It's a much shorter version of this for-loop:

numbers = []
for _ in range(8):
    numbers.append(random.randint(33, 126))

This way you don't have to do so much bookkeeping. Also, there is no reason to go from int -> chr -> ord (line #15 and #21), because ord(chr(47)) == 47. Python is good at list comprehensions and generators, so there is no reason to build a simple list like this with a while loop (for more complicated processing, maybe, but for-loops are possibly even better).

chriswelborn 63

I can only find python-based "watermark" plugins at the moment. You may have to make one. The PIL or pillow libraries can help you work with images. Outside of GIMP, I see the StegHide application recommended for this.

chriswelborn 63

Small typo in that example, the font name. Should be 'Times New Roman'

chriswelborn 63

I see that your __init__ method is misspelled, but you're gonna want an instance to work with. You have a calculating class, but no object. Instantiate the class:

mycalc = calculating()

...then use the method (mycalc.addition). Also, its good practice in python for classes to start with a capital letter. So calculating should be called Calculating instead.

chriswelborn 63

@Gribouillis: yeh, I don't use tell() a lot, but I can image len() being faster. I'm on my phone so I can't check, but I know yours will return the correct character position. What I'm wondering is if tell() will return the correct byte position (multibyte Unicode comes to mind). If so, each version is good for a specific use case, character position versus byte position.

chriswelborn 63

enumerate() is great for grabbing an index and item at the same time, and f.tell() can tell you the current position in the file:

for i, line in enumerate(file):
    print('{lineno} ({pos}): {line}'.format(
        lineno=i + 1, 
        pos=file.tell(), 
        line=line))

chriswelborn 63

Here is the parameter expansion version, which seems to be better than calling 2 unnecessary commands:

APPPATH="$(realpath ${BASH_SOURCE[0]})"
APPSCRIPT="${APPPATH##*/}"
APPDIR="${APPPATH%/*}"

chriswelborn 63

You could use RegEx, but that may be overkill. I think GetFiles supports glob matching like GetFiles("C:\dir", "*.exe"), but you don't want to call GetFiles multiple times. So maybe a simple If statement would suffice:

If IO.Path.GetExtension(s) = ".exe" Then
    MyOtherBox.Items.Add(IO.Path.GetFileNameWithoutExtension(s))
Else
    WithoutThisTypeBox.Items.Add(IO.Path.GetFileNameWithoutExtension(s))
End If

My VB.Net is rusty, but I think that would do it. There is also s.EndsWith(".exe").

chriswelborn 63

Windows Batch Scripting

It's good for Sytem Administrators and small tasks, much like the Linux world's BASH (though in my opinion BASH is much more powerful).

chriswelborn 63

just type it out. Put a blank line before the code, make sure all of the code lines are indented with 4 spaces.

# I did not use the </>Code button.
print('Hello World.')

You can also use the tilde character (`) to do "inline code" such as this: int c = 5; ...for when you don't need a whole block.