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
slotbadger
Jul 19, 2007
hey deadhead - take a bite of peach.
I have a question about masking...

Okay, let's say I have a value in hex, "1234"

When I want to update that value, I can also choose to apply a mask. In this example I want the new value to be "ABCD" and the mask to be "00FF". So if I use the mask, the new value is "00CD"

So, when this is applied to the old value it should be "12CD".

I'm struggling with the final part of this process. Can anyone tell me a simple way to do this, using bitwise operators etc?

Adbot
ADBOT LOVES YOU

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
Assume you have old = 0x1234, replacement = 0xabcd, and mask = 0x00ff. We want to create a value, new which consists of: 1) The portion of replacement that matches mask, and 2) The portion of old that matches the complement of mask. Because these portions do not overlap (since, obviously, mask does not overlap its complement) we can combine them with an or.

This leads to the operation new = (replacement & mask) | (old & ~mask).

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe
I'm working on a simple perl bot that can search a wiki. In order to find an article and not have to worry about the case of the search terms (the articles themselves are case sensitive) I'm using the following:

code:
my $response = $browser->get("http://wiki.blah.org/index.php?search=$articlename&go=Go");
If the exact search term has an article somewhere in the wiki the page will forward there and the content I get will be what is in that page. However, I need to know what page it redirected me to. How would I find this out?

baquerd
Jul 2, 2007

by FactsAreUseless

clockwork automaton posted:

I'm working on a simple perl bot that can search a wiki. In order to find an article and not have to worry about the case of the search terms (the articles themselves are case sensitive) I'm using the following:

code:
my $response = $browser->get("http://wiki.blah.org/index.php?search=$articlename&go=Go");
If the exact search term has an article somewhere in the wiki the page will forward there and the content I get will be what is in that page. However, I need to know what page it redirected me to. How would I find this out?

Check out http://en.wikipedia.org/wiki/Japanime

code:
<div id="contentSub">  (Redirected from <a href="/w/index.php?title=Japanime&amp;redirect=no" title="Japanime">Japanime</a>)</div>
Regex for that with the appropriate wildcards to see if you've been redirected and then grab the title.

code:
<h1 id="firstHeading" class="firstHeading">Anime</h1>
This does require the uniqueness of these identifiers, which should be guaranteed in wikipedia. You probably should search only for the first occurrence, which is default perl behavior anyway I believe.

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe

quadreb posted:

Check out http://en.wikipedia.org/wiki/Japanime

code:
<div id="contentSub">  (Redirected from <a href="/w/index.php?title=Japanime&amp;redirect=no" title="Japanime">Japanime</a>)</div>
Regex for that with the appropriate wildcards to see if you've been redirected and then grab the title.

code:
<h1 id="firstHeading" class="firstHeading">Anime</h1>
This does require the uniqueness of these identifiers, which should be guaranteed in wikipedia. You probably should search only for the first occurrence, which is default perl behavior anyway I believe.

Hmm... that makes sense. Thanks!

Metonymy
Aug 31, 2005
How do RSS readers work? Let's say you have a RSS reader with 100 users, and each user is subscribed to 10 different feeds. Do you need to write a job that polls each one of those feeds at regular intervals to see if they have been updated? I can see doing lazy polling, where you just pull the feed when a user requests it, but if the feed only carries the latest 10 items, then you obviously might miss a lot of information. Lets say you're Google Reader, and you have to manage subscriptions to hundreds of thousands of individual feeds - do you have a scheduled job that goes and pings all of those feeds on a regular interval?

hey mom its 420
May 12, 2007

You can probably hold a big list of the feeds that your users are subscribed to and then poll those at regular intervals and store them in a cache of some sorts. Only pull it from your cache when the user requests it i.e. lazily. Actually, you don't need to poll feeds that have more than a few subscribers, because requests for popular feeds are done often enough, so you can just cache them when users request them.

Also, take advantage of HTTP etags and Last-Modified + If-Modified-Since headers. No need to download what ain't new.

hey mom its 420 fucked around with this message at 01:14 on Jul 8, 2009

slotbadger
Jul 19, 2007
hey deadhead - take a bite of peach.

ShoulderDaemon posted:

Assume you have old = 0x1234, replacement = 0xabcd, and mask = 0x00ff. We want to create a value, new which consists of: 1) The portion of replacement that matches mask, and 2) The portion of old that matches the complement of mask. Because these portions do not overlap (since, obviously, mask does not overlap its complement) we can combine them with an or.

This leads to the operation new = (replacement & mask) | (old & ~mask).

