Search Results

Search found 1506 results on 61 pages for 'replacement'.

Page 52/61 | < Previous Page | 48 49 50 51 52 53 54 55 56 57 58 59  | Next Page >

  • Driver denied access to PCI card

    - by Corin
    We wrote a Windows device driver to access our custom PCI card. The driver uses CreateFile to get a handle to the card. We recently had trouble at one installation were the card appeared to stop working. We tried replacing the card (the replacement appeared not work either). The computer vendor replaced the motherboard and both cards still failed to work. We put the cards in a different computer and both worked fine. We now have the computer at our office for examination. The Windows Device Manager lists our card in Other Devices as usual and says it's working fine. However, our driver initialization fails when it attempts to connect to the card. We created a test version of our driver with some extra debugging and determined that CreateFile is failing. It returns INVALID_HANDLE_VALUE as it is supposed to on failure. GetLastError indicates the error is Access is Denied. Since we're logged into the system as a local administrator, what can deny access to the device?

    Read the article

  • Unmanaged Process in Mono

    - by Residuum
    I want to start a quite expensive process (jackd) from a Mono application, and do not need full access to the process from the application itself. As the process is so expensive in terms of CPU usage, a Glib.IdleHandler for polling the process will not work, as it is never executed, and the GUI becomes unresponsive. Is there any way to have the cake and eating it at the same time in Mono? EDIT: I only need to be able to start and stop the process from Mono, I do not need information about the state of the process or if it has exited, as my application will register itself as a client to jackd, basically I need a "replacement" for bash's jackd &>/dev/null 2>&1 & for the System.Diagnostics.Process ;). Here is what I have so far for starting and stopping the process: public void StartJackd() { _jackd = new Process (); _jackd.StartInfo = _jackdStartup; if (_jackd.Start ()) { _jackd.EnableRaisingEvents = true; _jackd.Exited += JackdExited; } } public void StopJackd() { if (_jackd != null && !_jackd.HasExited) { _jackd.CloseMainWindow (); } } And somewhere else I have this code for registering the IdleHandler: GLib.Idle.Add(new GLib.IdleHandler(UpdateJackdConnections)); This handler will fire all the time, while the process is not running, but never, when jackd is running.

    Read the article

  • Loading JNI lib on Mac OS X?

    - by Clinton
    Background So I am attempting to load a jnilib (specifically JOGL) into Java on Mac OS X at runtime. I have been following along the relevant Stack Overflow questions: Maven and the JOGL Library Loading DLL in Java - Eclipse - JNI How to make a jar file that include all jar files The end goal for me is to package platform specific JOGL files into a JAR and unzip them into a temp directory and load them at start-up. I worked my problem back to simply attempting to load JOGL using hard-coded paths: File f = new File("/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/libjogl.jnilib"); System.load(f.toString()); f = new File ("/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/libjogl_awt.jnilib"); System.load(f.toString()); I get the following exception when attempting to use the JOGL API: Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path But when I specify java.library.path by adding the following JVM option: -Djava.library.path="/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/" Everything works fine. Question Is it possible use System.load (or some other variant) on Mac OS X as a replacement for -Djava.library.path that is invoked at runtime?

    Read the article

  • Replace without the replace function

    - by Molly Potter
    Assignment: Let X and Y be two words. Find/Replace is a common word processing operation that finds each occurrence of word X and replaces it with word Y in a given document. Your task is to write a program that performs the Find/Replace operation. Your program will prompt the user for the word to be replaced (X), then the substitute word (Y ). Assume that the input document is named input.txt. You must write the result of this Find/Replace operation to a file named output.txt. Lastly, you cannot use the replace() string function built into Python (it would make the assignment much too easy). To test your code, you should modify input.txt using a text editor such as Notepad or IDLE to contain different lines of text. Again, the output of your code must look exactly like the sample output. This is my code: input_data = open('input.txt','r') #this opens the file to read it. output_data = open('output.txt','w') #this opens a file to write to. userStr= (raw_input('Enter the word to be replaced:')) #this prompts the user for a word userReplace =(raw_input('What should I replace all occurences of ' + userStr + ' with?')) #this prompts the user for the replacement word for line in input_data: words = line.split() if userStr in words: output_data.write(line + userReplace) else: output_data.write(line) print 'All occurences of '+userStr+' in input.txt have been replaced by '+userReplace+' in output.txt' #this tells the user that we have replaced the words they gave us input_data.close() #this closes the documents we opened before output_data.close() It won't replace anything in the output file. Help!

    Read the article

  • Modify onclick function with jQuery

    - by Chris Barr
    I've got a button that has an onclick event in it, which was set on the back end from .NET. Beside it is a checkbox <button class="img_button" onclick="if(buttonLoader(this)){WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('uxBtnRelease', '', true, '', 'somepage.aspx?oupid=5&fp=true', false, true))} return false;" type="button">Release</button> <input type="checkbox" checked="checked" id="myCheckbox"> When the checkbox is clicked, needs to change the value of the query string in the URL inside the onclick function of the button. So far I have this, and the idea is right, but I keep getting errors when it's run: "Uncaught SyntaxError: Unexpected token ILLEGAL" var defaultReleaseOnClick=null; $("#myCheckbox").click(function(){ var $releaseBtn = $(".img_button"); if(defaultReleaseOnClick==null) defaultReleaseOnClick=$releaseBtn.attr("onclick"); var newOnClickString = defaultReleaseOnClick.toString().replace(/&fp=[a-z]+'/i,"&fp="+this.checked); $releaseBtn.removeAttr("onclick").click(eval(newOnClickString)); }); I know it seems kinda hacky to convert the function to a string, do a replacement, and then try to convert it back to a function, but I don't know any other way to do it. Any ideas? I've set up a demo here: http://jsbin.com/asiwu4/edit

    Read the article

  • How to cache code in PHP?

    - by Janis Peisenieks
    I am creating a custom form building system, which includes various tokens. These tokens are found using Regular Expressions, and depending on the type of toke, parsed. Some require simple replacement, some require cycles, and so forth. Now I know, that RegExp is quite resource and time consuming, so I would like to be able to parse the code for the form once, creating a php code, and then save the PHP code, for next uses. How would I go about doing this? So far I have only seen output caching. Is there a way to cache commands like echo and cycles like foreach()? Because of misunderstandings, I'll create an example. Unparsed template data: Thank You for Your interest, [*Title*] [*Firstname*] [*Lastname*]. Here are the details of Your order! [*KeyValuePairs*] Here is the link to Your request: [*LinkToRequest*]. Parsed template: "Thank You for Your interest, <?php echo $data->title;?> <?php echo $data->firstname;?> <?php echo $data->lastname;?>. Here are the details of Your order! <?php foreach($data->values as $key=>$value){ echo $key."-".$value }?> Here is the link to Your request: <?php echo $data->linkToRequest;?>. I would then save the parsed template, and instead of parsing the template every time, just pass the $data variable to the already parsed one, which would generate an output.

    Read the article

  • RMagick transparent_color deprecated? What's the alternative?

    - by user315975
    I'm developing an app that does a fair amount of generating transparent pngs on the fly. These are used as overlays, to show areas of interest in a graphic, so they have to have transparent backgrounds. I am developing in Ruby on Rails, deploying on Heroku. What works fine in development is not working in production. I get this error when I call a drawing routine using RMagick: NotImplementedError (the `transparent_color=' method is not supported by ImageMagick 6.2.4): /usr/local/lib/ruby/gems/1.8/gems/rmagick-1.15.17/lib/RMagick.rb:1691:in `transparent_color=' I'm using RMagick version 2.12.1 on the development machine, but I'm not exactly certain how to discover the version of ImageMagick that it's running, so I'm not sure if this is a case of my local code being behind or ahead. I'm hoping behind, because perhaps then there'll be a replacement for this call. Does anyone know what the fix is here? What's required to generate a transparent background, if not the call I'm using? I can't find this in the documentation: in fact, it was on a third-party site that I found mention of this capability.

    Read the article

  • Replacing tags inside the parent tag using DOM PHP

    - by user585303
    Here is what I got: <div id="list"> <ol> <li>Ordered list 1</li> <li>Ordered list 2</li> <ul><li>Unordered list inside ol ul</li></ul> <ol><li>Ordered list inside ol ol</li></ol> <ol> <ul> <li>Unordered list</li> <ol><li>Ordered list inside ul</li></ol> <ul> <ol> <li>Ordered list 1</li> <ol><li>Ordered list inside ol ol</li></ol> <ol> </div> I need somehow replace LI tags only inside div id="list" - OL tags I need so that it replaces only LI tags only within the first OL tags and not UL or the once inside OL - OL tags I tried using preg_replace_callback but it only replaces all LI tags inside id="list" and from what i figured it will be over my head to limit replacement only with first ol tags and not the rest, so I been suggested to try out PHP DOM since it should be as easy as div id="list" - OL I would appreciate if someone got me started with the code, maybe with something as replacing all LI tags with in the first OL tag within the whole content.

    Read the article

  • Questions regarding detouring by modifying the virtual table

    - by Elliott Darfink
    I've been practicing detours using the same approach as Microsoft Detours (replace the first five bytes with a jmp and an address). More recently I've been reading about detouring by modifying the virtual table. I would appreciate if someone could shed some light on the subject by mentioning a few pros and cons with this method compared to the one previously mentioned! I'd also like to ask about patched vtables and objects on the stack. Consider the following situation: // Class definition struct Foo { virtual void Call(void) { std::cout << "FooCall\n"; } }; // If it's GCC, 'this' is passed as the first parameter void MyCall(Foo * object) { std::cout << "MyCall\n"; } // In some function Foo * foo = new Foo; // Allocated on the heap Foo foo2; // Created on the stack // Arguments: void ** vtable, uint offset, void * replacement PatchVTable(*reinterpret_cast<void***>(foo), 0, MyCall); // Call the methods foo->Call(); // Outputs: 'MyCall' foo2.Call(); // Outputs: 'FooCall' In this case foo->Call() would end up calling MyCall(Foo * object) whilst foo2.Call() call the original function (i.e Foo::Call(void) method). This is because the compiler will try to decide any virtual calls during compile time if possible (correct me if I'm wrong). Does that mean it does not matter if you patch the virtual table or not, as long as you use objects on the stack (not heap allocated)?

    Read the article

  • Looking for an email template engine for end-users ...

    - by RizwanK
    We have a number of customers that we have to send monthly invoices too. Right now, I'm managing a codebase that does SQL queries against our customer database and billing database and places that data into emails - and sends it. I grow weary of maintaining this every time we want to include a new promotion or change our customer service phone numbers. So, I'm looking for a replacement to move more of this into the hands of those requesting the changes. In my ideal world, I need : A WYSIWYG (man, does anyone even say that anymore?) email editor that generates templates based upon the output from a Database Query. The ability to drag and drop various fields from the database query into the email template. Display of sample email results with the database query. Web application, preferably not requiring IIS. Involve as little code as possible for the end-user, but allow basic functionality (i.e. arrays/for loops) Either comes with it's own email delivery engine, or writes output in a way that I can easily write a Python script to deliver the email. Support for generic Database Connectors. (I need MSSQL and MySQL) F/OSS So ... can anyone suggest a project like this, or some tools that'd be useful for rolling my own? (My current alternative idea is using something like ERB or Tenjin, having them write the code, but not having live-preview for the editor would suck...)

    Read the article

  • regexp target last main li in list

    - by veilig
    I need to target the starting tag of the last top level LI in a list that may or may-not contain sublists in various positions - without using CSS or Javascript. Is there a simple/elegant regexp that can help with this? I'm no guru w/ them, but it appears the need for greedy/non-greedy selectors when I'm selecting all the middle text (.*) / (.+) changes as nested lists are added and moved around in the list - and this is throwing me off. $pattern = '/^(<ul>.*)<li>(.+<\/li><\/ul>)$/'; $replacement = '$1<li id="lastLi">$3'; Perhaps there is an easier approach?? converting to XML to target the LI and then convert back? ie: Single Element <ul> <li>TARGET</li> </ul> Multiple Elements <ul> <li>foo</li> <li>TARGET</li> </ul> Nested Lists before end <ul> <li> foo <ul> <li>bar</li> </ul> <li> <li>TARGET</li> </ul> Nested List at end <ul> <li>foo</li> <li> TARGET <ul> <li>bar</li> </ul> </li> </ul>

    Read the article

  • Robotlegs: Warning: Injector already has a rule for type

    - by MikeW
    I have a bunch of warning messages like this appear when using Robotlegs/Signals. Everytime this command class executes, which is every 2-3 seconds ..this message displays below If you have overwritten this mapping intentionally you can use "injector.unmap()" prior to your replacement mapping in order to avoid seeing this message. Warning: Injector already has a rule for type "mx.messaging.messages::IMessage", named "". The command functions fine otherwise but I think I'm doing something wrong anyhow. public class MessageReceivedCommand extends SignalCommand { [Inject] public var message:IMessage; ...etc.. do something with message.. } the application context doesnt map IMessage to this command, as I only see an option to mapSignalClass , besides the payload is received fine. Wonder if anyone knows how I might either fix or suppress this message. I've tried calling this as the warning suggests injector.unmap(IMessage, "") but I receive an error - no mapping found for ::IMessage named "". Thanks Edit: A bit more info about the error Here is the signal that I dispatch to the command public class GameMessageSignal extends Signal { public function GameMessageSignal() { super(IMessage); } } which is dispatched from a IPushDataService class gameMessage.dispatch(message.message); and the implementation is wired up in the app context via injector.mapClass(IPushDataService, PushDataService); along with the signal signalCommandMap.mapSignalClass(GameMessageSignal, MessageReceivedCommand); Edit #2: Probably good to point out also I inject an instance of GameMessageSignal into IPushDataService public class PushDataService extends BaseDataService implements IPushDataService { [Inject] public var gameMessage:GameMessageSignal; //then private function processMessage(message:MessageEvent):void { gameMessage.dispatch(message.message); } } Edit:3 The mappings i set up in the SignalContext: injector.mapSingleton(IPushDataService); injector.mapClass(IPushDataService, PushDataService);

    Read the article

  • User will input some filter criteria -- how can I turn it into a regular expression for String.match

    - by envinyater
    I have a program where the user will enter a string such as PropertyA = "abc_*" and I need to have the asterisk match any character. In my code, I'm grabbing the property value and replacing PropertyA with the actual value. For instance, it could be abc_123. I also pull out the equality symbol into a variable. It should be able to cover this type of criteria PropertyB = 'cba' PropertyC != '*-this' valueFromHeader is the lefthand side and value is the righthand side. if (equality.equals("=")) { result = valueFromHeader.matches(value); } else if (equality.equals("!=")) { result = !valueFromHeader.matches(value); } EDIT: The existing code had this type of replacement for regular expressions final String ESC = "\\$1"; final String NON_ALPHA = "([^A-Za-z0-9@])"; final String WILD = "*"; final String WILD_RE_TEMP = "@"; final String WILD_RE = ".*"; value = value.replace(WILD, WILD_RE_TEMP); value = value.replaceAll(NON_ALPHA,ESC); value = value.replace(WILD_RE_TEMP, WILD_RE); It doesn't like the underscore here... abcSite_123 != abcSite_123 (evaluates to true) abcSite_123$1.matches("abcSite$1123") It doesn't like the underscore...

    Read the article

  • StreamReader not working as expected

    - by Jon Preece
    Hi, I have written a simple utility that loops through all C# files in my project and updates the copyright text at the top. For example, a file may look like this; //Copyright My Company, © 2009-2010 The program should update the text to look like this; //Copyright My Company, © 2009-2010 However, the code I have written results in this; //Copyright My Company, � 2009-2011 Here is the code I am using; public bool ModifyFile(string filePath, List<string> targetText, string replacementText) { if (!File.Exists(filePath)) return false; if (targetText == null || targetText.Count == 0) return false; if (string.IsNullOrEmpty(replacementText)) return false; string modifiedFileContent = string.Empty; bool hasContentChanged = false; //Read in the file content using (StreamReader reader = File.OpenText(filePath)) { string file = reader.ReadToEnd(); //Replace any target text with the replacement text foreach (string text in targetText) modifiedFileContent = file.Replace(text, replacementText); if (!file.Equals(modifiedFileContent)) hasContentChanged = true; } //If we haven't modified the file, dont bother saving it if (!hasContentChanged) return false; //Write the modifications back to the file using (StreamWriter writer = new StreamWriter(filePath)) { writer.Write(modifiedFileContent); } return true; } Any help/suggestions are appreciated. Thanks!

    Read the article

  • Execute JavaScript from within a C# assembly

    - by ScottKoon
    I'd like to execute JavaScript code from within a C# assembly and have the results of the JavaScript code returned to the calling C# code. It's easier to define things that I'm not trying to do: I'm not trying to call a JavaScript function on a web page from my code behind. I'm not trying to load a WebBrowser control. I don't want to have the JavaScript perform an AJAX call to a server. What I want to do is write unit tests in JavaScript and have then unit tests output JSON, even plain text would be fine. Then I want to have a generic C# class/executible that can load the file containing the JS, run the JS unit tests, scrap/load the results, and return a pass/fail with details during a post-build task. I think it's possible using the old ActiveX ScriptControl, but it seems like there ought to be a .NET way to do this without using SilverLight, the DLR, or anything else that hasn't shipped yet. Anyone have any ideas? update: From Brad Abrams blog namespace Microsoft.JScript.Vsa { [Obsolete("There is no replacement for this feature. Please see the ICodeCompiler documentation for additional help. http://go.microsoft.com/fwlink/?linkid=14202")] Clarification: We have unit tests for our JavaScript functions that are written in JavaScript using the JSUnit framework. Right now during our build process, we have to manually load a web page and click a button to ensure that all of the JavaScript unit tests pass. I'd like to be able to execute the tests during the post-build process when our automated C# unit tests are run and report the success/failure alongside of out C# unit tests and use them as an indicator as to whether or not the build is broken.

    Read the article

  • Regex Replacing only whole matches

    - by Leen Balsters
    I am trying to replace a bunch of strings in files. The strings are stored in a datatable along with the new string value. string contents = File.ReadAllText(file); foreach (DataRow dr in FolderRenames.Rows) { contents = Regex.Replace(contents, dr["find"].ToString(), dr["replace"].ToString()); File.SetAttributes(file, FileAttributes.Normal); File.WriteAllText(file, contents); } The strings look like this _-uUa, -_uU, _-Ha etc. The problem that I am having is when for example this string "_uU" will also overwrite "_-uUa" so the replacement would look like "newvaluea" Is there a way to tell regex to look at the next character after the found string and make sure it is not an alphanumeric character? I hope it is clear what I am trying to do here. Here is some sample data: private function _-0iX(arg1:flash.events.Event):void { if (arg1.type == flash.events.Event.RESIZE) { if (this._-2GU) { this._-yu(this._-2GU); } } return; } The next characters could be ;, (, ), dot, comma, space, :, etc.

    Read the article

  • IE textarea wrap bug?

    - by user2227033
    It seems that IE starting from IE7 to IE10 wraps text in the textarea control incorrectly when using \n (or \r\n - doesn't matter - results are the same). Is this a bug in IE or they treat the html standard differently than other browsers - who is right? I have defined: <textarea id="TextArea1" runat="server" style="width: 190px; height: 390px; white-space: normal; word-wrap: normal; overflow: scroll" ></textarea> When I try to add long string like "VeryLongStringEndingWithNewLine\n" by using JavaScript code (obj.value += text;) the text is shown in one line with scroll (this is ok) but added with an additional empty line (\r\n) - why? When I try to add short string like "Short\n" multiple times, again via JavaScript code the text is on the same line (should be on the separate lines because normal wrapping should be applied). Moreover when I do postback then all \r\n's are replaced with spaces (why?) and then text parsed correctly (assuming if I used spaces instead of crlf normal wraping with space only wraps when does not fit in the area). When using FF or Chrome same control behaves correctly - long lines are shown without an additional empty next line, short lines are on the different lines, no replacement with spaces when doing postback. I know I could probably use other options or white space characters, but I feel that above is not correct about IE. Any comments? Mindaugas

    Read the article

  • How to replace auto-implemented c# get body at runtime or compile time?

    - by qstarin
    I've been trying to figure this out all night, but I guess my knowledge of the .Net Framework just isn't that deep and the problem doesn't exactly Google well, but if I can get a nod in the right direction I'm sure I can implement it, one way or another. I'd like to be able to declare a property decorated with a custom attribute as such: public MyClass { [ReplaceWithExpressionFrom(typeof(SomeOtherClass))] public virtual bool MyProperty { get; } } public SomeOtherClass : IExpressionHolder<MyClass, bool> { ... } public interface IExpressionHolder<TArg, TResult> { Expression<Func<TArg, TResult>> Expression { get; } } And then somehow - this is the part I'm having trouble figuring - replace the automatically generated implementation of that getter with a piece of custom code, something like: Type expressionHolderType = LookupAttributeCtorArgTypeInDeclarationOfPropertyWereReplacing(); return ReplaceWithExpressionFromAttribute.GetCompiledExpressionFrom(expressionHolderType)(this); The main thing I'm not sure how to do is replace the automatic implementation of the get. The first thing that came to mind was PostSharp, but that's a more complicated dependency than I care for. I'd much prefer a way to code it without using post-processing attached to the build (I think that's the jist of how PostSharp sinks its hooks in anyway). The other part of this I'm not so sure about is how to retrieve the type parameter passed to the particular instantiation of the ReplaceWithExpressionFrom attribute (where it decorates the property whose body I want to replace; in other words, how do I get typeof(SomeOtherClass) where I'm coding the get body replacement). I plan to cache compiled expressions from concrete instances of IExpressionHolder, as I don't want to do that every time the property gets retrieved. I figure this has just got to be possible. At the very least I figure I should be able to search an assembly for any method decorated with the attribute and somehow proxy the class or just replace the IL or .. something? And I'd like to make the integration as smooth as possible, so if this can be done without explicitly calling a registration or initialization method somewhere that'd be super great. Thanks!

    Read the article

  • Determining presence of prototype with correct return type

    - by R..
    Here's a random problem in C black magic I just came up with: Write a function that returns 1 if malloc has been prototyped to return a pointer type and 0 if malloc has a return type of int (either implicitly or due to wrong prototype), without invoking any implementation-defined or undefined behavior. I believe it's solvable, but I haven't worked out the solution. Note that calling the function cannot be necessary and in fact is not possible since calling a function with the incorrect prototype is undefined behavior. I have some ideas for ingredients but I think it makes for a better puzzle (and possibly more diverse ideas) if I leave them out for now. I don't need the solution for any immediate use, but it could be handy in configure scripts and such. Update: A better example of the usefulness (with strdup instead of malloc): #undef strdup #define strdup(x) (strdup_has_proto ? strdup((x)) : my_strdup((x))) i.e. being able to implement X_has_proto as an expression at the source level could be a portable way to use functions which a system might or might not have, and fall back on a local replacement, without needing any separate configure step.

    Read the article

  • Using placeholders/variables in a sed command

    - by jesse_galley
    I want to store a specific part of a matched result as a variable to be used for replacement later. I would like to keep this in a one liner instead of finding the variable I need before hand. when configuring apache, and use mod_rewrite, you can specificy specific parts of patterns to be used as variables,like this: RewriteRule ^www.example.com/page/(.*)$ http://www.example.com/page.php?page=$1 [R=301,L] the part of the pattern match that's contained inside the parenthesis is stored as $1 for use later. So if the url was www.example.com/page/home, it would be replaced with www.example.com/page.php?page=home. So the "home" part of the match was saved in $1 because it was the part of the pattern inside the parenthesis. I want something like this functionality with a sed command, I need to automatically replace many strings in a SQL dump file, to add drop table if exist commands before each create table, but I need to know the table name to do this, so if the dump file contains something like: ... CREATE TABLE `orders` ... I need to run something like: cat dump.sql | sed "s/CREATE TABLE `(.*)`/DROP TABLE IF EXISTS $1\N CREATE TABLE `$1`/g" to get the result of: ... DROP TABLE IF EXISTS `orders` CREATE TABLE `orders` ... I'm using the mod_rewrite syntax in the sed command as a logical example of what I'm trying to do. Any suggestions?

    Read the article

  • ReplaceAll not working as expected

    - by Tim Kemp
    Still early days with Mathematica so please forgive what is probably a very obvious question. I am trying to generate some parametric plots. I have: ParametricPlot[{ (a + b) Cos[t] - h Cos[(a + b)/b t], (a + b) Sin[t] - h Sin[(a + b)/b t]}, {t, 0, 2 \[Pi]}, PlotRange -> All] /. {a -> 2, b -> 1, h -> 1} No joy: the replacement rules are not applied and a, b and h remain undefined. If I instead do: Hold@ParametricPlot[{ (a + b) Cos[t] - h Cos[(a + b)/b t], (a + b) Sin[t] - h Sin[(a + b)/b t]}, {t, 0, 2 \[Pi]}, PlotRange -> All] /. {a -> 2, b -> 1, h -> 1} it looks like the rules ARE working, as confirmed by the output: Hold[ParametricPlot[{(2 + 1) Cos[t] - 1 Cos[(2 + 1) t], (2 + 1) Sin[t] - 1 Sin[(2 + 1) t]}, {t, 0, 2 \[Pi]}, PlotRange -> All]] Which is what I'd expect. Take the Hold off, though, and the ParametricPlot doesn't work. There's nothing wrong with the equations or the ParametricPlot itself, though, because I tried setting values for a, b and h in a separate expression (a=2; b=1; h=1) and I get my pretty double cardoid out as expected. So, what am I doing wrong with ReplaceAll and why are the transformation rules not working? This is another fundamentally important aspect of MMA that my OOP-ruined brain isn't understanding. I tried reading up on ReplaceAll and ParametricPlot and the closest clue I found was that "ParametricPlot has attribute HoldAll and evaluates f only after assigning specific numerical values to variables" which didn't help much or I wouldn't be here. Thanks.

    Read the article

  • Coding the R-ight way - avoiding the for loop

    - by mropa
    I am going through one of my .R files and by cleaning it up a little bit I am trying to get more familiar with writing the code the r-ight way. As a beginner, one of my favorite starting points is to get rid of the for() loops and try to transform the expression into a functional programming form. So here is the scenario: I am assembling a bunch of data.frames into a list for later usage. dataList <- list (dataA, dataB, dataC, dataD, dataE ) Now I like to take a look at each data.frame's column names and substitute certain character strings. Eg I like to substitute each "foo" and "bar" with "baz". At the moment I am getting the job done with a for() loop which looks a bit awkward. colnames(dataList[[1]]) [1] "foo" "code" "lp15" "bar" "lh15" colnames(dataList[[2]]) [1] "a" "code" "lp50" "ls50" "foo" matchVec <- c("foo", "bar") for (i in seq(dataList)) { for (j in seq(matchVec)) { colnames (dataList[[i]])[grep(pattern=matchVec[j], x=colnames (dataList[[i]]))] <- c("baz") } } Since I am working here with a list I thought about the lapply function. My attempts handling the job with the lapply function all seem to look alright but only at first sight. If I write f <- function(i, xList) { gsub(pattern=c("foo"), replacement=c("baz"), x=colnames(xList[[i]])) } lapply(seq(dataList), f, xList=dataList) the last line prints out almost what I am looking for. However, if i take another look at the actual names of the data.frames in dataList: lapply (dataList, colnames) I see that no changes have been made to the initial character strings. So how can I rewrite the for() loop and transform it into a functional programming form? And how do I substitute both strings, "foo" and "bar", in an efficient way? Since the gsub() function takes as its pattern argument only a character vector of length one.

    Read the article

  • Why extremely occasionally will one of bof/eof be true for a new non-empty recordset

    - by jjb
    set recordsetname = databasename.openrecordset(SQLString) if recordsetname.bof <> true and recordsetname.eof <> true then 'do something end if 2 questions : the above test can evaluate to false incorrectly but only extremely rarely (I've had one lurking in my code and it failed today, I believe for the first time in 5 years of daily use-that's how I found it). Why very occasionally will one of bof/eof be true for a non-empty recordset. It seems so rare that I wonder why it occurs at all. Is this a foolproof replacement: if recordsetname.bof <> true or recordsetname.eof <> true then Edit to add details of code : Customers have orders, each order begins with a BeginOrder item and end with an EndOrder item and in between are the items in the order. The SQL is: ' ids are autoincrement long integers ' SQLString = "select * from Orders where type = OrderBegin or type = OrderEnd" Dim OrderOpen as Boolean OrderOpen = False Set rs = db.Openrecordset(SQLString) If rs.bof <> True And rs.eof <> True Then myrec.movelast If rs.fields("type").value = BeginOrder Then OrderOpen = True End If End If If OrderOpen F False Then 'code here to add new BeginOrder Item to Orders table ' End If ShowOrderHistory 'displays the customer's Order history ' In this case which looks this this BeginOrder Item a Item b ... Item n EndOrder BeginOrder Item a Item b ... Item n EndOrder BeginOrder Item a item b ... Item m BeginOrder <----should not be there as previous order still open

    Read the article

  • Rewriting Live TCP/IP (Layer 4) Streams

    - by user213060
    I want to rewrite TCP/IP streams. Ettercap's etterfilter command lets you perform simple live replacements of TCP/IP data based on fixed strings or regexes. Example: if (ip.proto == TCP && tcp.dst == 80) { if (search(DATA.data, "gzip")) { replace("gzip", " "); msg("whited out gzip\n"); } } if (ip.proto == TCP && tcp.dst == 80) { if (search(DATA.data, "deflate")) { replace("deflate", " "); msg("whited out deflate\n"); } } http://ettercap.sourceforge.net/forum/viewtopic.php?t=2833 I would like to rewrite streams based on my own filter program instead of just simple string replacements. Anyone have an idea of how to do this? Is there anything other than Ettercap that can do live replacement like this, maybe as a plugin to a VPN software or something? The rewriting should occur at the transport layer (Layer 4) as it does in this example, instead of a lower layer packet-based approach. Thanks!

    Read the article

  • ORDERBY "human" alphabetical order using SQL string manipulation

    - by supertrue
    I have a table of posts with titles that are in "human" alphabetical order but not in computer alphabetical order. These are in two flavors, numerical and alphabetical: Numerical: Figure 1.9, Figure 1.10, Figure 1.11... Alphabetical: Figure 1A ... Figure 1Z ... Figure 1AA If I orderby title, the result is that 1.10-1.19 come between 1.1 and 1.2, and 1AA-1AZ come between 1A and 1B. But this is not what I want; I want "human" alphabetical order, in which 1.10 comes after 1.9 and 1AA comes after 1Z. I am wondering if there's still a way in SQL to get the order that I want using string manipulation (or something else I haven't thought of). I am not an expert in SQL, so I don't know if this is possible, but if there were a way to do conditional replacement, then it seems I could impose the order I want by doing this: delete the period (which can be done with replace, right?) if the remaining figure number is more than three characters, add a 0 (zero) after the first character. This would seem to give me the outcome I want: 1.9 would become 109, which comes before 110; 1Z would become 10Z, which comes before 1AA. But can it be done in SQL? If so, what would the syntax be? Note that I don't want to modify the data itself—just to output the results of the query in the order described. This is in the context of a Wordpress installation, but I think the question is more suitably an SQL question because various things (such as pagination) depend on the ordering happening at the MySQL query stage, rather than in PHP.

    Read the article

< Previous Page | 48 49 50 51 52 53 54 55 56 57 58 59  | Next Page >