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
No Safe Word
Feb 26, 2005

yaoi prophet posted:

Monkey patching or duck punching. The former is a derivation from 'guerilla patching', and the latter is because if it walks like a duck, but it doesn't quack like a duck, you punch it until it makes the noise you want :haw:

That isn't monkey patching because he's not modifying a class, he's modifying an instance. I know monkey patching as modifying an existing class and then all instances of that class (and the class itself of course) get whatever modifications you've made regardless of whether you want to or not.

I don't know what the name is for that particular feature.

Adbot
ADBOT LOVES YOU

Vino
Aug 11, 2010
Maybe this is my C++ experience working against me but I can't see that as being anything but a bad thing. How would it not cause problems and bugs?

tef
May 30, 2004

-> some l-system crap ->

ultra-inquisitor posted:

What is the name of the language feature that lets type definitions be modified at runtime? eg
code:
class Foo {}

Foo f;
f.x = 10; // creates new member 'x' on this instance of Foo

Prototypes fit this bill (ish)

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Vino posted:

Maybe this is my C++ experience working against me but I can't see that as being anything but a bad thing. How would it not cause problems and bugs?

The only example that I've come across in my very limited experience is eventlet for python. It monkey-patches python standard libraries like socket to support async I/O. I guess as far as bugs go, it's just like any other thing you code...issues with it get reported and fixed?

raminasi
Jan 25, 2005

a last drink with no ice

Vino posted:

Maybe this is my C++ experience working against me but I can't see that as being anything but a bad thing. How would it not cause problems and bugs?

Wikipedia posted:

Monkey patching is used to:

* Replace methods/attributes/functions at runtime, e.g. to stub out a function during testing;
* Modify/extend behaviour of a third-party product without maintaining a private copy of the source code;
* Apply a patch at runtime to the objects in memory, instead of the source code on disk;
* Distribute security or behavioural fixes that live alongside the original source code (an example of this would be distributing the fix as a plugin for the Ruby on Rails platform).

tef
May 30, 2004

-> some l-system crap ->

Vino posted:

Maybe this is my C++ experience working against me but I can't see that as being anything but a bad thing. How would it not cause problems and bugs?

It does cause problems and bugs. Sometimes it is possible to monkey patch when it is not possible to edit. Roughly, when you're monkey patching something else is already broken.

At best it is like ad-hoc dependency injection: Use *these* socket libraries instead of the stdlib ones.

Other times it is just 'man why doesn't string have this it would be cool' and praying that no-other library wants to add those methods.

slacjs
Feb 27, 2009

This is a query about which language/library/whatever is best to use for the task at hand. I have an assignment to produce a "Direct Manipulation" interface. The idea is that the interface will teach the user how to do a task such as making a pizza. To quote my assignment:

The Assignment posted:

Direct manipulation interfaces draw on users’ real-world knowledge by using representations of concrete objects and hence are believed to make the systems easy to learn. The fact that actions can be undone is intended to encourage users to explore the system. DM interfaces frequently use animation to show the effect of an action and cursor changes to denote the action to be performed. Metaphors may be used when the objects within a system have no obvious concrete representation.

The code isn't important. Marks are awarded based on the interface alone.

I'm having a hard time deciding what language/library/whatever is best to use. I've been looking into C# but I'm not sure it's the best tool. It's great since it has a lot of the stuff done already, such as buttons though I haven't found a way to make draggable items. I've thought maybe javascript but that seems like a comedy option and I don't have much experience in it.

Any ideas? Thanks for the help.

Zhentar
Sep 28, 2003

Brilliant Master Genius
I don't know much about it, but I'm pretty sure C# has support for the drag and drop stuff you'd be interested in.

The other option you should consider is C++/Qt4. Qt4 makes making a nice looking interface easier than anything else I've tried.

nielsm
Jun 1, 2009



JavaScript doesn't actually sound as a bad idea at all, especially not if you use something like jQuery UI.
Flash or Silverlight may also be options.
It sounds like graphical quality is important for the project, and I'd say that general desktop application languages/frameworks aren't the most suited for that.

slacjs
Feb 27, 2009

Thanks a lot for the suggestions. I've gone with the JQuery as it seems pretty simple and does exactly what I need it to do.

N.Z.'s Champion
Jun 8, 2003

Yam Slacker
Is there a library that will let me read a PDF or SVG and let me know the X/Y/width/height coordinates of everything in it? E.g. something that will resolve nested transformation matrices, font sizes and kerning and other font metrics, or any other layout aspects of the format.

I guess I'm looking for a PDF renderer with an API where I can query where it's putting things on the page. Does such a thing exist?

N.Z.'s Champion fucked around with this message at 02:46 on Dec 1, 2010

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

