« first day (427 days earlier)      last day (4514 days later) » 

3:01 PM
This Javascript BigNumber library seems very bogus. Is there a command-line JS interpreter with which I could test the library in a more comfortable environment than in a browser?
 
@KerrekSB in windows there's jscript, invoked via cscript command
 
@AlfPSteinbach Hmm... and in Linux?
 
dunno, sorry
 
user406009
@KerrekSb Phantomjs
 
3:02 PM
  function ExpMod(Base, Expo, Modu) {
      var result = new BigNumber(1);
      while (Expo >= 1) {
          if (Expo.mod(2) != 0) {
              result = result.multiply(Base);
              result = result.mod(Modu);
          }
          Base = Base.multiply(Base);
          Base = Base.mod(Modu);
          Expo = Expo.divide(2);
      }
      return result;
  }
Does this look right?
@EthanSteinberg Thanks, will check it out!
 
oh, there's the javascript console in firefox?
plus a ditto one in opera?
 
@DeadMG nice watch ;)
 
@AlfPSteinbach Those clog up the browser, though...
(Plus I don't really know how to operate those!)
 
@FredOverflow not me
 
user406009
Yep, definitely available in Linux.
 
user406009
3:05 PM
 
user406009
You would hardly need it's advanced features to have fake webpages and whatnot. But you can certainly use it's intput and output features only.
 
Err... on the Chrome JS console, how do I print a variable? Like, I have this BigNumber, and when I say alert(n); I can show it in a box.
But how to just print it in the console?
 
(If I just say n; I get BigNumber.)
@EthanSteinberg Perfect, thanks!
 
3:10 PM
print( 2+2 ); seems to work
 
Ah, no, still only prints "BigNumber"
I.e. the conversion to string isn't done
Ahhh: n + "";
The old Javascript fuckery
Now I want to die.
 
I'd oblige if you were within death ray range
 
@DeadMG "Who wants to buy a death ray? Come on guys... it's made from solid titanium! Anyone?"
 
@StackedCrooked oh don't remind me of haskell. i stopped just when it was getting interesting. now i have this blog articles to write and sonata to compose... argh
 
@EthanSteinberg: Does PhantomJS have an interactive mode?
 
@AlfPSteinbach In once read that you should plan your play time first and then plan your work time in terms of the play time. So that the play times comes as an award for the work time. This should make work more appealing... Or something..
 
@StackedCrooked What if I enjoy working, does that change anything? :)
 
user406009
@KerrekSB Probably not. It looks more like Phantomjs is just there to create applications with js, similar to node.js.
 
3:17 PM
@FredOverflow Then you have no problem to begin with.
 
Hm, OK. Can I at least concatenate multiple JS files?
It can't even read from the standard input - what a piece of crap
 
@KerrekSB put -> what?
 
@FredOverflow yes. Freudian repeater
 
user406009
@KerrekSB injectJs(filename)
 
ReferenceError: Can't find variable: injectJs
 
3:22 PM
freedb seems to be down somehow, I need to refresh 5 times before it works... am I the only one?
 
user406009
@KerrekSB Its in the object phantom.
 
user406009
So phantom.injectJs.
 
@EthanSteinberg Oh OK. Cheers.
How do I access command line args?
Ah, never mind, found it
phantom.args
 
PhantomJS is mostly for testing AFAIR.
 
@CatPlusPlus Yes, but interactive testing would be nice, too
 
3:29 PM
i get so mad at the close-voters and down-voters stackoverflow.com/questions/8545608/copy-a-cd-byte-for-byte
 
Write proper unit-tests, you lazy fish!
 
i think democracy is dangerous without a good school system, i.e. with retarded population
 
a problem many Western countries are finally noticing
 
