Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





Avenging Dentist posted:

Generally, I think it's best to pick one style and use it for both variables and methods. It just makes things more consistent.

i use underscore_deliminated_method_names and CamelCaseVariableNames generally. in some languages it's extremely nice to be able to differentiate between the two at a glance.

Adbot
ADBOT LOVES YOU

Incoherence
May 22, 2004

POYO AND TEAR

fletcher posted:

Is it more common to write variables as someVariable or some_variable? I can't decide which to use. I like using someMethod() instead of some_method(), so I'm thinking it would make more sense to use some_variable.
Depends on the language. Java usually uses camelCase for everything (first letter uppercase for classes, first letter lowercase for methods). C# style is similar to Java's, except that method names have the first letter uppercase. C/C++ varies but tends to prefer underscored_names.

Match whatever your language/environment uses. If neither of those give any guidance, just be consistent.

narbsy
Jun 2, 2007
Appa Time! Yeah, I build a list of primes first to test against. Here's my code if you'd like; it's pretty simple. I'm not very complex.

code:
function findPrimes(howfar)
{
	var primes = new Array();
	
	for(var i = 3; i < howfar; i += 2)
	{
		if(isPrime(i, primes)){primes.push(i);}
	}
	primes.unshift(2*1);
	return primes;
}
function isPrime(number, primes)
{
	var root = Math.sqrt(number*1);
	if(primes.length == 0){return true);
	
	for(var i = 0; i < primes.length; i++)
	{
		if(primes[i]*1 > root){return true;}
		if(number*1 % primes[i]*1 == 0){return false;}
	}
	return true;
}
function getPrimeFactors(number)
{
	number = number*1;
	var primes = findPrimes(Math.sqrt(number));
	var factors = new Array();
	
	for(i = 0; i < primes.length; i++)
	{
		if(number % primes[i] == 0)
		{
			factors.push(primes[i]);
		}
	}
	return factors;
}

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again

narbsy posted:

Appa Time! Yeah, I build a list of primes first to test against. Here's my code if you'd like; it's pretty simple. I'm not very complex.

Jesus, I modeled mine more after yours and it gave me the correct answer almost instantly. My old way ran for 15 minutes and still didn't find it. Thanks a lot man.

Triangulum
Oct 3, 2007

by Lowtax
TI BASIC question. I wrote my first program for my 83 that solves the quadratic formula. The problem is that my program gives decimal approximations instead of exact value when dealing with square roots. How do I program it to show exact values?

narbsy
Jun 2, 2007
No problem Appa Time!! My pleasure.

Triangulum: There is a site devoted to TI programming, here. There's a ton of stuff, and if all else fails you can download an example program that does what you want to learn from.

JawnV6
Jul 4, 2004

So hot ...

Triangulum posted:

TI BASIC question. I wrote my first program for my 83 that solves the quadratic formula. The problem is that my program gives decimal approximations instead of exact value when dealing with square roots. How do I program it to show exact values?

I don't think the 83 will show square roots inline like the 89 or 92 does. Just to make sure I understand, you're plugging in values to a solver, it's spitting out "1.732..". and you want it to say "sqrt(3)" instead? Your best bet is to also print out the square of all the numbers given to see if they're integers, otherwise it's going to be a guessing game.

Incoherence
May 22, 2004

POYO AND TEAR

Triangulum posted:

TI BASIC question. I wrote my first program for my 83 that solves the quadratic formula. The problem is that my program gives decimal approximations instead of exact value when dealing with square roots. How do I program it to show exact values?
You'll have to figure out a way to display the root, since the 83 just gives you the approximation. I wrote something similar for my TI-83 which just displayed
code:
         ___
 X +/- v/ Y
 ----------
     Z
where X = -b, Y = b^2 - 4ac, and Z = 2a... I think it also tried to find exact square roots and simplify that. You'll have to do the output formatting yourself, in other words.