You guys have discussed monkey patching and duck punching but what about monkey punching? Because that sounds really humourous and cool.

1337JiveTurkey
Feb 17, 2005

Scaramouche posted:

You guys have discussed monkey patching and duck punching but what about monkey punching? Because that sounds really humourous and cool.

It should probably be something more extreme. Come to think of it, nothing really prohibits __metaclass__ from being called self-recursively in Python....

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
I propose "snake-loving". If an exception is thrown, you have the opportunity to examine and edit the callstack. When you make changes, the runtime modifies the sequence of calling classes so that it would have worked how you describe. Then just try it again.

Coming soon to a batshit scripting language near you.

1337JiveTurkey
Feb 17, 2005

Well, that's what we have continuations for, right?

mr_jim
Oct 30, 2006

OUT OF THE DARK

Internet Janitor posted:

I propose "snake-loving". If an exception is thrown, you have the opportunity to examine and edit the callstack. When you make changes, the runtime modifies the sequence of calling classes so that it would have worked how you describe. Then just try it again.

Coming soon to a batshit scripting language near you.

That sounds both awesome and terrible at the same time.

pseudorandom name
May 6, 2007

Congratulations, you've just badly reimplemented Lisp exceptions.

tef
May 30, 2004

-> some l-system crap ->
Also available in dylan.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Internet Janitor posted:

I propose "snake-loving". If an exception is thrown, you have the opportunity to examine and edit the callstack. When you make changes, the runtime modifies the sequence of calling classes so that it would have worked how you describe. Then just try it again.

Coming soon to a batshit scripting language near you.

I sort of want to implement this.

Actually I think I just want to think about how you'd do it but never actually write anything.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Plorkyeran: If you are successful, you could theoretically produce a language in which self-modification and exceptions are the only forms of flow control.

God help us all.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Well the obvious ultimate extension of the idea is a language where the only two operations are exception throwing and stack rewriting but I have a feeling that if one somehow found a way to make that work it'd be boringly similar to lambda calculus.

Bozart
Oct 28, 2006

Give me the finger.

Plorkyeran posted:

I sort of want to implement this.

Actually I think I just want to think about how you'd do it but never actually write anything.

Forget about implementing it. I just want to see the dev hype and the fanboyism and the :smug: surrounding something so mind-blowingly wretched.

mr_jim
Oct 30, 2006

OUT OF THE DARK

Plorkyeran posted:

Well the obvious ultimate extension of the idea is a language where the only two operations are exception throwing and stack rewriting but I have a feeling that if one somehow found a way to make that work it'd be boringly similar to lambda calculus.

Well, you see, there isn't a need for an integer type because numbers are represented by the depth of the call stack.
      /
:smug:

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

mr_jim posted:

Well, you see, there isn't a need for an integer type because numbers are represented by the depth of the call stack.
      /
:smug:

:barf:

drat you all.

Pleads
Jun 9, 2005

pew pew pew


Ugh, finding ColdFusion resources sucks.

Does anyone know if it's possible to get the value from an existing cookie on another domain using ColdFusion? Wording it like that sounds like a pretty big security hole, but it's worth a shot.

I need to check if a cookie exists from another website, because the web-app I'm working on will need to use that session cookie for its calls if it exists, otherwise I have to go through the authentication process to get a session value first.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Pleads posted:

Ugh, finding ColdFusion resources sucks.

Does anyone know if it's possible to get the value from an existing cookie on another domain using ColdFusion? Wording it like that sounds like a pretty big security hole, but it's worth a shot.

I need to check if a cookie exists from another website, because the web-app I'm working on will need to use that session cookie for its calls if it exists, otherwise I have to go through the authentication process to get a session value first.

The whole point about the address associated with cookies is that they're only given to that particular website. If I had a website which could unconditionally grant cookies, I could pose as the site's vistors on any website they happened to be logged in on - be it a bank or Facebook. So yes, it would be a massive security hole - which is why you can't do it.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



N.Z.'s Champion posted:

Is there a library that will let me read a PDF or SVG and let me know the X/Y/width/height coordinates of everything in it? E.g. something that will resolve nested transformation matrices, font sizes and kerning and other font metrics, or any other layout aspects of the format.

I guess I'm looking for a PDF renderer with an API where I can query where it's putting things on the page. Does such a thing exist?

I know a different group of devs here uses something like that to rip apart PDFs for our product and I'm fairly sure it's using and API on some piece of Adobe software to extract most of the information you mention. I should mention that I know it still depends on either the PDF having all font information embedded or the local machine having all the font installed or things start coming out wrong, anyway.

Edit: sorry I can't be more helpful :\

Munkeymon fucked around with this message at 23:57 on Dec 1, 2010