Belated thanks for that, by the way. That's actually where I was, but it was refusing to work due to a terribly stupid array-related error on my part. :~

cletus42o
Apr 11, 2003

Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light.
College Slice
So I'm creating an email, with an unknown number of attachments (determined by client when "building" the email).

Parts in the email reference different attachments.

Is there any way to place a link in the email that would duplicate the same action as double-clicking the attachment in the standard attachments list? They are using Outlook only, so don't need to worry about it being a standard thing. (as much as I would hate to do it)

My first suggestion was to host the files on the web server, and eliminate the attachments altogether, but that isn't a solution they like. The only reason they want this is so people don't have to scroll the list of attachments to find the one referenced, since there may be 10-20 attachments total.

Silly, yes, but said I'd look into it. :)

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
In GUI Outlook (like, I don't know how to do this programmatically) you can put attachments inline, so they aren't in an attachments tray, they're sort of in the body of the message. So if each attachment is only referred to once, you could put the attachments right next to where they are referred to.

I think internally that's a multi part MIME message? I have no idea what I'm talking about, just guessing.

cletus42o
Apr 11, 2003

Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light.
College Slice

Triple Tech posted:

In GUI Outlook (like, I don't know how to do this programmatically) you can put attachments inline, so they aren't in an attachments tray, they're sort of in the body of the message. So if each attachment is only referred to once, you could put the attachments right next to where they are referred to.
Do you know the steps you take to do it through the GUI? I couldn't find a way to do that myself. If I can do that, I can probably reverse engineer the email that gets sent to create it programmatically. Thanks!

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

cletus42o posted:

Do you know the steps you take to do it through the GUI? I couldn't find a way to do that myself. If I can do that, I can probably reverse engineer the email that gets sent to create it programmatically. Thanks!

Pretty sure that in Outlook 2007 it's the default behavior when you attach something. But I haven't used Outlook for like a year (thank god*).

* Not because Outlook sucks especially bad, but that job did.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

cletus42o posted:

Do you know the steps you take to do it through the GUI? I couldn't find a way to do that myself. If I can do that, I can probably reverse engineer the email that gets sent to create it programmatically. Thanks!

I think AD is right. All I have on my system now is 2007 and I can't find any way to bring back a tray of attachments. Like, I'm typing a sentence, I decide to attach something, and it's just sitting there in the middle of my words. Kind of annoying. So I guess nab your hands on a copy of 2007, type some words, insert something, notice how it's right where your cursor is, type more wards, insert again, type more words, and then dissect what gets sent out. And then check how it gets rendered.

cletus42o
Apr 11, 2003

Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light.
College Slice
Weird, I already have Outlook 2007. I'll see if I can figure this mystery out. Thanks!

kwantam
Mar 25, 2008

-=kwantam

Triple Tech posted:

I think AD is right. All I have on my system now is 2007 and I can't find any way to bring back a tray of attachments.

In OL2003, enabling HTML email inlines attachments, whereas plain text email forces the tray. This may also be the case in OL2007.

cletus42o
Apr 11, 2003

Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light.
College Slice

kwantam posted:

In OL2003, enabling HTML email inlines attachments, whereas plain text email forces the tray. This may also be the case in OL2007.
I wish I knew what the hell you guys were doing!

Only registered members can see post attachments!

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
Yeah I'm sorry I totally lied. I have 2003 in the office, but I have 2007 at home. I can check when I get back home.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

cletus42o posted:

I wish I knew what the hell you guys were doing!

Try "Rich Text".

cletus42o
Apr 11, 2003

Try to imagine all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light.
College Slice

Avenging Dentist posted:

Try "Rich Text".
That's it, thanks!

kwantam
Mar 25, 2008

-=kwantam

Avenging Dentist posted:

Try "Rich Text".

D'oh, you're right. Oh well, I knew it was one of those format options I always turn off; guess I misremembered which.

Metonymy
Aug 31, 2005
e:blrrp

Metonymy fucked around with this message at 03:47 on May 25, 2011

SpoonsForThought
Jul 1, 2007

I'm so lost.

I wrote some php that I need to work on my webserver for a form mailer.

PHP is not installed. How on earth do I do this? I can not find a single link anywhere on the internet that will explain this in simple terms.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

SpoonsForThought posted:

I can not find a single link anywhere on the internet that will explain this in simple terms.

That is because, unless you are an admin, you cannot install PHP (or anything really).

SpoonsForThought
Jul 1, 2007

I've been bugging up up some of the threads here with my noobie questions and I know someone must be annoyed with me but here is my problem. I usually only work with css/html, which are very, very simple. I just upload them to the server and they work. Well here is my problem completely fleshed out.

I created a form on one of my pages. This form is a request information page. I want this form to be e-mailed to a specific e-mail address upon submitting without opening up the user's mail program, because frankly that is annoying. To the best of my knowledge, HTML can not do this. I looked around and modified (with a lot of help from the php/web dev megathread) a php page that should do this. Correct? I had access to a web server through school, and once I uploaded the php page, it did not work and we(megathread guys) kind of came to the conclusion that this must be because some features of php were disabled that did not let this e-mailing work. I have access now to the server that this page should be going on (other space was just temp) and it still does not work. It is being hosted by Nuvox, which says they support PHP, yet whenever I try to access a php page, my browser acts as if it is a download.

There is my problem. I might have been over-thinking this by a mile, maybe there is an easier way to do this, I don't know and would really, really love some help.

**UPDATE***

In my investigation of the server, it appears that the host has not updated it in nearly a decade, which means no PHP support. I did however work an ASP alternative.

Thanks for all the guys that helped with my php problem.

SpoonsForThought fucked around with this message at 04:29 on Jul 10, 2009

Notorious H.P.B.
Jun 19, 2006

by Y Kant Ozma Post
I'm not sure where else to put this, so I'll just ask here and hope for the best. If someone knows a more specific place to ask, please let me know.

My question is about an Access 2007 form. Access 2007 added (I think) the ability to have forms with multiple items. I've created a form to review all the orders made in a product database, and each record has a button to record the arrival of an order:



When the button is clicked, it sets Date Arrived to the current date and sets an invisible flag called IsArrived to true and runs an SQL UPDATE to add the amount ordered to the total amount in another table. What I'd like to do is have the button be disabled on only those records where IsArrived = true. Right now, I've only figured out how to do it for the whole form. What do I need to do?

Here's the code I have so far:
code:
Private Sub Form_Load()
    If Me.IsArrived = True Then
        Me.RecordArrival.Enabled = False
    End If
End Sub

Private Sub RecordArrival_LostFocus()
    If Me.IsArrived = True Then
        Me.RecordArrival.Enabled = False
    End If
End Sub

RussianManiac
Dec 27, 2005

by Ozmaugh

SpoonsForThought posted:

I've been bugging up up some of the threads here with my noobie questions and I know someone must be annoyed with me but here is my problem. I usually only work with css/html, which are very, very simple. I just upload them to the server and they work. Well here is my problem completely fleshed out.

I created a form on one of my pages. This form is a request information page. I want this form to be e-mailed to a specific e-mail address upon submitting without opening up the user's mail program, because frankly that is annoying. To the best of my knowledge, HTML can not do this. I looked around and modified (with a lot of help from the php/web dev megathread) a php page that should do this. Correct? I had access to a web server through school, and once I uploaded the php page, it did not work and we(megathread guys) kind of came to the conclusion that this must be because some features of php were disabled that did not let this e-mailing work. I have access now to the server that this page should be going on (other space was just temp) and it still does not work. It is being hosted by Nuvox, which says they support PHP, yet whenever I try to access a php page, my browser acts as if it is a download.

There is my problem. I might have been over-thinking this by a mile, maybe there is an easier way to do this, I don't know and would really, really love some help.

**UPDATE***

In my investigation of the server, it appears that the host has not updated it in nearly a decade, which means no PHP support. I did however work an ASP alternative.

Thanks for all the guys that helped with my php problem.
just make the HTTP form submit information to another web server where you can actually control it.

Make a simple webserver on some computer with constant IP and process all POST requests coming to it from a certain URI, then do whatever your heart desires with it :D

Zenaida
Nov 13, 2004
Any verilog people in here? I'm trying to get the sum of bits in a parameterizable-width register.

So I have something along the lines of

code:
parameter N = 10;

reg [N-1:0] reg1;

wire sumval;

assign sumval = //sum of all bits in reg1
It'd be easy if there was a unary reductive sum, like the reductive boolean operations, but of course there's not. I feel like there must be some way to do this though, maybe using generate or for loops or some combination of the two...

BangersInMyKnickers
Nov 3, 2004

I have a thing for courageous dongles

Management had me hobble together a scheduled task that runs overnight on systems to generate a log so we can keep track of those who aren't turning things off at night. Basically there is a network share and the each system appends to a text file bearing the system name in that share adding a line "%date% %time% %status%" (where status is the username if logged on or simply 'loggedoff' if there is no console session). Output ends up looking like this:

code:
Thu 07/16/2009 04:00:00.53      [DOMAIN]\[USERNAME]
Fri 07/17/2009 04:00:00.53      [DOMAIN]\[USERNAME]
Sat 07/18/2009 04:00:00.53      loggedoff
Sun 07/19/2009 04:00:00.53      loggedoff
Then I have my own script that pulls a directory listing and loops through each file checking for the day codes and setting a variable if found, which at the end dumps the data in to a single CSV document which I can import easily in to Excel and hand off the management.

Looks like this:
code:
[SYSTEM1],O,O,,,,, 
[SYSTEM2],L,L,,,,, 
[SYSTEM3],L,L,,,,, 
[SYSTEM4],O,O,,,,,
Due to the limitations of the FIND and FINDSTR commands returning the whole line a pattern match was found on, I can only search for "[DOMAIN]\*" and set a value to O(on, logged off) or L (logged on) depending on the returned errorlevel. Is there some command line search trickery I can use to filter down the results of the "[DOMAIN]\*" to show only the matching pattern and not the entire line it is on so I can dump that in to a variable to pass to the CSV data? Is there a Windows FIND or FINDSTR replacement that can give me this kind of functionality? Is there a better way to go about this than what I am doing, bearing in mind that I have to keep this garbage in a command-line script for future workers?

kwantam
Mar 25, 2008

-=kwantam

Zenaida posted:

It'd be easy if there was a unary reductive sum, like the reductive boolean operations, but of course there's not. I feel like there must be some way to do this though, maybe using generate or for loops or some combination of the two...

OK, first of all, if you mean the sum then presumably sumval has to be 4 bits wide, yeah?

Now forget about code and think about how it will actually be implemented in hardware. The simplest way is to make a ripple-ish adder with increasing bit width, e.g. (for three bits, and bear with the pseudo code please),

code:
add_2bit({1'b0,reg1[2]],add_1bit(reg1[1],reg1[0]))
where add_1bit produces a two bit output {carry,value}. You'll note that in this case add_2bit doesn't need to support carrying because the maximum value is 2'b11.

But of course this is ugly as hell, and you have to manually compute at each stage the bit width necessary on input and output. How about we make a tree:

code:
add2(add1(1'b0,reg1[2]),add1(reg1[1],reg1[0]))
Now it's obvious that the bit width increases by one with each layer, i.e., adding two bits together takes two bits, adding two sums of two bits takes three bits, et cetera. So at least we've broken it down into more regular units, and if not for the need for a parametrized structure we'd be done.

(Actually, you can optimize this tree a little bit more by summing every three bits of the input register since 1+1+1=2'b11, but after that you're stuck "wasting" a little bit of adder width at each stage.)

In some cases you can cheat: do you have a bounded range of parameters? You can generate the largest possible bit-add tree and map your register into one as large as the largest input. The useless parts of it (adding a bunch of zeros together) will be optimized away when you synthesize it.

Otherwise, if you're stuck using generate, you can make an appropriately sized tree by adding together pairs or triplets, then pairing outputs of your adders and adding again, et cetera. Unfortunately, generate's syntax is kind of lovely and I avoid it because it's not always supported; usually when I have to do parametrized stuff that's even remotely complex I'll generate verilog with perl. It's quite convenient to have a Makefile wrapping your project in this case (well, in all cases).

A much simpler alternative for doing this for an arbitrary register width is to make a state machine that shifts bits out of the register and produces a sum, but it seems like you wanted static logic, so that won't work very well.

kwantam fucked around with this message at 20:49 on Jul 16, 2009

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

BangersInMyKnickers posted:

Management had me hobble together a scheduled task that runs overnight on systems to generate a log so we can keep track of those who aren't turning things off at night. Basically there is a network share and the each system appends to a text file bearing the system name in that share adding a line "%date% %time% %status%" (where status is the username if logged on or simply 'loggedoff' if there is no console session). Output ends up looking like this:

code:
Thu 07/16/2009 04:00:00.53      [DOMAIN]\[USERNAME]
Fri 07/17/2009 04:00:00.53      [DOMAIN]\[USERNAME]
Sat 07/18/2009 04:00:00.53      loggedoff
Sun 07/19/2009 04:00:00.53      loggedoff
Then I have my own script that pulls a directory listing and loops through each file checking for the day codes and setting a variable if found, which at the end dumps the data in to a single CSV document which I can import easily in to Excel and hand off the management.

Looks like this:
code:
[SYSTEM1],O,O,,,,, 
[SYSTEM2],L,L,,,,, 
[SYSTEM3],L,L,,,,, 
[SYSTEM4],O,O,,,,,
Due to the limitations of the FIND and FINDSTR commands returning the whole line a pattern match was found on, I can only search for "[DOMAIN]\*" and set a value to O(on, logged off) or L (logged on) depending on the returned errorlevel. Is there some command line search trickery I can use to filter down the results of the "[DOMAIN]\*" to show only the matching pattern and not the entire line it is on so I can dump that in to a variable to pass to the CSV data? Is there a Windows FIND or FINDSTR replacement that can give me this kind of functionality? Is there a better way to go about this than what I am doing, bearing in mind that I have to keep this garbage in a command-line script for future workers?
Give For /F a shot in conjunction with FINDSTR.

http://www.robvanderwoude.com/ntfortokens.php

BangersInMyKnickers
Nov 3, 2004

I have a thing for courageous dongles

Jethro posted:

Give For /F a shot in conjunction with FINDSTR.

http://www.robvanderwoude.com/ntfortokens.php

Great! I've only used for loops for increment counting and recursive list execution, you finally got me to sit down and figure out the delimiter functionality and this works perfectly.

Tekhne
Sep 11, 2001

I have a 2D plane with ellipses that may or may not be drawn at an angle. I know the angle and axis lengths of all of the ellipses. How would I go about placing an object (say a dot) every x units in the entire area of a particular ellipse? I'm not good with this math so I have no clue where to start as far as the equations go. Any language will do as I'll just study it and then convert it into the language I'm writing for.

In other words:
I have an ellipse centered at [5,10], Angle: 30degrees, Axis-a: 100, Axis-b: 200.
I want to place an object every 5 spaces in every direction within the ellipse. How do I get all of those positions using some mathematical equation that I could loop through?

magicalblender
Sep 29, 2007
First, find the position of the foci of the ellipse. They both lie along the major axis, and their distance from the center is given by the equation F = sqrt(a^2 - b^2), where a and b are the major and minor radii. If you know some simple trig, that should be enough information to find the foci's exact position.

Now that you have the foci F1 and F2, you can test whether a given point X is inside or outside the ellipse. Take the distance of X to F1, and add the distance of X to F2. If that number is larger than the major diameter, the point lies outside the ellipse. If it's smaller, it lies inside the ellipse.

So, get a set of points that are in the ballpark around the ellipse (say, all the points inside a rectangle that goes around the ellipse), and do the above test to see which ones are inside the ellipse.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
im dum

dougdrums fucked around with this message at 17:57 on Jul 18, 2009

Contero
Mar 28, 2004

Can someone who understands javascript closures explain why this spits out 10 in rhino instead of 8?

code:
js> function getClosure () {
   var x;
   var retVal;

   for (x = 0; x < 10; x++) {
      if (x == 8) {
         retVal = function () { return x; };
      }
   }

   return retVal;
}

js> clo = getClosure();

function () {
    return x;
}

js> clo();
10

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Contero posted:

Can someone who understands javascript closures explain why this spits out 10 in rhino instead of 8?

x is a variable, not a value. The closure captures its parent's scope, so its x is the same as the parent's x. The parent sets x to 10 before the closure is ever called, so the closure will always return 10.

If you want to capture the value, you have to declare a new variable for it:
code:
function closureReturning8 () {
  var x;
  var retClosure;

  for (x = 0; x < 10; ++x) {
    if (x == 8) {
      var y = x;
      retClosure = function () { return y; };
    }
  }

  return retClosure;

}
Note that the scope of y is limited to a single iteration of the for loop.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

ShoulderDaemon posted:

Note that the scope of y is limited to a single iteration of the for loop.

No, the scope of y is limited to the whole function, but you're rebinding it at every step of the loop.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

I'm trying to resurrect an old VB6 application that needs a bugfix. I can run it fine in the IDE, but VB6.exe crashes with a page fault when I try to compile an EXE. Has anyone run into this before and found a fix or a way to get more information on what is going wrong?

Alternatively, has anyone successfully converted a VB6 app to VB Express? How much work is involved?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Avenging Dentist posted:

No, the scope of y is limited to the whole function, but you're rebinding it at every step of the loop.

Yeah, you're right. Javascript has crazy scoping. In this case, at least, the distinction doesn't really matter.

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

ShoulderDaemon posted:

Yeah, you're right. Javascript has crazy scoping. In this case, at least, the distinction doesn't really matter.

It matters if you want to return more than one closure.

code:
var a = []
for (var i = 0; i < 10; ++i) {
  var y = i
  a.push(function() { print(y) })
}

for (var i = 0; i < 10; ++i)
  a[i]()
Here you need to do something crazy like a.push((function(y) { return function() { print(y) } })(i)) instead because the only way to introduce a new scope is through a new function, as far as I know.

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