Daily Archives

Articles indexed Saturday February 19 2011

Page 6/10 | < Previous Page | 2 3 4 5 6 7 8 9 10  | Next Page >

  • Finite state machine in C++

    - by Electro
    So, I've read a lot about using FSMs to do game state management, things like what and FSM is, and using a stack or set of states for building one. I've gone through all that. But I'm stuck at writing an actual, well-designed implementation of an FSM for that purpose. Specifically, how does one cleanly resolve the problem of transitioning between states, (how) should a state be able to use data from other states, and so on. Does anyone have any tips on designing and writing a implementation in C++, or better yet, code examples?

    Read the article

  • How to manage enemy movement and shoot in a shmup?

    - by whatever
    I'm wondering what is the best (or at least a good) way of managing enemies in a shoot-em-up. Basically, what I'd do would be a class that manages displaying and updating positions of all the enemies. But how to create good deplacements for enemies? A list of where-to-go points? gravitating around some fixed points (with ponderation, distance evaluation etc.)? Same question for the shoot patterns? Can you please put me on a track?

    Read the article

  • Atmospheric Scattering

    - by Lawrence Kok
    I'm trying to implement atmospheric scattering based on Sean O`Neil algorithm that was published in GPU Gems 2. But I have some trouble getting the shader to work. My latest attempts resulted in: http://img253.imageshack.us/g/scattering01.png/ I've downloaded sample code of O`Neil from: http://http.download.nvidia.com/developer/GPU_Gems_2/CD/Index.html. Made minor adjustments to the shader 'SkyFromAtmosphere' that would allow it to run in AMD RenderMonkey. In the images it is see-able a form of banding occurs, getting an blueish tone. However it is only applied to one half of the sphere, the other half is completely black. Also the banding appears to occur at Zenith instead of Horizon, and for a reason I managed to get pac-man shape. I would appreciate it if somebody could show me what I'm doing wrong. Vertex Shader: uniform mat4 matView; uniform vec4 view_position; uniform vec3 v3LightPos; const int nSamples = 3; const float fSamples = 3.0; const vec3 Wavelength = vec3(0.650,0.570,0.475); const vec3 v3InvWavelength = 1.0f / vec3( Wavelength.x * Wavelength.x * Wavelength.x * Wavelength.x, Wavelength.y * Wavelength.y * Wavelength.y * Wavelength.y, Wavelength.z * Wavelength.z * Wavelength.z * Wavelength.z); const float fInnerRadius = 10; const float fOuterRadius = fInnerRadius * 1.025; const float fInnerRadius2 = fInnerRadius * fInnerRadius; const float fOuterRadius2 = fOuterRadius * fOuterRadius; const float fScale = 1.0 / (fOuterRadius - fInnerRadius); const float fScaleDepth = 0.25; const float fScaleOverScaleDepth = fScale / fScaleDepth; const vec3 v3CameraPos = vec3(0.0, fInnerRadius * 1.015, 0.0); const float fCameraHeight = length(v3CameraPos); const float fCameraHeight2 = fCameraHeight * fCameraHeight; const float fm_ESun = 150.0; const float fm_Kr = 0.0025; const float fm_Km = 0.0010; const float fKrESun = fm_Kr * fm_ESun; const float fKmESun = fm_Km * fm_ESun; const float fKr4PI = fm_Kr * 4 * 3.141592653; const float fKm4PI = fm_Km * 4 * 3.141592653; varying vec3 v3Direction; varying vec4 c0, c1; float scale(float fCos) { float x = 1.0 - fCos; return fScaleDepth * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25)))); } void main( void ) { // Get the ray from the camera to the vertex, and its length (which is the far point of the ray passing through the atmosphere) vec3 v3FrontColor = vec3(0.0, 0.0, 0.0); vec3 v3Pos = normalize(gl_Vertex.xyz) * fOuterRadius; vec3 v3Ray = v3CameraPos - v3Pos; float fFar = length(v3Ray); v3Ray = normalize(v3Ray); // Calculate the ray's starting position, then calculate its scattering offset vec3 v3Start = v3CameraPos; float fHeight = length(v3Start); float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fCameraHeight)); float fStartAngle = dot(v3Ray, v3Start) / fHeight; float fStartOffset = fDepth*scale(fStartAngle); // Initialize the scattering loop variables float fSampleLength = fFar / fSamples; float fScaledLength = fSampleLength * fScale; vec3 v3SampleRay = v3Ray * fSampleLength; vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5; // Now loop through the sample rays for(int i=0; i<nSamples; i++) { float fHeight = length(v3SamplePoint); float fDepth = exp(fScaleOverScaleDepth * (fInnerRadius - fHeight)); float fLightAngle = dot(normalize(v3LightPos), v3SamplePoint) / fHeight; float fCameraAngle = dot(normalize(v3Ray), v3SamplePoint) / fHeight; float fScatter = (-fStartOffset + fDepth*( scale(fLightAngle) - scale(fCameraAngle)))/* 0.25f*/; vec3 v3Attenuate = exp(-fScatter * (v3InvWavelength * fKr4PI + fKm4PI)); v3FrontColor += v3Attenuate * (fDepth * fScaledLength); v3SamplePoint += v3SampleRay; } // Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader vec4 newPos = vec4( (gl_Vertex.xyz + view_position.xyz), 1.0); gl_Position = gl_ModelViewProjectionMatrix * vec4(newPos.xyz, 1.0); gl_Position.z = gl_Position.w * 0.99999; c1 = vec4(v3FrontColor * fKmESun, 1.0); c0 = vec4(v3FrontColor * (v3InvWavelength * fKrESun), 1.0); v3Direction = v3CameraPos - v3Pos; } Fragment Shader: uniform vec3 v3LightPos; varying vec3 v3Direction; varying vec4 c0; varying vec4 c1; const float g =-0.90f; const float g2 = g * g; const float Exposure =2; void main(void){ float fCos = dot(normalize(v3LightPos), v3Direction) / length(v3Direction); float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos*fCos) / pow(1.0 + g2 - 2.0*g*fCos, 1.5); gl_FragColor = c0 + fMiePhase * c1; gl_FragColor.a = 1.0; }

    Read the article

  • FrameBuffer Render to texture not working all the way

    - by brainydexter
    I am learning to use Frame Buffer Objects. For this purpose, I chose to render a triangle to a texture and then map that to a quad. When I render the triangle, I clear the color to something blue. So, when I render the texture on the quad from fbo, it only renders everything blue, but doesn't show up the triangle. I can't seem to figure out why this is happening. Can someone please help me out with this ? I'll post the rendering code here, since glCheckFramebufferStatus doesn't complain when I setup the FBO. I've pasted the setup code at the end. Here is my rendering code: void FrameBufferObject::Render(unsigned int elapsedGameTime) { glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); glClearColor(0.0, 0.6, 0.5, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // adjust viewport and projection matrices to texture dimensions glPushAttrib(GL_VIEWPORT_BIT); glViewport(0,0, m_FBOWidth, m_FBOHeight); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, m_FBOWidth, 0, m_FBOHeight, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); DrawTriangle(); glPopAttrib(); // setting FrameBuffer back to window-specified Framebuffer glBindFramebuffer(GL_FRAMEBUFFER, 0); //unbind // back to normal viewport and projection matrix //glViewport(0, 0, 1280, 768); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, 1.33, 1.0, 1000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); render(elapsedGameTime); } void FrameBufferObject::DrawTriangle() { glPushMatrix(); glBegin(GL_TRIANGLES); glColor3f(1, 0, 0); glVertex2d(0, 0); glVertex2d(m_FBOWidth, 0); glVertex2d(m_FBOWidth, m_FBOHeight); glEnd(); glPopMatrix(); } void FrameBufferObject::render(unsigned int elapsedTime) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_TextureID); glPushMatrix(); glTranslated(0, 0, -20); glBegin(GL_QUADS); glColor4f(1, 1, 1, 1); glTexCoord2f(1, 1); glVertex3f(1,1,1); glTexCoord2f(0, 1); glVertex3f(-1,1,1); glTexCoord2f(0, 0); glVertex3f(-1,-1,1); glTexCoord2f(1, 0); glVertex3f(1,-1,1); glEnd(); glPopMatrix(); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); } void FrameBufferObject::Initialize() { // Generate FBO glGenFramebuffers(1, &m_FBO); glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); // Add depth buffer as a renderbuffer to fbo // create depth buffer id glGenRenderbuffers(1, &m_DepthBuffer); glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer); // allocate space to render buffer for depth buffer glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_FBOWidth, m_FBOHeight); // attaching renderBuffer to FBO // attach depth buffer to FBO at depth_attachment glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_DepthBuffer); // Adding a texture to fbo // Create a texture glGenTextures(1, &m_TextureID); glBindTexture(GL_TEXTURE_2D, m_TextureID); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_FBOWidth, m_FBOHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); // onlly allocating space glBindTexture(GL_TEXTURE_2D, 0); // attach texture to FBO glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TextureID, 0); // Check FBO Status if( glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "\n Error:: FrameBufferObject::Initialize() :: FBO loading not complete \n"; // switch back to window system Framebuffer glBindFramebuffer(GL_FRAMEBUFFER, 0); } Thanks!

    Read the article

  • How can I catch an invalid fgetpos call as a C++ exception on Windows?

    - by Brent Arias
    In Visual C++ 2008, I want to "catch" an exception generated as shown here: try { int foo = 20; ::fgetpos(0, (fpos_t*)&foo); } //... Here are adjustments I've made to attempt a successful catch: SEH is activated (/eha) I've added a catch(...) I've added a _set_se_translator vector. I've added/adjusted to SEH syntax: __try / __except(EXCEPTION_EXECUTE_HANDLER) In short, I've tried "everything in the book" and I still can't catch the exception. If I replace the call to ::fgetpos with int hey = foo / 0 then suddenly all of the above techniques work as expected. So the exception I'm dealing with from ::fgetpos is somehow "extra special." Can someone explain why this ::fgetpos error seems uncatchable, and how to work around it? update When executed in the VS IDE, the output window doesn't name an exception. All it says is this: Microsoft Visual Studio C Runtime Library has detected a fatal error in MyProgram.exe. Not very helpful. When I run the console app from the command line, I get a crash dialogue. The "problem details" section of the dialogue includes this information: Problem Event Name: BEX Exception Offset:0002fd30 Exception Code: c0000417 Exception Data: 00000000 Additional Information 1:69ad Additional Information 2:69addfb19767b2221c8e3e7a5cd2f4ae Additional Information 3:b1ff Additional Information 4:b1ffca30cadddc78c19f19b6d150997f

    Read the article

  • Repeating characters in VIM insert mode

    - by Cthutu
    Is there a way of repeating a character while in Vim's insert mode? For example, say I would like to insert 80 dashes, in something like emacs I would type: Ctrl+U 8 0 - The only way I know how to do it in VIM is to exit normal mode for the repeat argument, then go back into insert mode to type the dash, then exit to insert the actual dashes, AND then go back into insert mode to carry on typing. The sequence is a really long: <ESC> 8 0 a - <ESC> a It would be nice not to switch in and out of modes. Thanks

    Read the article

  • Initializing static pointer in templated class.

    - by Anthony
    This is difficult for me to formulate in a Google query (at least one that gives me what I'm looking for) so I've had some trouble finding an answer. I'm sure I'm not the first to ask though. Consider a class like so: template < class T > class MyClass { private: static T staticObject; static T * staticPointerObject; }; ... template < class T > T MyClass<T>::staticObject; // <-- works ... template < class T > T * MyClass<T>::staticPointerObject = NULL; // <-- cannot find symbol staticPointerObject. I am having trouble figuring out why I cannot successfully create that pointer object. Edit: The above code is all specified in the header, and the issue I mentioned is an error in the link step, so it is not finding the specific symbol.

    Read the article

  • NHibernate (or other worth recommendation ORM), real life example?

    - by migajek
    I'd like to learn database applications in C# and I'm about to select some framework. I heard many recommendations of NHibernate, however I haven't decided yet. Anyway, I'd like to know if there's any real-life example (with sources) of NHibernate in C#, to learn best practices etc.? I know all of them are probably covered in the docs, but working example helps a lot understanding the proper development pattern.

    Read the article

  • Android: Use XML Layout for List Cell rather than Java Code Layout (Widgets)

    - by Stephen Finucane
    Hi, I'm in the process of making a music app and I'm currently working on the library functionality. I'm having some problems, however, in working with a list view (In particular, the cells). I'm trying to move from a simple textview layout in each cell that's created within java to one that uses an XML file for layout (Hence keeping the Java file mostly semantic) This is my original code for the cell layout: public View getView(int position, View convertView, ViewGroup parent) { String id = null; TextView tv = new TextView(mContext.getApplicationContext()); if (convertView == null) { music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE); musiccursor.moveToPosition(position); id = musiccursor.getString(music_column_index); music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME); musiccursor.moveToPosition(position); id += "\n" + musiccursor.getString(music_column_index); music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM); musiccursor.moveToPosition(position); id += "\n" + musiccursor.getString(music_column_index); tv.setText(id); } else tv = (TextView) convertView; return tv; } And my new version: public View getView(int position, View convertView, ViewGroup parent) { View cellLayout = findViewById(R.id.albums_list_cell); ImageView album_art = (ImageView) findViewById(R.id.album_cover); TextView album_title = (TextView) findViewById(R.id.album_title); TextView artist_title = (TextView) findViewById(R.id.artist_title); if (convertView == null) { music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM); musiccursor.moveToPosition(position); album_title.setText(musiccursor.getString(music_column_index)); //music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME); //musiccursor.moveToPosition(position); music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE); musiccursor.moveToPosition(position); artist_title.setText(musiccursor.getString(music_column_index)); } else{ cellLayout = (TextView) convertView; } return cellLayout; } The initialisation (done in the on create file): musiclist = (ListView) findViewById(R.id.PhoneMusicList); musiclist.setAdapter(new MusicAdapter(this)); musiclist.setOnItemClickListener(musicgridlistener); And the respective XML files: (main) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/PhoneMusicList" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:id="@android:id/empty" android:layout_width="wrap_content" android:layout_height="0dip" android:layout_weight="1.0" android:text="@string/no_list_data" /> </LinearLayout> (albums_list_cell) <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/albums_list_cell" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/album_cover" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_width="50dip" android:layout_height="50dip" /> <TextView android:id="@+id/album_title" android:layout_toRightOf="@+id/album_cover" android:layout_alignParentTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/artist_title" android:layout_toRightOf="@+id/album_cover" android:layout_below="@+id/album_title" android:layout_width="wrap_content" android:layout_height="15dip" /> </RelativeLayout> In theory (based on the tiny bit of Android I've done so far) this should work..it doesn't though. Logcat gives me a null pointer exception at line 96 of the faulty code, which is the album_title.setText line. It could be a problem with my casting but Google tells me this is ok :D Thanks for any help and let me know if you need more info!

    Read the article

  • Visual Studio 2005 - Debugger stopped working.

    - by eric
    More fun and pain with Visual Studio. Visual Studio 2005. About two months ago, I started an assignment. In my role, I cannot install or configure development software. Trust me this has given me plenty of heartburn. No IIS is involved here, just File Sharing. That being said, when I first started I had a problem with my debugger not working. The debugger just stopped. I was able to get it working. Now the problem has returned and I am pulling every last hair on my head. Almost none of my symbols loads. It can't find the PDB files. In Debugger options, I checked the Symbol section. My symbol file location entry is completely blank. ? I don't know why. I did not touch this prior to the problem occurring. I have cleared the Temporary ASP.NET folders. Example: Here is my Module Output CppCodeProvider.dll C:\Windows\assembly\GAC_MSIL\CppCodeProvider\8.0.0.0__b03f5f7f11d50a3a\CppCodeProvider.dll No No Cannot find or open the PDB file. 17 8.0.50727.762 12/2/2006 4:23 AM 6A510000-6A52C000 [1844] WebDev.WebServer.EXE: Managed WebDev.WebHost.dll C:\Windows\assembly\GAC_32\WebDev.WebHost\8.0.0.0__b03f5f7f11d50a3a\WebDev.WebHost.dll No No Cannot find or open the PDB file. 3 8.0.50727.42 9/23/2005 4:20 AM 6D040000-6D050000 [1844] WebDev.WebServer.EXE: Managed So I enabled the SHFUSION.dll in my versio of the the Framework I am using... In my GAC, I can see this version of WebDev.WebHost.dll for example: ProcessArchitecture(x86) Public key token matches: b03f5f7f11d50a3a 8.0.50727.42 I then see some custom dlls. I should note, I created a new project. Recreated my files manually by importing them. The debugger worked 5 times and died. I'm at a loss of what to do next? The obvious has been checked: The project is set to Debug Configuration Manager Configuration Debug Platform .NET Build : checked. Web.Config: I have attempted to manually attach to the Webdev process from the Debug window and that doesn't work. I have googled this and this problem seems to occur quite a bit.

    Read the article

  • Rails populate edit form for non-column attributes

    - by Rabbott
    I have the following form: <% form_for(@account, :url => admin_accounts_path) do |f| %> <%= f.error_messages %> <%= render :partial => 'form', :locals => {:f => f} %> <h2>Account Details</h2> <% f.fields_for :customer do |customer_fields| %> <p> <%= customer_fields.label :company %><br /> <%= customer_fields.text_field :company %> </p> <p> <%= customer_fields.label :first_name %><br /> <%= customer_fields.text_field :first_name %> </p> <p> <%= customer_fields.label :last_name %><br /> <%= customer_fields.text_field :last_name %> </p> <p> <%= customer_fields.label :phone %><br /> <%= customer_fields.text_field :phone %> </p> <% end %> <p> <%= f.submit 'Create' %> </p> <% end %> As well as attr_accessor :customer And I have a before_create method for the account model which does not store the customer_fields, but instead uses them to submit data to an API.. The only thing I store are in the form partial.. The problem I'm running into is that when a validation error gets thrown, the page renders the new action (expected) but none of the non-column attributes within the Account Detail form will show? Any ideas as to how I can change this code around a bit to make this work me?? This same solution may be the help I need for the edit form, I have a getter for the data which it asks the API for, but without place a :value = "asdf" within each text box, it doesn't populate the fields either..

    Read the article

  • What is the current state of the art in HTML canvas JavaScript libraries and frameworks?

    - by Toby Hede
    I am currently investigating options for working with the canvas in a new HTML 5 application, and was wondering what is the current state of the art in HTML canvas JavaScript libraries and frameworks? In particular, are there frameworks that support the kind of things needed for game development - complex animation, managing scene graphs, handling events and user interactions? Also willing to consider both commercial and open source products.

    Read the article

  • How do I center this CSS?

    - by sarthaksss
    Here is the CSS - #slider ul, #slider li, #slider2 ul, #slider2 li{ margin:0; padding:0; list-style:none; } #slider2{margin-top:1em;} #slider li, #slider2 li{ /* define width and height of list item (slide) entire slider area will adjust according to the parameters provided here */ width:500px; height:250px; overflow:hidden; } #prevBtn, #nextBtn, #slider1next, #slider1prev{ display:block; width:30px; height:77px; position:absolute; left:-30px; top:71px; z-index:1000; } #nextBtn, #slider1next{ left:696px; } #prevBtn a, #nextBtn a, #slider1next a, #slider1prev a{ display:block; position:relative; width:30px; height:77px; background:url(../images/btn_prev.gif) no-repeat 0 0; } #nextBtn a, #slider1next a{ background:url(../images/btn_next.gif) no-repeat 0 0; } /* numeric controls */ #slider img{ width:500px; height:300px; } ol#controls{ margin:1em 0; padding:0; height:28px; } ol#controls li{ margin:0 10px 0 0; padding:0; float:left; list-style:none; height:28px; line-height:28px; } ol#controls li a{ float:left; height:28px; line-height:28px; border:1px solid #ccc; background:#b32d45; color:white; padding:0 10px; text-decoration:none; } ol#controls li.current a{ background:#5DC9E1; color:#fff; } ol#controls li a:focus, #prevBtn a:focus, #nextBtn a:focus{outline:none;} I want to center the #slider HTML <div id="slider"> <ul> <li>IMAGE</li> <li>IMAGE2</li> </ul> </div>

    Read the article

  • plot 3D and combine in matlab

    - by George
    Hello ,i have this matrix "experiment=2*rand(npoints,3)-1". I want to plot in in 3D,so i use "mesh(experiment)". How can i take red points in my plot? Also,i want to implement in the above plot , a sphere with radius 1 at 0,0,0. I did : mesh(experiment) hold on [x,y,z]=sphere; r=1; mesh(r*x,r*y,r*z) hold off but 1) i am not taking radius 1 2) the figures just showing in the same graph but don't combine Thanks

    Read the article

  • Performing text processing on flatpage content to include handling of custom tag

    - by Dzejkob
    Hi. I'm using flatpages app in my project to manage some html content. That content will include images, so I've made a ContentImage model allowing user to upload images using admin panel. The user should then be able to include those images in content of the flatpages. He can of course do that by manually typing image url into <img> tag, but that's not what I'm looking for. To make including images more convenient, I'm thinking about something like this: User edits an additional, let's say pre_content field of CustomFlatPage model (I'm using custom flatpage model already) instead of defining <img> tags directly, he uses a custom tag, something like [img=...] where ... is name of the ContentImage instance now the hardest part: before CustomFlatPage is saved, pre_content field is checked for all [img=...] occurences and they are processed like this: ContentImage model is searched if there's image instance with given name and if so, [img=...] is replaced with proper <img> tag. flatpage actual content is filled with processed pre_content and then flatpage is saved (pre_content is leaved unchanged, as edited by user) The part that I can't cope with is text processing. Should I use regular expressions? Apparently they can be slow for large strings. And how to organize logic? I assume it's rather algorithmic question, but I'm not familliar with text processing in Python enough, to do it myself. Can somebody give me any clues?

    Read the article

  • How to write an Android SocketServer to listen on wifi

    - by xioxox
    I've written a thread using java.net.SocketServer to listen on a particular port. It works fine in the android simulator (using port forwarding). I'm planning to connect over wifi to this port when the app is being used. However, the SocketServer documentation says that if you don't supply an InetAddress, the server listens on localhost. Am I correct that if I do not supply the address, I will not be able to get a connection over wifi? How can I get the InetAddress of the wifi connection to pass to the SocketServer?

    Read the article

  • django urls.py regex isn't working

    - by Phil
    This is for Django 1.2.5 and Python 2.7 on Wamp Server running apache version 2.2.17. My problem is that the my URLConf in urls.py isn't redirecting, it's just throwing a 404 error. urls.py: from django.conf.urls.defaults import * # Uncomment the next two lines to enable the admin: #from django.contrib import admin #admin.autodiscover() urlpatterns = patterns('', (r'^app/$', include('app.views.index')), # Uncomment the admin/doc line below to enable admin documentation: #(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: #(r'^admin/', include(admin.site.urls)), ) views.py from django.http import HttpResponse def index(request): return HttpResponse("Hello World") I'm getting the following error: ImportError at /app/ No module named index I'm stumped as I'm only learning Django, can anybody see something wrong with my code? Here's my PythonPath: ['C:\Windows\system32\python27.zip', 'C:\Python27\Lib', 'C:\Python27\DLLs', 'C:\Python27\Lib\lib-tk', 'C:\wamp\bin\apache\Apache2.2.17', 'C:\wamp\bin\apache\apache2.2.17\bin', 'C:\Python27', 'C:\Python27\lib\site-packages', 'c:\wamp\www\seetwo']

    Read the article

  • python crc32 woes

    - by lazyr
    I'm writing a python program to extract data from the middle of a 6 GB bz2 file. A bzip2 file is made up of independently decryptable blocks of data, so I only need to find a block (they are delimited by magic bits), then create a temporary one-block bzip2 file from it in memory, and finally pass that to the bz2.decompress function. Easy, no? The bzip2 format has a crc32 checksum for the file at the end. No problem, binascii.crc32 to the rescue. But wait. The data to be checksummed does not necessarily end on a byte boundary, and the crc32 function operates on a whole number of bytes. My plan: use the binascii.crc32 function on all but the last byte, and then a function of my own to update the computed crc with the last 1-7 bits. But hours of coding and testing has left me bewildered, and my puzzlement can be boiled down to this question: how come crc32("\x00") is not 0x00000000? Shouldn't it be, according to the wikipedia article? You start with 0b00000000 and pad with 32 0's, then do polynomial division with 0x04C11DB7 until there are no ones left in the first 8 bits, which is immediately. Your last 32 bits is the checksum, and how can that not be all zeroes? I've searched google for answers and looked at the code of several crc32 implementations without finding any clue to why this is so.

    Read the article

  • Preselection in the save dialog (c#)

    - by FullmetalBoy
    Goal: Save a notepad file in the computer. (C#) Problem: I don't know how to make a preselection as "TXT Files(*.txt)" in the "Save as type:" when save dialog display? // Fullmetalboy using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace Labb2_application { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void mnuFileOpen_Click(object sender, EventArgs e) { OpenFileDialog fDialog = new OpenFileDialog(); fDialog.Title = "Öppna"; fDialog.Filter = "Text files|*.txt"; fDialog.InitialDirectory = @"C:\Windows"; fDialog.ShowHelp = true; DialogResult result = fDialog.ShowDialog(); // Show the dialog and get result. if (result == DialogResult.OK) { string fileAdress = fDialog.FileName; try { string textContent = File.ReadAllText(fileAdress); rtxtDisplay.Text = textContent; } catch (IOException) { } } // If syntax } private void mnuFileSave_Click(object sender, EventArgs e) { saveAsFileDialog.ShowDialog(); } private void mnuFileSaveAs_Click(object sender, EventArgs e) { saveAsFileDialog.Filter = "Text files|*.txt"; saveAsFileDialog.ShowDialog(); } private void mnuFileExit_Click(object sender, EventArgs e) { Application.Exit(); } private void saveAsFileDialog_FileOk(object sender, CancelEventArgs e) { string fileNameAddress = saveAsFileDialog.FileName; File.WriteAllText(fileNameAddress, rtxtDisplay.Text); } } // Partial Class }

    Read the article

  • How can one use multi threading in php applications

    - by Steve Obbayi
    Is there a realistic way of implementing a multi-threaded model in php whether truly or just simulating it. Some time back it was suggested that you can force the operating system to load another instance of the php executable and handle other simultaneous processes. The problem with this is that when the php code finished executing the php instance remains in memory because there is no way to kill it from within php. so if you are simulating several threads you can imagine whats going to happen. So am still looking for a way multi-threading can be done or simulated effectively from within php. Any ideas?

    Read the article

  • excluding previously randomized integer, and randomize again without it

    - by Rob
    <?php if (isset($_POST['Roll!'])) { $sides = $_POST['sides']; $rolled = rand(1,$sides); echo "$rolled was rolled by the dice, it is now out!"; } ?> This is the code I currently have. After rolling that number, however, I want it to roll again, but without the previously rolled number, until it has rolled all number except one, which would be the winning number. I have no idea how to go about doing that. Any ideas? EDIT: I'm sorry, I should have been more clear, thank you all for the help so far, but I also need to echo each number rolled, such as echo "$rolledArray[0] was rolled, it lost.\n"; echo "$rolledArray[1] was rolled, it lost.\n"; echo "$rolledArray[2] was rolled, it lost.\n"; echo "$rolledArray[3] was rolled, it lost.\n"; echo "$rolledArray[x] was rolled, it lost.\n"; echo "$rolledArray[x] was rolled, it lost.\n"; echo "$rolledArray[50?] was rolled, it lost."; EDIT AGAIN: Also I only want them to have to click Roll! once, not multiple times until they've rolled all the numbers, meaning no need for session, I think, though I could be wrong, most of you are clearly more experienced than me. Sorry, I should have mentioned that before as well.

    Read the article

  • Can An Android Appliction Be Launched Without a Main Activity?

    - by Androider
    I have verified that an App does not need a Main Activity, and in fact does not need any activities. Thanks for the responses on this. But here is another question. Is there any way to launch an application without a main activity declared? If the answer is no, then I have a follow up, can the MAIN action be removed from the application at runtime after launch so that the app no longer has a MAIN activity after launch? Or even can the activity itself be entirely removed from the application at runtime if it is no longer needed. Thanks.

    Read the article

  • Integrate Weld CDI into a JSF 1.2 EJB Application on jboss 6 AS

    - by ich-bin-drin
    Hi, since two evenings i am trying to integrate weld CDI into an EJB 3.1 Application with JSF 1.2. I simply tried to call a with @Named annotated controller in an JSF page. The problem is, that no exception is thrown, when i deploy the project and also no exception is thrown when i call the page. The simple example contains only: The Controller: import javax.inject.Named; @Named public class HelloWorldController { public HelloWorldController(){ System.out.println("Hello World!"); } public String getMessage() { return "Hello Weld World"; } } And it's call: <h1><h:outputText value="#{helloWorldController.message}" /></h1> THX

    Read the article

  • System Center Service Manager 2010 SP1 Resource Links

    - by Mickey Gousset
    System Center Service Manager is a new product that Microsoft released last year to handle incident/problem/change management.  Currently the latest version is System Center Service Manager SP1, and there is a Cumulative Update for SP1 that you should grab as well. A strong ecosystem is starting to spring up around this product, with tools and connectors that fill needs not build into the product.  To find the latest list of these items, you need to do to the SCSM 2010 Downloads page.  Here you can find a list of the latest tools and add-ons from Microsoft, as well as third-party vendors.  The Microsoft Exchange connector, and the Powershell Cmdlets are definitely worth it to download and install.

    Read the article

  • Multiple SSL on same IP [closed]

    - by kadourah
    Possible Duplicate: Multiple SSL domains on the same IP address and same port? I have the following situation: first domain: test.domain.com IP: 1.2.3.4 Port: 443 SSL: Purchased from godaddy and specific to that domain Works fine no issues. I would like to add another site: test2.domain.com IP: the same Port: can be different SSL: different since I can't use the SSL above because it's specific to the site above. Now, when I add the HTTPS binding to the second site with IP:Port combination it appears to always load the first SSL ignoring the second certificate. How can I add second SSL binding to the same IP using a "different" certificate? Can this be done?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10  | Next Page >