Search Results

Search found 31491 results on 1260 pages for 'simple talk'.

Page 98/1260 | < Previous Page | 94 95 96 97 98 99 100 101 102 103 104 105  | Next Page >

  • C++: parsing with simple regular expression or shoud I use sscanf?

    - by Helltone
    I need to parse a string like func1(arg1, arg2); func2(arg3, arg4);. It's not a very complex parsing problem, so I would prefer to avoid resorting to flex/bison or similar utilities. My first approch was to try to use POSIX C regcomp/regexec or Boost implementation of C++ std::regex. I wrote the following regular expression, which does not work (I'll explain why further on). "^" "[ ;\t\n]*" "(" // (1) identifier "[a-zA-Z_][a-zA-Z0-9_]*" ")" "[ \t\n]*" "(" // (2) non-marking "\[" "(" // (3) non-marking "[ \t]*" "(" // (4..n-1) argument "[a-zA-Z0-9_]+" ")" "[ \t\n]*" "," ")*" "[ \t\n]*" "(" // (n) last argument "[a-zA-Z0-9_]+" ")" "]" ")?" "[ \t\n]*" ";" Note that the group 1 captures the identifier and groups 4..n-1 are intended to capture arguments except the last, which is captured by group n. When I apply this regex to, say func(arg1, arg2, arg3) the result I get is an array {func, arg2, arg3}. This is wrong because arg1 is not in it! The problem is that in the standard regex libraries, submarkings only capture the last match. In other words, if you have for instance the regex "((a*|b*))*" applied on "babb", the results of the inner match will be bb and all previous captures will have been forgotten. Another thing that annoys me here is that in case of error there is no way to know which character was not recognized as these functions provide very little information about the state of the parser when the input is rejected. So I don't know if I'm missing something here... In this case should I use sscanf or similar instead? Note that I prefer to use C/C++ standard libraries (and maybe boost).

    Read the article

  • Number of simple mutations to change one string to another?

    - by mstksg
    Hi; I'm sure you've all heard of the "Word game", where you try to change one word to another by changing one letter at a time, and only going through valid English words. I'm trying to implement an A* Algorithm to solve it (just to flesh out my understanding of A*) and one of the things that is needed is a minimum-distance heuristic. That is, the minimum number of one of these three mutations that can turn an arbitrary string a into another string b: 1) Change one letter for another 2) Add one letter at a spot before or after any letter 3) Remove any letter Examples aabca => abaca: aabca abca abaca = 2 abcdebf => bgabf: abcdebf bcdebf bcdbf bgdbf bgabf = 4 I've tried many algorithms out; I can't seem to find one that gives the actual answer every time. In fact, sometimes I'm not sure if even my human reasoning is finding the best answer. Does anyone know any algorithm for such purpose? Or maybe can help me find one? Thanks.

    Read the article

  • Hopefully simple topic to spark some good opinions, Question is MySQL or SQL Server???

    - by magellings
    I'm beginning development of a website and a high priority is for it to be extremely optimized, quick responses, etc. There will ultimately end up being large amounts of rows in the main tables (millions), so scalability is also important. It will need to use a database on the back-end for data storage and my web hosting service supports either MySQL or Sql Server. This website will be developed with .NET ASP.NET MVC with NHibernate (hopefully it can run in medium trust mode, as that is a requirement of my web hosting and reflection requirements of NHibernate may be problematic, maybe someone has a comment on this too). I'd also prefer to use the database that will require the least attention in regards to management. I don't want to have to be a DBA here. :) I wanted to through this topic out to the public to see what the community thinks? So MySQL or Sql Server, generally, which one would be better to use?

    Read the article

  • Simple XNA 2D demo: why is my F# version slower than C# version?

    - by Den
    When running this XNA application it should display a rotated rectangle that moves from top-left corner to bottom-right corner. It looks like my F# version is noticeably much slower. It seems that the Draw method skips a lot of frames. I am using VS 2012 RC, XNA 4.0, .NET 4.5, F# 3.0. I am trying to make it as functional as possible. What could be the reason for poor performance? C#: class Program { static void Main(string[] args) { using (var game = new FlockGame()) { game.Run(); } } } public class FlockGame : Game { private GraphicsDeviceManager graphics; private DrawingManager drawingManager; private Vector2 position = Vector2.Zero; public FlockGame() { graphics = new GraphicsDeviceManager(this); } protected override void Initialize() { drawingManager = new DrawingManager(graphics.GraphicsDevice); this.IsFixedTimeStep = false; } protected override void Update(GameTime gameTime) { position = new Vector2(position.X + 50.1f * (float)gameTime.ElapsedGameTime.TotalSeconds, position.Y + 50.1f * (float)gameTime.ElapsedGameTime.TotalSeconds); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { //this.GraphicsDevice.Clear(Color.Lavender) drawingManager.DrawRectangle(position, new Vector2(100.0f, 100.0f), 0.7845f, Color.Red); base.Draw(gameTime); } } public class DrawingManager { private GraphicsDevice GraphicsDevice; private Effect Effect; public DrawingManager(GraphicsDevice graphicsDevice) { GraphicsDevice = graphicsDevice; this.Effect = new BasicEffect(this.GraphicsDevice) { VertexColorEnabled = true, Projection = Matrix.CreateOrthographicOffCenter(0.0f, this.GraphicsDevice.Viewport.Width, this.GraphicsDevice.Viewport.Height, 0.0f, 0.0f, 1.0f) }; } private VertexPositionColor[] GetRectangleVertices (Vector2 center, Vector2 size, float radians, Color color) { var halfSize = size/2.0f; var topLeft = -halfSize; var bottomRight = halfSize; var topRight = new Vector2(bottomRight.X, topLeft.Y); var bottomLeft = new Vector2(topLeft.X, bottomRight.Y); topLeft = Vector2.Transform(topLeft, Matrix.CreateRotationZ(radians)) + center; topRight = Vector2.Transform(topRight, Matrix.CreateRotationZ(radians)) + center; bottomRight = Vector2.Transform(bottomRight, Matrix.CreateRotationZ(radians)) + center; bottomLeft = Vector2.Transform(bottomLeft, Matrix.CreateRotationZ(radians)) + center; return new VertexPositionColor[] { new VertexPositionColor(new Vector3(topLeft, 0.0f), color), new VertexPositionColor(new Vector3(topRight, 0.0f), color), new VertexPositionColor(new Vector3(topRight, 0.0f), color), new VertexPositionColor(new Vector3(bottomRight, 0.0f), color), new VertexPositionColor(new Vector3(bottomRight, 0.0f), color), new VertexPositionColor(new Vector3(bottomLeft, 0.0f), color), new VertexPositionColor(new Vector3(bottomLeft, 0.0f), color), new VertexPositionColor(new Vector3(topLeft, 0.0f), color) }; } public void DrawRectangle(Vector2 center, Vector2 size, float radians, Color color) { var vertices = GetRectangleVertices(center, size, radians, color); foreach (var pass in this.Effect.CurrentTechnique.Passes) { pass.Apply(); this.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, vertices.Length/2); } } } F#: namespace Flocking module FlockingProgram = open System open Flocking [<STAThread>] [<EntryPoint>] let Main _ = use g = new FlockGame() g.Run() 0 //------------------------------------------------------------------------------ namespace Flocking open System open System.Diagnostics open Microsoft.Xna.Framework open Microsoft.Xna.Framework.Graphics open Microsoft.Xna.Framework.Input type public FlockGame() as this = inherit Game() let mutable graphics = new GraphicsDeviceManager(this) let mutable drawingManager = null let mutable position = Vector2.Zero override Game.LoadContent() = drawingManager <- new Rendering.DrawingManager(graphics.GraphicsDevice) this.IsFixedTimeStep <- false override Game.Update gameTime = position <- Vector2(position.X + 50.1f * float32 gameTime.ElapsedGameTime.TotalSeconds, position.Y + 50.1f * float32 gameTime.ElapsedGameTime.TotalSeconds) base.Update gameTime override Game.Draw gameTime = //this.GraphicsDevice.Clear(Color.Lavender) Rendering.DrawRectangle(drawingManager, position, Vector2(100.0f, 100.0f), 0.7845f, Color.Red) base.Draw gameTime //------------------------------------------------------------------------------ namespace Flocking open System open System.Collections.Generic open Microsoft.Xna.Framework open Microsoft.Xna.Framework.Graphics open Microsoft.Xna.Framework.Input module Rendering = [<AllowNullLiteral>] type DrawingManager (graphicsDevice : GraphicsDevice) = member this.GraphicsDevice = graphicsDevice member this.Effect = new BasicEffect(this.GraphicsDevice, VertexColorEnabled = true, Projection = Matrix.CreateOrthographicOffCenter(0.0f, float32 this.GraphicsDevice.Viewport.Width, float32 this.GraphicsDevice.Viewport.Height, 0.0f, 0.0f, 1.0f)) let private GetRectangleVertices (center:Vector2, size:Vector2, radians:float32, color:Color) = let halfSize = size / 2.0f let mutable topLeft = -halfSize let mutable bottomRight = halfSize let mutable topRight = new Vector2(bottomRight.X, topLeft.Y) let mutable bottomLeft = new Vector2(topLeft.X, bottomRight.Y) topLeft <- Vector2.Transform(topLeft, Matrix.CreateRotationZ(radians)) + center topRight <- Vector2.Transform(topRight, Matrix.CreateRotationZ(radians)) + center bottomRight <- Vector2.Transform(bottomRight, Matrix.CreateRotationZ(radians)) + center bottomLeft <- Vector2.Transform(bottomLeft, Matrix.CreateRotationZ(radians)) + center [| new VertexPositionColor(new Vector3(topLeft, 0.0f), color) new VertexPositionColor(new Vector3(topRight, 0.0f), color) new VertexPositionColor(new Vector3(topRight, 0.0f), color) new VertexPositionColor(new Vector3(bottomRight, 0.0f), color) new VertexPositionColor(new Vector3(bottomRight, 0.0f), color) new VertexPositionColor(new Vector3(bottomLeft, 0.0f), color) new VertexPositionColor(new Vector3(bottomLeft, 0.0f), color) new VertexPositionColor(new Vector3(topLeft, 0.0f), color) |] let DrawRectangle (drawingManager:DrawingManager, center:Vector2, size:Vector2, radians:float32, color:Color) = let vertices = GetRectangleVertices(center, size, radians, color) for pass in drawingManager.Effect.CurrentTechnique.Passes do pass.Apply() drawingManager.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, vertices.Length/2)

    Read the article

  • Why is my simple python gtk+cairo program running so slowly/stutteringly?

    - by synapz
    My program draws circles moving on the window. I think I must be missing some basic gtk/cairo concept because it seems to be running too slowly/stutteringly for what I am doing. Any ideas? Thanks for any help! #!/usr/bin/python import gtk import gtk.gdk as gdk import math import random import gobject # The number of circles and the window size. num = 128 size = 512 # Initialize circle coordinates and velocities. x = [] y = [] xv = [] yv = [] for i in range(num): x.append(random.randint(0, size)) y.append(random.randint(0, size)) xv.append(random.randint(-4, 4)) yv.append(random.randint(-4, 4)) # Draw the circles and update their positions. def expose(*args): cr = darea.window.cairo_create() cr.set_line_width(4) for i in range(num): cr.set_source_rgb(1, 0, 0) cr.arc(x[i], y[i], 8, 0, 2 * math.pi) cr.stroke_preserve() cr.set_source_rgb(1, 1, 1) cr.fill() x[i] += xv[i] y[i] += yv[i] if x[i] > size or x[i] < 0: xv[i] = -xv[i] if y[i] > size or y[i] < 0: yv[i] = -yv[i] # Self-evident? def timeout(): darea.queue_draw() return True # Initialize the window. window = gtk.Window() window.resize(size, size) window.connect("destroy", gtk.main_quit) darea = gtk.DrawingArea() darea.connect("expose-event", expose) window.add(darea) window.show_all() # Self-evident? gobject.idle_add(timeout) gtk.main()

    Read the article

  • Why does Java force user-agent through simple Socket IO?

    - by Zombies
    I am using nothing but raw Socket IO. There isn't one HttpURLConnection nor any http client libs in my project. When I run it through wireshark I see somethign very revealing: GET / HTTP/1.1 User-Agent: Java/1.6.0_15 Host: www.google.com Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Here is the crazy part, I never put ANY of that in my original request. My original request was: "GET http://www.google.com/ HTTP/1.1\r\n" + "Host: www.google.com\r\n" + "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100214 Ubuntu/9.10 (karmic) Firefox/3.5.8\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" + "Accept-Language: en-us,en;q=0.5\r\n" + "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" + "Keep-Alive: 300\r\n" + "\r\n"; I am using the default Sun JVM.

    Read the article

  • How can I bind a simple Javascript array to an MVC3 controller action method?

    - by Sergio Tapia
    Here is the javascript code I use to create the array and send it on it's way: <script type="text/javascript" language="javascript"> $(document).ready(function () { $("#update-cart-btn").click(function() { var items = []; $(".item").each(function () { var productKey = $(this).find("input[name='item.ProductId']").val(); var productQuantity = $(this).find("input[type='text']").val(); items[productKey] = productQuantity; }); $.ajax({ type: "POST", url: "@Url.Action("UpdateCart", "Cart")", data: items, success: function () { alert("Successfully updated your cart!"); } }); }); }); </script> The items object is properly constructed with the values I need. What data type must my object be on the backend of my controller? I tried this but the variable remains null and is not bound. [Authorize] [HttpPost] public ActionResult UpdateCart(object[] items) // items remains null. { // Some magic here. return RedirectToAction("Index"); }

    Read the article

  • Ruby on Rails: Simple way to select all records of a nested model?

    - by Josh Pinter
    Just curious, I spent an embarrassing amount of time trying to get an array of all the records in a nested model. I just want to make sure there is not a better way. Here is the setup: I have three models that are nested under each other (Facilities Tags Inspections), producing code like this for routes.rb: map.resources :facilities do |facilities| facilities.resources :tags, :has_many => :inspections end I wanted to get all of the inspections for a facility and here is what my code ended up being: def facility_inspections @facility = Facility.find(params[:facility_id]) @inspections = [] @facility.tags.each do |tag| tag.inspections.each do |inspection| @inspections << inspection end end end It works but is this the best way to do this - I think it's cumbersome. Thanks in advance. Josh

    Read the article

  • Why's a simple change to rt.jar causing the Java Runtime Environment to crash silently?

    - by Tom
    This is what I'm doing: extract contents of my JRE's rt.jar extract src.zip of my JDK (same version) Now, if I copy Runtime.java from the extracted src folder and compile it using javac.exe without any modifications and then put it in the extracted rt folder to finally put everything back in a jar file using jar.exe, everything works as expected. The JRE runs fine. However, if I make the slightest change to Runtime.java and compile it and put it in rt.jar, the JRE crashes whenever I attempt to start it. This is an example of a slight change that causes the silent crash: /** Don't let anyone else instantiate this class */ private Runtime() { System.out.println("This is a test."); } Instead of: /** Don't let anyone else instantiate this class */ private Runtime() {} Could anyone tell me why this is causing my JRE to crash? Thanks in advance.

    Read the article

  • PostgreSQL: Why does this simple query not use the index?

    - by David
    I have a table t with a column c, which is an int and has a btree index on it. Why does the following query not utilize this index? explain select c from t group by c; The result I get is: HashAggregate (cost=1005817.55..1005817.71 rows=16 width=4) -> Seq Scan on t (cost=0.00..946059.84 rows=23903084 width=4) My understanding of indexes is limited, but I thought such queries were the purpose of indexes.

    Read the article

  • need to use mootools for simple script instead of jquery... how?

    - by liz
    i have a script in jquery (that grabs a value from a select field and transfers it to an input field) that i need to do in mootools...i love jquery... mootools i dont know... not having much luck... here is the code: - Select an Article -Acetaia LeonardiEsperidiaFrescobaldi LaudemioPrimitiviziaPrincipato LucedioRustichella d'Abruzzo --

    Read the article

  • Is there simple way to play an rtp video/audio stream in WPF?

    - by Robin
    I need to create a WPF control that will play an rtp stream with the requirement that the latency needs to be as low as possible. I've looked at the following two projects: http://vlcdotnet.codeplex.com/ http://wpfmediakit.codeplex.com/ As far as I know, I can't use VLC because we're shipping a commercial application with a more restrictive license than GPL (i.e. we can't ship our source). Wpf media kit is nice, but I can't seem to find a good/free rtp directshow source filter and I wanted to ask if there is a simpler solution out there that I'm missing before I jump into writing my own. Any ideas?

    Read the article

  • How should I parse this simple text file in Java?

    - by Winston
    I have a text file that looks like this: grn129 agri- ac-214 ahss hud114 ahss lov1150 ahss lov1160 ahss lov1170 ahss lov1210 ahss What is the best way to parse this file using Java if I want to create a HashMap with the first column as the key and the second column as the value. Should I use the Scanner class? Try to read in the whole file as a string and split it? What is the best way?

    Read the article

  • Bypass OpenID. Please give us a simple login form.

    - by Florin
    Can I kindly ask that we're allowed to login without the OpenID nonsense? This system is so popular that stack-overflow is the only place that I use it. If it is the policy of stack-overflow to prevent people to login, they've succeeded. I am a passive reader. For some reasons, I really don't like the idea of having one Id for all sites. To me, this system is dead in the water. Unless used within organizations I will never use it. Of course, until the government decides to reign us all in. Will you give them a hand? Until then, can we simply have a login form as in 1995? Thank you for your consideration.

    Read the article

  • Spring 3 MVC - Does Anything Just Work? Very Simple Use Case Not Working

    - by jboyd
    index.jsp ... <h1> ${myobject} </h1> ... HomeController.java @RequestMapping(value = "/index") public ModelAndView indexPath() { System.out.println("going home"); return new ModelAndView("index", "myobject", "isastring"); } Output: going home The <h1> on index doesn't show anything, how is this even possible? I absolutely cannot get my index.jsp to show this bean, I've tried using a usebean, I've tried storing it on the session, and now I'm directly placing it in the model. Nothing works. Spring 3 has been like every other spring release, intensely frustrating.

    Read the article

  • How can I run a package created with Simple Build Tool?

    - by Lukasz Lew
    I run: $ echo 'object Hi { def main(args: Array[String]) { println("Hi!") } }' > hw.scala $ sbt > warn Set log level to warn > run Hi! > package $ java -jar target/scala_2.7.7/test_2.7.7-1.0.jar Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) at java.net.URLClassLoader.defineClass(URLClassLoader.java:260) Why can't I run this jar package this way?

    Read the article

  • can a python script know that another instance of the same script is running... and then talk to it?

    - by Justin Grant
    I'd like to prevent multiple instances of the same long-running python command-line script from running at the same time, and I'd like the new instance to be able to send data to the original insance before the new instance commits suicide. How can I do this in a cross-platform way? Specifically, I'd like to enable the following behavior: "foo.py" is launched from the command line, and it will stay running for a long time-- days or weeks until the machine is rebooted or the parent process kills it. every few minutes the same script is launched again, but with different command-line parameters when launched, the script should see if any other instances are running. if other instances are running, then instance #2 should send its command-line parameters to instance #1, and then instance #2 should exit. instance #1, if it receives command-line parameters from another script, should spin up a new thread and (using the command-line parameters sent in the step above) start performing the work that instance #2 was going to perform. So I'm looking for two things: how can a python program know another instance of itself is running, and then how can one python command-line program communicate with another? Making this more complicated, the same script needs to run on both Windows and Linux, so ideally the solution would use only the Python standard library and not any OS-specific calls. Although if I need to have a Windows codepath and an *nix codepath (and a big if statement in my code to choose one or the other), that's OK if a "same code" solution isn't possible. I realize I could probably work out a file-based approach (e.g. instance #1 watches a directory for changes and each instance drops a file into that directory when it wants to do work) but I'm a little concerned about cleaning up those files after a non-graceful machine shutdown. I'd ideally be able to use an in-memory solution. But again I'm flexible, if a persistent-file-based approach is the only way to do it, I'm open to that option. More details: I'm trying to do this because our servers are using a monitoring tool which supports running python scripts to collect monitoring data (e.g. results of a database query or web service call) which the monitoring tool then indexes for later use. Some of these scripts are very expensive to start up but cheap to run after startup (e.g. making a DB connection vs. running a query). So we've chosen to keep them running in an infinite loop until the parent process kills them. This works great, but on larger servers 100 instances of the same script may be running, even if they're only gathering data every 20 minutes each. This wreaks havoc with RAM, DB connection limits, etc. We want to switch from 100 processes with 1 thread to one process with 100 threads, each executing the work that, previously, one script was doing. But changing how the scripts are invoked by the monitoring tool is not possible. We need to keep invocation the same (launch a process with different command-line parameters) but but change the scripts to recognize that another one is active, and have the "new" script send its work instructions (from the command line params) over to the "old" script.

    Read the article

  • Am I going the right way to make login system secure with this simple password salting?

    - by LoVeSmItH
    I have two fields in login table password salt And I have this little function to generate salt function random_salt($h_algo="sha512"){ $salt1=uniqid(rand(),TRUE); $salt2=date("YmdHis").microtime(true); if(function_exists('dechex')){ $salt2=dechex($salt2); } $salt3=$_SERVER['REMOTE_ADDR']; $salt=$salt1.$salt2.$salt3; if(function_exists('hash')){ $hash=(in_array($h_algo,hash_algos()))?$h_algo:"sha512"; $randomsalt=hash($hash,md5($salt)); //returns 128 character long hash if sha512 algorithm is used. }else{ $randomsalt=sha1(md5($salt)); //returns 40 characters long hash } return $randomsalt; } Now to create user password I have following $userinput=$_POST["password"] //don't bother about escaping, i have done it in my real project. $static_salt="THIS-3434-95456-IS-RANDOM-27883478274-SALT"; //some static hard to predict secret salt. $salt=random_salt(); //generates 128 character long hash. $password =sha1($salt.$userinput.$static_salt); $salt is saved in salt field of database and $password is saved in password field. My problem, In function random_salt(), I m having this FEELING that I'm just making things complicated while this may not generate secure salt as it should. Can someone throw me a light whether I m going in a right direction? P.S. I do have an idea about crypt functions and like such. Just want to know is my code okay? Thanks.

    Read the article

  • Get the "source network address" in Event ID 529 audit entries on Windows XP

    - by Make it useful Keep it simple
    In windows server 2003 when an Event 529 (logon failure) occures with a logon type of 10 (remote logon), the source network IP address is recorded in the event log. On a windows XP machine, this (and some other details) are omitted. If a bot is trying a brute force over RDP (some of my XP machines are (and need to be) exposed with a public IP address), i cannot see the originating IP address so i don't know what to block (with a script i run every few minutes). The DC does not log this detail either when the logon attempt is to the client xp machine and the DC is only asked to authenticate the credentials. Any help getting this detail in the log would be appreciated.

    Read the article

< Previous Page | 94 95 96 97 98 99 100 101 102 103 104 105  | Next Page >