Standish
May 21, 2001

Pleads posted:

Does anyone know if it's possible to get the value from an existing cookie on another domain using ColdFusion?
It's not possible using any programming language.

The only way to solve your problem requires the third-party domain to tell actively tell your domain the cookie value, (e.g. by writing something like "<img src=http://yourdomain.com/?cookie=0x92323266w436....>" to the browser)

Pleads
Jun 9, 2005

pew pew pew


I thought so :sigh: Sadly we don't have access to how the second site sets its cookies despite controlling its license. Hosted solutions :argh:

Thanks!

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Let's imagine a hypothetical snake loving implemention in Python. There's a few obvious "practical" applications:

VB's greatest contribution to programming, On Error GoTo Next:
code:
try:
    ...
except Exception as e:
    frame = e.stack_frame
    while frame:
        # if there are any more statements in the current function, move to the next one
        if frame.current_statement < len(frame.statements):
            frame.current_statement += 1
            frame.resume()
        # otherwise go up a step in the call stack
        frame = frame.parent
    # no remaining statements after the one that failed so we win
    sys.exit(0)
Get rid of that annoying requirement to give variables values before using them:
code:
try:
    ...
except NameError as e:
    name = re.search("'([^']+)'", e[0]).group(1)
    e.frame.locals[name] = None
    e.frame.resume()
Of course, this'll usually just result in type erorrs instead, so we need to set up some automatic type conversion:
code:
try:
    ...
except TypeError as e:
    if re.search("is not subscriptable", e[0]) or re.search("does not support item assignment", e[0]):
        e.source = {}
        e.frame.resume()

    # tried to call a non-function
    if re.search("is not callable", e[0]):
        e.source = lambda *args: pass
        e.frame.resume()

    # wrong number of arguments
    match = re.search("takes exactly (\d+) arguments \((\d+) given\)", e[0])
    if match:
        if e[1] < e[2]:
            e.args = e.args[0:e[1] - 1]
        else:
            e.args.extend([None] * (e[1] - e[2]))
        e.frame.resume()

    # right number of args, wrong types
    for arg in e.args:
        if "int" in arg.expected_types:
            if arg.type == "string":
                arg.value = int(arg.value)
            else
                arg.value = 0
        elif "string" in arg.expected_types:
            arg.value = str(arg.value)
        # and so on
    e.frame.resume()

except KeyError as e:
    e.source[e[0]] = None
    e.frame.resume()
I guess this doesn't actually involve any callstack rewriting and so doesn't have much to do with snake loving but the idea of implementing weak typing via userland error handling is sort of amusing too. I suppose the snake-fucker way to do this would be to rewrite the call stack such that the variables are of the correct type (preferably introducing a lot of side effects in the process) instead of just directly "fixing" them.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

What have I spawned? :psyduck:

Opinion Haver
Apr 9, 2007

Plorkyeran posted:

Let's imagine a hypothetical snake loving implemention in Python. There's a few obvious "practical" applications:

VB's greatest contribution to programming, On Error GoTo Next:
code:
try:
    ...
except Exception as e:
    frame = e.stack_frame
    while frame:
        # if there are any more statements in the current function, move to the next one
        if frame.current_statement < len(frame.statements):
            frame.current_statement += 1
            frame.resume()
        # otherwise go up a step in the call stack
        frame = frame.parent
    # no remaining statements after the one that failed so we win
    sys.exit(0)
Get rid of that annoying requirement to give variables values before using them:
code:
try:
    ...
except NameError as e:
    name = re.search("'([^']+)'", e[0]).group(1)
    e.frame.locals[name] = None
    e.frame.resume()
Of course, this'll usually just result in type erorrs instead, so we need to set up some automatic type conversion:
code:
try:
    ...
except TypeError as e:
    if re.search("is not subscriptable", e[0]) or re.search("does not support item assignment", e[0]):
        e.source = {}
        e.frame.resume()

    # tried to call a non-function
    if re.search("is not callable", e[0]):
        e.source = lambda *args: pass
        e.frame.resume()

    # wrong number of arguments
    match = re.search("takes exactly (\d+) arguments \((\d+) given\)", e[0])
    if match:
        if e[1] < e[2]:
            e.args = e.args[0:e[1] - 1]
        else:
            e.args.extend([None] * (e[1] - e[2]))
        e.frame.resume()

    # right number of args, wrong types
    for arg in e.args:
        if "int" in arg.expected_types:
            if arg.type == "string":
                arg.value = int(arg.value)
            else
                arg.value = 0
        elif "string" in arg.expected_types:
            arg.value = str(arg.value)
        # and so on
    e.frame.resume()