Triangulum
Oct 3, 2007

by Lowtax
The TIcalc site has a quadratic solver that expresses the answer as a radical but I don't have a link cable. Maybe I can convince the one person in my class with this version of the quad EQ program to give me a look at the code so I can figure out how the gently caress it was done. It's not a huge deal or incredibly important but it's driving me nuts and I would like to learn how to do it.

6174
Dec 4, 2004

Triangulum posted:

The TIcalc site has a quadratic solver that expresses the answer as a radical but I don't have a link cable. Maybe I can convince the one person in my class with this version of the quad EQ program to give me a look at the code so I can figure out how the gently caress it was done. It's not a huge deal or incredibly important but it's driving me nuts and I would like to learn how to do it.

If the program posted is actually TI-Basic you should be able to open the file in just a text editor to view the source without a cable. Granted you'd have to reimplement the program yourself if you want it on your calculator, but it would tell you how it is done.

Triangulum
Oct 3, 2007

by Lowtax
I had assumed that as well until I opened the files in Notepad and got a huge string of gibberish. I could also be a moron, who knows!

Scaevolus
Apr 16, 2007

6174 posted:

If the program posted is actually TI-Basic you should be able to open the file in just a text editor to view the source without a cable. Granted you'd have to reimplement the program yourself if you want it on your calculator, but it would tell you how it is done.

No, the Ti-83 is too cool to do real tokenization, so it's essentially a binary format.

6174
Dec 4, 2004

Triangulum posted:

I had assumed that as well until I opened the files in Notepad and got a huge string of gibberish. I could also be a moron, who knows!

Interesting. I remember just opening the files in a text editor when I used to play with programs on my TI-86 and then 89. Maybe it was the linking software allows you to view the programs?

This was many years ago though, so my memory is a little fuzzy on some of the details.

6174 fucked around with this message at 23:56 on Feb 27, 2008

Incoherence
May 22, 2004

POYO AND TEAR

6174 posted:

Interesting. I remember just opening the files in a text editor when I used to play with programs on my TI-86 and then 89. Maybe it was the linking software allows you to view the programs?

This was many years ago though, so my memory is a little fuzzy on some of the details.
The TI calculators can either be programmed in a BASIC variant or in whatever flavor of assembly they use. Maybe it was the latter, and there's some compilation done on it?

more falafel please
Feb 26, 2005

forums poster

6174 posted:

Interesting. I remember just opening the files in a text editor when I used to play with programs on my TI-86 and then 89. Maybe it was the linking software allows you to view the programs?

This was many years ago though, so my memory is a little fuzzy on some of the details.

You should be able to open them in the TI Connect software, or whatever it's called now. That's assuming they're in BASIC, if they're written in assembly you're kind of hosed, but I'm assuming that no one went to the trouble to hand-write QUADFORM in assembly :) And if you get a program from TI's official site, it's pretty much guaranteed to be BASIC.

Kaiju
Mar 19, 2003

HEINEKEN!?! FUCK THAT SHIT! PABST BLUE RIBBON!!
I have a client at work that has two mirror sites translated into German and Spanish. All three sites are hosted on the same server. The translated sites are relatively new and since they launched, they've started having submissions to their contact forms that include non-english characters. When the form outputs the submission emails anything not english, say, letters with accents, umlauts or tilde (for spanish characters) they are replaced in the email body with strange approximations and not the correct characters.

And if it matters, the sites are all in ASP classic.

I've never had to deal with anything like this in the past and I'm not sure how to fix it. I've been letting this one slide for a while and people are starting to ask questions.

Any ideas?

narbsy
Jun 2, 2007
You can also get an emulator for the TI-83 and open it up in there. I think there were a few listed on the website.

csammis
Aug 26, 2003

Mental Institution

Kaiju posted:

I have a client at work that has two mirror sites translated into German and Spanish. All three sites are hosted on the same server. The translated sites are relatively new and since they launched, they've started having submissions to their contact forms that include non-english characters. When the form outputs the submission emails anything not english, say, letters with accents, umlauts or tilde (for spanish characters) they are replaced in the email body with strange approximations and not the correct characters.

And if it matters, the sites are all in ASP classic.

I've never had to deal with anything like this in the past and I'm not sure how to fix it. I've been letting this one slide for a while and people are starting to ask questions.

Any ideas?

"Text encoding" is the keyword you'll be looking for, as that's the problem. The users are sending characters to the web server in a character set that your email can't contain, probably because your email is sending as ASCII. You'll have to send the emails using the correct text encoding, whatever that might be. I think it'll be whatever encoding the form's page is being sent in, but I'm not sure. The web development thread folks might know right off the bat.

Kaiju
Mar 19, 2003

HEINEKEN!?! FUCK THAT SHIT! PABST BLUE RIBBON!!

csammis posted:

"Text encoding" is the keyword you'll be looking for, as that's the problem. The users are sending characters to the web server in a character set that your email can't contain, probably because your email is sending as ASCII. You'll have to send the emails using the correct text encoding, whatever that might be. I think it'll be whatever encoding the form's page is being sent in, but I'm not sure. The web development thread folks might know right off the bat.

Thanks, man. That's a start.

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

I'm writing a bash script that involves a long series of pipes. I also want to make it readable.

Is there a simple way to put these on multiple lines and making bash treat it as one single line of input?

code:
from
command 'args' $1 |anothercommand|yetanother|...|nthcommand

to  
command 'args' $1 
|anothercommand
|yetanother
|...|
|...nthcommand
Sort of the opposite of a semicolon!

6174
Dec 4, 2004

axolotl farmer posted:

I'm writing a bash script that involves a long series of pipes. I also want to make it readable.

Is there a simple way to put these on multiple lines and making bash treat it as one single line of input?

What you are looking for is called a line continuation character. In the case of bash it is \

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

6174 posted:

What you are looking for is called a line continuation character. In the case of bash it is \

Oh yes it is. My error was caused by something else. :blush:

furtheraway
Dec 19, 2005

this milchkuh has given its last pound of flesh
I understand that we're supposed to keep language specific questions in their related threads, but I don't see any current threads on shell scripting or sed. If I'm wrong, feel free to ridicule me.

With that out of the way, my question is about using regular expressions with sed. I'm searching a line of numbers and symbols and only want a certain group of numbers. My input string will look like this:
code:
16(100%)
I only want the numerals between the first parenthesis and the percent sign. That group can contain from one to three numerals. How do I extract it?

I've tried the following (and many variations) with no luck. This regex makes the most sense to me in this context:
code:
([0-9]*(\([0-9]{1,3})%\))
Any ideas? I know it's something simple, so if anyone can spare an epiphany...

bitprophet
Jul 22, 2004
Taco Defender
Must be sed's interpretation of regex, I wasn't able to convince it to do what you want (not even anything as simple as '[0-9]+' was matching, so either I was being retarded in my sed usage or that's the aspect it doesn't support...?) but Python's RE library works fine, I think it's largely PCRE compatible:

quote:

re.findall(r'[0-9]+\(([0-9]{1,3})%',"16(100%)")
Out[5]: ['100']

Upon further investigation, it looks like you need the -E flag for sed to use extended regex instead of simple:

quote:

jeff@jeff.local:~ $ echo "16(100%)" | sed -Ee "s/[0-9]+\(([0-9]+)%\)/\1/"
100

EDIT: I used + instead of {1,3} there but same difference in this case :v: Also, I used + instead of * for the earlier part, which is probably better unless your input sometimes lacks the leading number entirely; I also removed the all-encompassing parentheses which I am pretty sure were extraneous :)

bitprophet fucked around with this message at 20:03 on Feb 28, 2008

furtheraway
Dec 19, 2005