I now have libgmp and Maple agreeing on modular exponentiation results, but not BigNumber :-(
 
Also, console logging in Chrome, Fx et al is always console.log.
 
3:30 PM
you can't teach your kids Shakespeare and then ask them to do finance
 
user406009
@Alf What if we forced everyone to vote, but secretly tossed out all ballots from people with low IQs
 
That violates integrity and anonymity of the voting.
Might as well not bother with voting at all.
 
user406009
That is why you toss out the ballots secretly. People will never know.
 
user406009
And that is also why you force people to vote.
 
user406009
Probably Australia style, with an extra tax for not voting.
 
3:33 PM
Ballots are not signed, how do you plan to assign IQ to each one?
 
a longer voting questionnaire :)
 
Right.
 
user406009
When the citizens swipe their ID card that verifies that they are a citizen, have the software test the recorded IQ on the card.
 
with a friendly message: your vote has been discarded due to utter stupidity of the voter
 
@EthanSteinberg And then what?
 
3:35 PM
problem is IQ isn't everything. It's very a very ... limited ... measure of intelligence
 
You can not hand them ballot in that case, but you don't know which one is theirs after they fill it.
IQ is downright useless.
 
and that's why you need to educate everyone
 
user406009
You are right, an IQ test is worthless.
 
user406009
Perhaps a political literacy test?
 
user406009
IE which issue does this cannidate support?
 
3:36 PM
a proper one isn't completely useless, but still very limited.
political literacy isn't always super-relevant. Often people vote only for popular issue opinions
 
Ah, got it: The BigNumber library automatically creates floats, so integer division takes an extra command.
 
At least in countries with more than two big parties
I'm glad I live in a country with more than two big parties. Otherwise life is so dull.
 
which country?
 
user406009
I wish the US had a better third party. We really need the Pirate Party right now to protect us from evil media companies.
 
@rubenvb Why do you need more than one party? You can only party at one location at the same time, so...
 
3:41 PM
@FredOverflow phew, the internet isn't completely oblivious to my dry jokes. You make a good point though :)
 
Seems like Chrome is miles faster than PhantomJS...
 
@DeadMG Belgium, we have probably the most number of relevant parties (at least for the federal government)
 
nobody uses JS for the speed
heh, we only have three here
 
3's a lot better than 2.
much less polarization.
 
user406009
I just can't wait until Dart and its VM replaces JS. Then we can finally use any language on the web.
 
3:45 PM
although four or five is the sweet spot
 
4:05 PM
hmm
just realized half my family didn't tell me what they wanted for Christmas
and I've suddenly realized that it's getting kind of close
 
the result of one of those useless unremembered discussions?
 
no, we email them to each other for future reference
 
void donothing(int i) { } // has a security vulnerability because you can do this:
donothing(system("notepad.exe"));
 
Hello :) I have a little question about mutex
I'm posting a question here : stackoverflow.com/questions/8545957/…
But in the comments it is said that it would be wiser to have a object-scope mutex
I would like to now why? The read access won't cause a race condition
 
static std::timed_mutex mutex; is not thread-safe inside a function.
 
4:17 PM
Why?
 
Good morning.
 
When the function is called for the first time the mutex needs to be created. And this part is not protected so races can occur.
 
Okay, thanks for your response
I learned STL containers are now thread safe
But then how to have a safe-access?
Should I lock it with the same mutex wherever I modify it?
 
@StackedCrooked That's not true. The implementation takes care of thread-safe initialization of statics.
 
user406009
Yeah, you could create a typeNamesMutex inside your class.
 
user406009
4:21 PM
And just lock that whenever you access typeNames.
 
@DeadMG Is this new in C++11?
 
no, it's effectively enforced amongst any compiler that wanted to support parallelism in C++03 too
just like thread-safe exceptions
 
And should I also lock read access?
 
user406009
Yes.
 
user406009
Although you could use a fancier lock that allows concurrent readers.
 
4:22 PM
at least, I'm pretty sure that this is actually the case
 
What kind of lock should I use in that case?
 
for example, if you look at the MSDN documentation, it clearly states that assigning to them is not-thread safe, but says nothing about constructing them
To cite §3.6 of C++11 "Declaration statement [stmt.dcl]":
If control enters the declaration concurrently while the variable is being initialized, the concurrent execution shall wait for completion of the initialization.
 
user406009
@Geoffroy This is it in boost.
 
@DeadMG that is awesome. Automatic thread-safe initialization.
 
it's not that awesome, I can describe an algorithm which can do it
it's not even that complex
 
4:26 PM
I mean it's good to have
 
user406009
@Geoffroy
But be careful, you still might need to lock the whole "transaction".
Like for example, what happens when the typeName is set, but the typeFlagNames is not set and then something requests a name ...
 
which reminds me of some code in libc++ which becomes thread-safe due to that
 
and lockless, too
at least, in the general case
 
Okay :) That's a bit more complicated than I though :)
 
user406009
Just lock the whole object. Much simpler.
 
user406009
4:28 PM
You do not need a try_lock as your locks should not be held for very long anyways.
 
At that point I work in static methods
@EthanSteinberg But then it would fail if there is a concurrent access no?
 
user406009
No, it would wait until it is available.
 
user406009
Just keep your locks small and the wait should be almost nothing.
 
critical sections are pretty lightweight if there is no contention
 
Okay...
Could you help me make a community wiki for that? Would be more than useful
 
4:38 PM
not really
 
@StackedCrooked Wow! WTF...
 
4:53 PM
@StackedCrooked he he, they were pwnd :-)
talking about stupid ms, the first thing i noted about windows 7 was that on my laptop screen, menu selections were white on white. they're really a kind of off-white on white, but they looked white on white, i.e. invisible. and as it turned out, can't be configured except by installing some big "theme" that fouls up lots of other things. i wonder what genius was responsible. why they don't listen
 
5:13 PM
Do you think it's acceptable if a GUI updates itself by actively polling the program state at regular intervals?
The traditional solution is to use something like the observer pattern. Where the GUI can register itself as a listener for change-events.
But I find that this often leads to error-prone code.
Especially in threaded applications.
So polling seems like a safer alternative.
 
@AlfPSteinbach Sounds like a bug to me. My Windows 7 Menus are just fine
they're pretty blue
 
It's also very unlike Windows to have bugs like this.
Their GUI is their product, basically.
 
@DeadMG they're not any particular color really. they're fined tuned for the display used by the ms gui person. they're just brittle, very very ungood for persons with limited sight and/or computer knowledge, and ms removed the ability to configure
 
Removing the ability to configure stuff is evil. (Thinking about Ubuntu Unity right now..)
 
are gnomes always from switzerland?
 
Xeo
5:20 PM
@StackedCrooked And you gotta admit, it's pretty good.
 
you could use the High Contrast mode
left alt, left shift, print screen is the key combo
 
@Xeo Yes. After using Ubuntu for nearly 2 years at work I realize that Windows UI is pretty good.
The forced switch to Unity is their most evil move ever.
Ubuntu has lost it's #1 spot on distrowatch for that reason alone.
I hate Unity with a passion.
It does everything wrong.
</rant>
 
ubuntu is stupid. use arch
unity is a failed attempt at a Mac/Windows7 combination
It lacks everything that makes the Windows 7 taskbar so awesome, and all Linux apps lack usefulness when the menu bar is at the top
 
I'm trying to understand why Ubuntu is slow. Launching simple applications like textedit or terminal often take 2 or more seconds. I wonder if it has something to do with ubiquitous shared linking.
 
Ubuntu is slow because it runs just as many services as Windows, but they're less optimized/tuned to each other
 
user406009
5:28 PM
Ubuntu always runs faster once I turn on LXDE.
 
user406009
Then it runs faster than windows.
 
Once the application has started it performs well. It's the startup times that are gratingly slow. I noticed that this is not the case on Gentoo.
 
user406009
At least on the 1 GB ram computer I was using at the time.
 
@StackedCrooked Gentoo is nearly, but not as good as Arch. Arch is the sumum of Linux performance. In all aspects
 
user406009
@StackedCrooked You can look at prelink to avoid dynamic linking.
 
5:30 PM
Haven't tried arch out yet.
 
@StackedCrooked Read the wiki. Then read it again. Then read and follow the unofficial beginner's guide. Remember it doesn't come with a default GUI. You have to install it and set the startup options to load it (see wiki). After that, everything's great.
 
@EthanSteinberg I'll have a look at it.
 
user406009
1
A: Binding pointer-to-member-function to std::pair and casting to void*

Ethan SteinbergIt is segfaulting because your temporary pair std::pair<T*, void (T::*)()> p(arg,function); is falling off the scope before your createThread function is called. Store a copy of your pair in a heap memory and pass that. Then delete the copy inside the createThread function. EDIT As an as...

 
user406009
People keep on asking how to bind things to C callbacks.
 
user406009
Where would be a good place to put a tutorial on how to convert C callbacks to std::function callbacks?
 
5:43 PM
nowhere, because you can't
 
@DeadMG yes you can: you bind the first parameter with a pointer to the instance you want a bound function for. But indeed, that's probably not what people are looking for...
 
user406009
Is it acceptable to create a question like "Help me, I want to use XXX C interface that requires a C callback function. What is an easy C++ way to pass member functions or bind parameters?" And then immediately post an answer.
 
@rubenvb That won't convert to a function pointer.
 
The secret exchange should now work reliably (for messages < 100 chars), and I also have an offline application that does the same thing.
 
user406009
@DeadMG you write a wrapperFunction that simply calls the boost::function passed in.
 
5:46 PM
The result of bind is a function object with state, and it will not magically convert to a function pointer
there is no way in Standard C++ to pass a stateful function object where a non-stateful function pointer is expected
 
user406009
void callFunction(void* data)
{

   boost::function<void(void)> *func = (boost::function<void(void)>* ) (data);
   (*func)();
   delete(func);
}
 
The offline app also has a random number generator to suggest long secrets, as well as instant MD5 hashing of the shared secret
 
@EthanSteinberg That can't be done in the general case.
You'd have to write a specific wrapper for every separate C function that uses that convention
 
user406009
Yes it can. All C callbacks have an option for user state.
 
Xeo
Variadic templates. ♪
 
5:47 PM
no, they most assuredly don't
the well-written ones do
but there's no language rule for it
 
user406009
Which common C callbacks do not have user state?
 
and there's also no way to know if a given void* parameter is the right one, as a C function can take as many as they like
how about the Windows API message proc?
you can have user state, but it doesn't take a void* argument for it
there's no way you could possibly automate code that would work with it
 
user406009
No, but you write one function wrapper and then you are set for that api.
 
sure, but you have to write every wrapper, manually.
and there's no guarantee it's even possible.
the only way that you could come even close is exception-upping
 
user406009
It is almost guarenteed. A C callback without user data is like an abstract class with a private constructor(and no friends).
 
5:50 PM
almost guaranteed? it's not almost guaranteed at all
it's likely, that's it
and even if it was guaranteed, the location of the parameter is not determinable at all
so you still wouldn't be able to write a generic function to cope with it
 
user406009
Every C api I have worked with, including libev, gtk, signals, pthread off the top of my head, has allowed user data.
 
well I'm glad you got lucky
but there are plenty of APIs which do not conform to a common interface convention
especially when that convention is too weak to be used as a generic wrapper anyway
 
user406009
Oh shoot, just found a counter example for myself. qsort has no user data at all.
 
lol
you can exception-up it
not very clean though
 
user406009
What is "exception-up"ing?
 
5:53 PM
@DeadMG I thought you guys called it "upception", or "inception"
 
lol
nah
there's not really a good name for it
exception upping is where you throw an exception, then rethrow and catch it later
 
user406009
Yay 999 rep. Perfect number.
 
user406009
@DeadMG Is that legal though? I thought passing exceptions into C land was UB.
 
C land never sees the exception
it's entirely caught within C++ land
 
5:58 PM
@EthanSteinberg In one day?
 
member for 1 year, 4 months
 
user406009
Very useful technique anyways. If I ever get into the position of being forced to use C functions without user data, it would be very useful.
 
eh
I think it has the potential to be UB, if you chained them
 

« first day (427 days earlier)      last day (4514 days later) »