except KeyError as e:
    e.source[e[0]] = None
    e.frame.resume()
I guess this doesn't actually involve any callstack rewriting and so doesn't have much to do with snake loving but the idea of implementing weak typing via userland error handling is sort of amusing too. I suppose the snake-fucker way to do this would be to rewrite the call stack such that the variables are of the correct type (preferably introducing a lot of side effects in the process) instead of just directly "fixing" them.

What the gently caress :stare:

Thrombosis
May 7, 2007
Any suggestions for programs or scripts for custom pasting around a selection? I'm looking to be able to
1) select a word in a plain text file
2) hit a key combination (like Crtl + something)
3) have it enter text before and after my selection.

So I select the word "fox" and hit a key, and it turns it into <seg>fox</seg> or whatever I want it to put around the selection.

PotatoManJack
Nov 9, 2009
I have extremely rudimentary understanding of programming (I did a tiny bit of C++ programming in high-school (I'm 31 now) and read like 3-4 chapters of teach yourself c++), but have always dreamed of programming my own turn based strategy style of game - most likely in a roguelike style.

My question is, how long would it take me to build the knowledge to be able to do something like this - probably in Python because of its friendliness - considering I have a full-time job, house, wife, and dogs?

Sorry, bit of a loaded question but I'm just trying to understand if this is a pipe-dream or an actual possibility.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Thrombosis posted:

Any suggestions for programs or scripts for custom pasting around a selection? I'm looking to be able to
1) select a word in a plain text file
2) hit a key combination (like Crtl + something)
3) have it enter text before and after my selection.

So I select the word "fox" and hit a key, and it turns it into <seg>fox</seg> or whatever I want it to put around the selection.

If you're using Mac OS X and don't mind copying then pasting the selected text, here's some AppleScript, for which you could set a hotkey with something like FastScripts:

code:
set the clipboard to "<seg>" & (the clipboard as text) & "</seg>"
If you just want to wrap selected text in-place, use a text editor and write a little macro for yourself.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

PotatoManJack posted:

I have extremely rudimentary understanding of programming (I did a tiny bit of C++ programming in high-school (I'm 31 now) and read like 3-4 chapters of teach yourself c++), but have always dreamed of programming my own turn based strategy style of game - most likely in a roguelike style.

My question is, how long would it take me to build the knowledge to be able to do something like this - probably in Python because of its friendliness - considering I have a full-time job, house, wife, and dogs?

Sorry, bit of a loaded question but I'm just trying to understand if this is a pipe-dream or an actual possibility.

Work your way through Learn Python the Hard Way and you will have everything you need to make your dream project playable. Give yourself a month to work through that book.

fankey
Aug 31, 2001

I'm looking for information about calculating the effective resolution of a display. I'm basically trying to compare a monochrome LCD of a given resolution/size to a grayscale LCD with different resolution/size. I'm going to mock up some different screens in Photoshop but I'd also like to have some 'scientific' data to back up why we really need to splurge on a grayscale LCD for a device.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

I'm looking at hacking on Clang for a lab project - but all the clang plugin tutorials that I've found appear to be broken for the current svn checkout of llvm/clang. They mainly seem to complain about missing header files, and if I'm lucky, I get complaints about no matching function for call to clang::Diagnostic::Diagnostic(clang::TextDiagnosticPrinter*&). :sigh: I know there are a few clang fans around here; anybody know of any better ways of getting my feet wet (taht don't involve sifting through INT_MAX doxygen pages)?

Dijkstracula fucked around with this message at 09:00 on Dec 3, 2010

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Dijkstracula posted:

I'm looking at hacking on Clang for a lab project - but all the clang plugin tutorials that I've found appear to be broken for the current svn checkout of llvm/clang. They mainly seem to complain about missing header files, and if I'm lucky, I get complaints about no matching function for call to clang::Diagnostic::Diagnostic(clang::TextDiagnosticPrinter*&). :sigh: I know there are a few clang fans around here; anybody know of any better ways of getting my feet wet (taht don't involve sifting through INT_MAX doxygen pages)?

Most Clang and LLVM C++ APIs are pretty unstable; there was a very recent change which moved all the header files in llvm/System to llvm/Support, and some of the code in Diagnostic got split out into a separate object which can be shared between translation units. I suggest using CompilerInstance to create these things; the code in examples/ — e.g. examples/clang-interpreter — is really the best getting-started guide I can suggest.

Feel free to PM me or open a thread.

Adbot
ADBOT LOVES YOU

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





I have a messaging system that consumes arbitrary binary sequences from a number of producers. Assuming all producers can read all other producers output, is there a way to uniquely identify producers that makes it impossible for producers to masquerade as other producers that doesn't rely on shared keys?

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