this milchkuh has given its last pound of flesh

bitprophet posted:

Must be sed's interpretation of regex, I wasn't able to convince it to do what you want (not even anything as simple as '[0-9]+' was matching, so either I was being retarded in my sed usage or that's the aspect it doesn't support...?) but Python's RE library works fine, I think it's largely PCRE compatible:


Upon further investigation, it looks like you need the -E flag for sed to use extended regex instead of simple:


EDIT: I used + instead of {1,3} there but same difference in this case :v: Also, I used + instead of * for the earlier part, which is probably better unless your input sometimes lacks the leading number entirely; I also removed the all-encompassing parentheses which I am pretty sure were extraneous :)

It doesn't look like my version of sed (4.0.7) supports -E, which seems odd. Maybe it's a GNU thing? Either way, your post (and a cup of tea) showed me exactly what I was missing, and it's totally embarrassing. I was forgetting to give sed a search command! :doh: I'm so ashamed of myself right now.

With a little fiddling I was able to get your version to work and my problem is solved. Thank you very much!

axolotl farmer
May 17, 2007

Now I'm going to sing the Perry Mason theme

Here's my very ugly take on it!

echo "16(100%)" |sed 's/[()%]/ /g'|awk '{print $2}'

furtheraway
Dec 19, 2005

this milchkuh has given its last pound of flesh

axolotl farmer posted:

Here's my very ugly take on it!

echo "16(100%)" |sed 's/[()%]/ /g'|awk '{print $2}'

That's a cool method as well (took me a second to spot the space), and it's not nearly as ugly as the entire command I'm using to get my string.

Thanks to everyone for the replies.

dest
May 28, 2003

9/9/99
Never Forget
Grimey Drawer
Wrong thread.

dest fucked around with this message at 00:43 on Feb 29, 2008

tef
May 30, 2004

-> some l-system crap ->

furtheraway posted:

I only want the numerals between the first parenthesis and the percent sign. That group can contain from one to three numerals. How do I extract it?

code:
[0-9]*(\([0-9]*%\))

re_format(7) posted:

Obsolete (``basic'') regular expressions differ in several respects. `|'
is an ordinary character and there is no equivalent for its functional-
ity. `+' and `?' are ordinary characters, and their functionality can be
expressed using bounds (`{1,}' or `{0,1}' respectively). Also note that
`x+' in modern REs is equivalent to `xx*'. The delimiters for bounds are
`\{' and `\}', with `{' and `}' by themselves ordinary characters. The
parentheses for nested subexpressions are `\(' and `\)', with `(' and `)'
by themselves ordinary characters. `^' is an ordinary character except
at the beginning of the RE or= the beginning of a parenthesized subex-
pression, `$' is an ordinary character except at the end of the RE or=
the end of a parenthesized subexpression, and `*' is an ordinary charac-
ter if it appears at the beginning of the RE or the beginning of a paren-
thesized subexpression (after a possible leading `^'). Finally, there is
one new type of atom, a back reference: `\' followed by a non-zero deci-
mal digit d matches the same sequence of characters matched by the dth
parenthesized subexpression (numbering subexpressions by the positions of
their opening parentheses, left to right), so that (e.g.) `\([bc]\)\1'
matches `bb' or `cc' but not `bc'.

Incoherence
May 22, 2004

POYO AND TEAR
Don't think we have a bash scripting thread yet, and at any rate I'm not any good with it... What does -a mean in a [ ] expression? Googling for it is kind of a pain, and the bash resources I found were no help.

edit: Never mind, found it; it's a logical and. It just looked strange because of the context I saw it in.

Incoherence fucked around with this message at 03:10 on Feb 29, 2008

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

furtheraway posted:

I understand that we're supposed to keep language specific questions in their related threads, but I don't see any current threads on shell scripting or sed. If I'm wrong, feel free to ridicule me.

With that out of the way, my question is about using regular expressions with sed. I'm searching a line of numbers and symbols and only want a certain group of numbers. My input string will look like this:
code:
16(100%)

It might be simpler (and possibly faster) to just 'cut' twice instead of sed:

code:
[jacob@tw-133]$ echo '16(100%)'|cut -d'(' -f2|cut -d'%' -f1
100
[jacob@tw-133]$ 

Lamb-Blaster 4000
Sep 20, 2007

is it possible to style individual items in a ListBox in C#? If so, how?

EDIT: After much rearranging of my google query terms I found the answer:

http://www.csharphelp.com/archives2/archive312.html

gotta replace the DrawItem Event Handler and set the drawing stuff myself

Lamb-Blaster 4000 fucked around with this message at 08:26 on Feb 29, 2008

csammis
Aug 26, 2003

Mental Institution

Dog Named Duke posted:

A C# question

For the future: .Net (C#, VB.NET) Questions Megathread

furtheraway
Dec 19, 2005

this milchkuh has given its last pound of flesh

Plastic Jesus posted:

It might be simpler (and possibly faster) to just 'cut' twice instead of sed:

code:
[jacob@tw-133]$ echo '16(100%)'|cut -d'(' -f2|cut -d'%' -f1
100
[jacob@tw-133]$ 

That's an excellent point. Using a regex in my situation is overkill. I think I'll just use this method.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
code:
(define (reverse mylist)
  (if (null? mylist) mylist
      (append (reverse (rest mylist)) (list (first mylist)))))
Can someone walk through this recursion with me? It's really confusing and I can't follow it. I don't understand the base case, how does mylist ever become null?

tef
May 30, 2004

-> some l-system crap ->

Appa Time! posted:

code:
(define (reverse mylist)
  (if (null? mylist) mylist
      (append (reverse (rest mylist)) (list (first mylist)))))

Reverse of the empty list is the empty list.
Reverse of any list is taking the first element off, reversing the rest, and appending the first element back onto the end.

When you try to reverse an empty list:

(reverse ()), mylist is null so the return is ()

When you try to reverse one:

(reverse (1)) is:

append (reverse (rest (1))) (list (first (1)))

rest (1) is () and first (1) is 1

which is

append (reverse ()) (1)

which is

append () (1)

which is (1).

reverse (2 1) is:

append ( reverse (rest (2 1))) (list (first (2 1)))

rest (2 1) is (1) and first (2 1) is 2.

append (reverse (1)) (2)

reverse (1) is (1) from above, and (list 2) is (2)

append (1) (2)

which is (1 2).

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
Oh I see now, now I just have to translate it into java. Thanks.

Edit: drat, I can't get this to work now in Java. I don't think there is a "rest" function for lists in java, so I did this:
code:
public static ArrayList<Integer> reverseListR(ArrayList<Integer> mylist)
	{
		if(mylist==null)
		{
			return mylist;
		}
		
		int current = mylist.get(0);
		mylist.remove(0);
		mylist = reverseListR(mylist);
		mylist.add(current);
		return mylist;
	}
Any ideas?

sd6 fucked around with this message at 03:18 on Mar 2, 2008

csammis
Aug 26, 2003

Mental Institution

Appa Time! posted:

code:
if(mylist==null)
{
	return mylist;
}

An empty list isn't null in Java, it's just empty. size() == 0.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again

csammis posted:

An empty list isn't null in Java, it's just empty. size() == 0.

Right you are, fixed it and it works just fine now. Thanks guys!

Adbot
ADBOT LOVES YOU

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
So I was :420: (not now, earlier) and programming and thinking about the finally statement. Is there any god drat reason for the finally statement? The only situation I see using finally in is if I didn't want to put a catch statement after a try which is a horrible practice anyways. And even if I did want to do that, couldn't I just use catch { } instead?

Sorry if I'm retarded and there actually is a good use for finally and I just never figured it out.

Edit: C#.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply