Search Results

Search found 11607 results on 465 pages for 'disabling features and an'.

Page 44/465 | < Previous Page | 40 41 42 43 44 45 46 47 48 49 50 51  | Next Page >

  • What is the best way to attach extenstion methods to static classes rather than to instances of a cl

    - by John Gietzen
    If I have a method for calculating the greatest common divisor of two integers as: public static int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); } What would be the best way to attach that to the System.Math class? Here are the three ways I have come up with: public static int GCD(this int a, int b) { return b == 0 ? a : b.GCD(a % b); } // Lame... var gcd = a.GCD(b); and: public static class RationalMath { public static int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); } } // Lame... var gcd = RationalMath.GCD(a, b); and: public static int GCD(this Type math, int a, int b) { return b == 0 ? a : typeof(Math).GCD(b, a % b); } // Neat? var gcd = typeof(Math).GCD(a, b); The desired syntax is Math.GCD since that is the standard for all mathematical functions. Any suggestions? What should I do to get the desired syntax?

    Read the article

  • What is the best way to attach static methods to classes rather than to instances of a class?

    - by John Gietzen
    If I have a method for calculating the greatest common divisor of two integers as: public static int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); } What would be the best way to attach that to the System.Math class? Here are the three ways I have come up with: public static int GCD(this int a, int b) { return b == 0 ? a : b.GCD(a % b); } // Lame... var gcd = a.GCD(b); and: public static class RationalMath { public static int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); } } // Lame... var gcd = RationalMath.GCD(a, b); and: public static int GCD(this Type math, int a, int b) { return b == 0 ? a : typeof(Math).GCD(b, a % b); } // Neat? var gcd = typeof(Math).GCD(a, b); The desired syntax is Math.GCD since that is the standard for all mathematical functions. Any suggestions? What should I do to get the desired syntax?

    Read the article

  • NetBeans Tips and Tricks

    - by cdmckay
    I just saw an Eclipse tips & tricks post and was wondering if anyone had any tips & tricks for my IDE of choice: NetBeans. Here's a few I know and find to be useful: Removing a package: After you remove a package in NetBeans, it sticks around as a grayed-out package in your Project view. To get rid of that, switch to Files view and delete the directory. Alt-Insert (in Windows) opens up a Generate submenu at your cursor. A nice shortcut for quickly generating getters/setters (among other things). Selecting a chunk of code, right-clicking and then clicking "Refactor Introduce Method" will have NetBeans introduce a method, complete with arguments and return value. Of course you have to make sure the chunk of code only has one return value. Sometimes when you run a build and it crashes, the Java window sticks around at the bottom. I used to just click X until Windows let me End Task, but there's a nicer way to get rid of them. Click "Run Stop Build/Run" and NetBeans will close the window for you. It'll even let you close multiple applications at once. These may seem obvious to grizzled NetBeans developers, but I thought they might be useful for NetBeans newbs like me. Anyone else have any tips/tricks to share? Here are some from the comments: NetBeans allows for code templates. You can even add yours on the Code Templates tab under the Editor settings on the Options window. Some examples: Type sout and hit the tab key as a shorcut for System.out.println("") Type psvm and hit the tab key as a shorcut for public static void main(String args[]) {} Ctrl Shift C: Comments out the selected block of code. Alt Shift F: Formats the selected block of code. Ctrl E: Deletes current line. Ctrl Shift I: Fixes your imports, handy if you've just written a piece of code that needs a lot of packages imported.

    Read the article

  • Python thread pool similar to the multiprocessing Pool?

    - by Martin
    Is there a Pool class for worker threads, similar to the multiprocessing module's Pool class? I like for example the easy way to parallelize a map function def long_running_func(p): c_func_no_gil(p) p = multiprocessing.Pool(4) xs = p.map(long_running_func, range(100)) however I would like to do it without the overhead of creating new processes. I know about the GIL. However, in my usecase, the function will be an IO-bound C function for which the python wrapper will release the GIL before the actual function call. Do I have to write my own threading pool?

    Read the article

  • Design a GUI browser to view a tree

    - by iamrohitbanga
    I have a large tree. I want to be able to visualize it using a GUI tool. I want the ability to pan and zoom the tree image so that i can focus on part of the tree. Is there an existing tool to achieve this? If not i would like to write a small tool for myself to be able to do this. what is the simplest way of doing this? what computer language should i use? the image should look something like http://upload.wikimedia.org/wikipedia/commons/d/df/Binary_tree.png I should be able to zoom and pan the image.

    Read the article

  • Why scala not allowing '$' identifier in case statement?

    - by Alex R
    this works as expected scala 3 match { case x:Int = 2*x } res1: Int = 6 why does this fail? scala 3 match { case $x:Int = 2*$x } :1: error: '=' expected but ':' found. 3 match { case $x:Int = 2*$x } ^ scala 3 match { case `$x`:Int = 2*$x } :1: error: '=' expected but ':' found. 3 match { case `$x`:Int = 2*$x } ^ scala 3 match { case `$x` : Int = 2*$x } :1: error: '=' expected but ':' found. 3 match { case `$x` : Int = 2*$x } '$' is supposed to be a valid identifier character, as demonstrated here: scala var y = 1 y: Int = 1 scala var $y = 2 $y: Int = 2 Thanks

    Read the article

  • How much of the "Objective-C" I'm learning is universal Objective-C, and not Apple's frameworks?

    - by Chris Cooper
    This question is related to one of my others about C: What can you do in C without “std” includes? Are they part of “C,” or just libraries? I've become curious lately as to what is really contained the the core Objective-C language, and what parts of the Objective-C I've done for iPhone/OS X development is specific to Apple platforms. I know that things like syntax are the same, but for instance, is NSObject and its torrent of NS-subclasses actually part of "standard" Objective-C? Could I use them in, say, Windows? What parts are universal for the most part, and what parts would I only find on an Apple platform? If you want, giving an example of Objective-C used elsewhere as an example of what is more "universal" would help me as well. Thanks! =)

    Read the article

  • Which languages support *recursive* function literals / anonymous functions?

    - by Hugh Allen
    It seems quite a few mainstream languages support function literals these days. They are also called anonymous functions, but I don't care if they have a name. The important thing is that a function literal is an expression which yields a function which hasn't already been defined elsewhere, so for example in C, &printf doesn't count. EDIT to add: if you have a genuine function literal expression <exp>, you should be able to pass it to a function f(<exp>) or immediately apply it to an argument, ie. <exp>(5). I'm curious which languages let you write function literals which are recursive. Wikipedia's "anonymous recursion" article doesn't give any programming examples. Let's use the recursive factorial function as the example. Here are the ones I know: JavaScript / ECMAScript can do it with callee: function(n){if (n<2) {return 1;} else {return n * arguments.callee(n-1);}} it's easy in languages with letrec, eg Haskell (which calls it let): let fac x = if x<2 then 1 else fac (x-1) * x in fac and there are equivalents in Lisp and Scheme. Note that the binding of fac is local to the expression, so the whole expression is in fact an anonymous function. Are there any others?

    Read the article

  • C# -Interview Question Anonymous Type

    - by Amutha
    Recently i was asked to prove the power of C# 3.0 in a single line( might be tricky) i wrote new int[] { 1, 2, 3 }.Union(new int[]{10,23,45}). ToList().ForEach(x => Console.WriteLine(x)); and explained you can have (i) anonymous array (ii) extension method (iii)lambda and closure all in a single line.I got spot offer. But..... The interviewer asked me how will you convert an anonymous type into know type :( I am 100% sure ,we can not do that.The interviewer replied there is 200% chance to do that if you have a small work around.I was clueless. As usual,I am waiting for your valuable reply(Is it possible?).

    Read the article

  • Can TextMate find matching opening and closing tags?

    - by johnny
    Something I liked in Visual Studio was that I could click an opening tag, say and it would do its best to highlight in bold the closing tag. Does anyone know if you can do that in textmate? I searched an looked but cannot find it. It gets hard to find the closing tag many DIVs deep. If TextMate won't do it, can anyone tell me an editor on Mac that will? Thank you for any help. EDIT: If it can do it, can someone please tell me how? Thanks again.

    Read the article

  • Making hovor state of hidden list visible when page is active

    - by Joel
    Hi guys, One day I hope to not be such a newbie on this stuff, but some of this feels so insurmountable sometimes! OK. I have a nav bar with hidden li items that are visible when hovered over. Here's the live site: http://www.rattletree.com Here's the code for the nav: <ul id="navbar"> <li id="iex"><a href="index.php">About Rattletree</a></li> <li id="upcomgshows"><a href="upcomingshows.php">Calendar</a></li> <li id="sods"><a href="#">Sights &amp; Sounds</a> <ul class="innerlist"> <li class="innerlist"><img class="arrowAdjust" src="images/curved_arrow.png" alt="" /></li> <li class="innerlist"><a href="/playlist.m3u" target="_blank" onclick="javascript:BatmoAudioPop('Rattletree Marimba',this.href,'1'); return false">Listen</a></li> <li class="innerlist"><a href="/new_pictures.php">Photos</a></li> <li class="innerlist"><a href="/video.php">Video</a></li> <li class="innerlist"><a href="/press.php">Press</a></li> </ul> </li> <li id="bookin"><a href="#">Contact</a> <ul class="innerlist"> <li class="innerlist"><img class="arrowAdjust" src="images/curved_arrow.png" alt="" /></li> <li class="innerlist"><a href="/booking.php">Booking Info</a></li> <li class="innerlist"><a href="/media.php">Media Inquiries</a></li> </ul> </li> <li id="ste"> <a href="/sounds.php">Store</a></li> <li id="instrumes"><a href="/instruments.php">The Instruments</a></li> <li id="classe"><a href="classes.php">Workshops</a></li> </ul> css: div#navbar2 { background-color:#546F8B; border-bottom:1px solid #546F8B; border-top:1px solid #000000; display:inline-block; position:relative; width:100%; } div#navbar2 ul#navbar { color:#FFFFFF; font-family:Arial,Helvetica,sans-serif; font-size:16px; letter-spacing:1px; margin:10px 0; padding:0; white-space:nowrap; } div#navbar2 ul#navbar li ul.innerlist { color:#000000; display:none; position:relative; z-index:20; } div#navbar2 ul#navbar li { display:inline; list-style-type:none; margin:0; padding:0; position:relative; } Now it's a bit tricky what I want to do: If a user navigates to one of the innerlist pages, I'd like that innerlist ul to remain visible (with the specific li displaying the hovered state). Now I think I could figure that out on my own, but you can see on the live page that if the user is on a page from the innerlist and that list was visible, then if they hovered over the other nav tab, then those innerlists would overlap. This is a problem. Hopefully that last sentence makes sense! In short: I need to keep the inner list of the active page displaying, BUT if the user hovers over another nav button WITH it's own inner list, then the live innerlist needs to disappear. Clear as mud?

    Read the article

  • java partial classes

    - by Dewfy
    Hello colleagues, Small preamble. I was good java developer on 1.4 jdk. After it I have switched to another platforms, but here I come with problem so question is strongly about jdk 1.6 (or higher :) ). I have 3 coupled class, the nature of coupling concerned with native methods. Bellow is example of this 3 class public interface A { public void method(); } final class AOperations { static native method(. . .); } public class AImpl implements A { @Override public void method(){ AOperations.method( . . . ); } } So there is interface A, that is implemented in native way by AOperations, and AImpl just delegates method call to native methods. These relations are auto-generated. Everything ok, but I have stand before problem. Sometime interface like A need expose iterator capability. I can affect interface, but cannot change implementation (AImpl). Saying in C# I could be able resolve problem by simple partial: (C# sample) partial class AImpl{ ... //here comes auto generated code } partial class AImpl{ ... //here comes MY implementation of ... //Iterator } So, has java analogue of partial or something like.

    Read the article

  • List of Lua derived VMs and Languages

    - by Shane Holloway
    Is there a compendium of virtual machines and languages derived or inspired by Lua? By derived, I mean usage beyond embedding and extending with modules. I'm wanting to research the Lua technology tree, and am looking for our combined knowledge of what already exists. Current List: Bright - A C-like Lua Derivative http://bluedino.net/luapix/Bright.pdf Agena - An Algol68/SQL like Lua Derivative http://agena.sourceforge.net/ LuaJIT - A (very impressive) JIT for Lua http://luajit.org MetaLua - An ML-style language extension http://metalua.luaforge.net/

    Read the article

  • Is Java assert broken?

    - by BlairHippo
    While poking around the questions, I recently discovered the assert keyword in Java. At first, I was excited. Something useful I didn't already know! A more efficient way for me to check the validity of input parameters! Yay learning! But then I took a closer look, and my enthusiasm was not so much "tempered" as "snuffed-out completely" by one simple fact: you can turn assertions off.* This sounds like a nightmare. If I'm asserting that I don't want the code to keep going if the input listOfStuff is null, why on earth would I want that assertion ignored? It sounds like if I'm debugging a piece of production code and suspect that listOfStuff may have been erroneously passed a null but don't see any logfile evidence of that assertion being triggered, I can't trust that listOfStuff actually got sent a valid value; I also have to account for the possibility that assertions may have been turned off entirely. And this assumes that I'm the one debugging the code. Somebody unfamiliar with assertions might see that and assume (quite reasonably) that if the assertion message doesn't appear in the log, listOfStuff couldn't be the problem. If your first encounter with assert was in the wild, would it even occur to you that it could be turned-off entirely? It's not like there's a command-line option that lets you disable try/catch blocks, after all. All of which brings me to my question (and this is a question, not an excuse for a rant! I promise!): What am I missing? Is there some nuance that renders Java's implementation of assert far more useful than I'm giving it credit for? Is the ability to enable/disable it from the command line actually incredibly valuable in some contexts? Am I misconceptualizing it somehow when I envision using it in production code in lieu of statements like if (listOfStuff == null) barf();? I just feel like there's something important here that I'm not getting. *Okay, technically speaking, they're actually off by default; you have to go out of your way to turn them on. But still, you can knock them out entirely.

    Read the article

  • Is there a name for a language feature that allows assignment/creation?

    - by Alex Mcp
    This is a bit hard for me to articulate, but in PHP you can say something like: $myArray['someindex'] = "my string"; and if there is no index named that, it will create/assign the value, and if there IS an index, it will overwrite the existing value. Compare this to Javascript where today I had to do checks like so: if (!myObject[key]) myObject[key] = "value"; I know this may be a bit of a picky point, but is there a name for the ability of PHP (and many other languages) to do these checks on their own as opposed to the more verbose (read: PITA) method of Javascript?

    Read the article

  • java vs python. In what way is Java Better?

    - by oxinabox.ucc.asn.au
    What are the advantages of Java over Python? What are the disadvantagesof Python, over Java? Why isn't Java more like Python? Like why don't java have an command line iterpretor? I beleive Java must have some advantages, but...I'm yet to see them. Logically all languages have an advantage afaict: I learnt java before python, - a 6 month unicourse. I spend a couple of weeks using python (writting a script to make a C source file). I hated it at first (as it was so differnt from C). I realised I had fallen in love it it, when I noticed that when I went to do a follow on Java Course at uni, I'ld stopped giving my variables types, and was tryign to multiply strings.

    Read the article

  • What languages have a while-else type control structure, and how does it work?

    - by Dan
    A long time ago, I thought I saw a proposal to add an else clause to for or while loops in C or C++... or something like that. I don't remember how it was supposed to work -- did the else clause run if the loop exited normally but not via a break statement? Anyway, this is tough to search for, so I thought maybe I could get some CW answers here for various languages. What languages support adding an else clause to something other than an if statement? What is the meaning of that clause? One language per answer please.

    Read the article

  • What is the full "for" loop syntax in C (and others in case they are compatible) ?

    - by fmsf
    I have seen some very weird for loops when reading other people's code. I have been trying to search for a full syntax explanation for the for loop in C but it is very hard because the word "for" appears in unrelated sentences making the search almost impossible to Google effectively. This question came to my mind after reading this thread which made me curious again. The for here: for(p=0;p+=(a&1)*b,a!=1;a>>=1,b<<=1); In the middle condition there is a comma separating the two pieces of code, what does this comma do? The comma on the right side I understand as it makes both a>>=1 and b<<=1. But within a loop exit condition, what happens? Does it exit when p==0, when a==1 or when both happen? It would be great if anyone could help me understand this and maybe point me in the direction of a full for loop syntax description.

    Read the article

  • Cross-Platform Language + GUI Toolkit for Prototyping Multimedia Applications

    - by msutherl
    I'm looking for a language + GUI toolkit for rapidly prototyping utility applications for multimedia installations. I've been working with Max/MSP/Jitter for many years, but I'd like to add a text-based language to my 'arsenal' for tasks apart from 'content production'. (When it comes to actual media synthesis, my choices are clear [SuperCollider + MSP for audio, Jitter + Quartz + openFrameworks for video]). I'm looking for something that maintains some of the advantages of Max, but is lower-level, faster, more cross-platfrom (Linux support), and text-based. Integration with powerful sound/video libraries is not a requirement. Some requirements: Cross-platform (at least OSX and Linux, Windows is a plus) Fast and easy cross-platform GUIs with no platform-specific modification GUI code separated from backend code as much as possible Good for interfacing with external serial devices (micro-controllers) Good network support (UDP/TCP) Good libraries for multi-media (video, sound, OSC) are a plus Asynchronous synchronous UNIX integration is a plus The options that come to mind: AS3/Flex (not a fan of AS3 or the idea of running in the Flash Player) openFrameworks (C++ framework, perhaps a bit too low level [looking for fast development time] and biased toward video work) Java w/ Processing libraries (like openFrameworks, just slower) Python + Qt (is Qt appropriate for rapid prototyping?) Python + Another GUI toolkit SuperCollider + Swing (yucky GUI development) Java w/ SWT Any other options? What do you recommend?

    Read the article

  • What are those little useful ,customize/enhanced php functions that you wish you knew about 2 years

    - by I Like PHP
    Hello All, i like to work in php bcoz it's just amazing language. please share basic, useful, enhanced and customize function that make things better and easy in php and must be used in our all PHP project, i m sharing some of them please share your customize function that may be useful for everyone alternative/ enhanced print_r() and var_dump() function watch( $what ) { echo '<pre>'; if ( is_array( $what ) ) { print_r ( $what ); } else { var_dump ( $what ); } echo '</pre>'; } usage: 1. watch($_POST); // to see all post variable 2. watch($array); // to see any variable may b array, string or a variable enhanced mysql_escape_string() for multidimensional array to prevent sql injection function recursive_escape(&$value) { if (is_array($value)) array_map('recursive_escape', $value); else $value = mysql_escape_string($value); } usage array_map('recursive_escape', $_POST); ---------------------For encoding Get variables-------------------------------------- function nkode($k) { if ( is_array( $k ) ) return array_map("base64_encode",$k); else return base64_encode($k); } ---------------------for decoding varaibles from GET--------------------------------- function dkode($k) { if ( is_array( $k ) ) return array_map("base64_decode",$k); else return base64_decode($k); } Usage <a href="somelink.php?pid=<?php echo nkode($someid)?>"> and on next page(somelink.php) $findID=dkode($_GET[pid]); date convert to mm/dd/yyyy to yyyy-mm-dd( if we use date datatype in mysql) and also change into mm/dd/yyyy to disply on page function dateconvert($date,$func) { if ($func == 1){ //insert conversion list($month, $day, $year) = split('[/.-]', $date); $date = "$year-$month-$day"; return $date; } if ($func == 2){ //output conversion list($year, $month, $day) = split('[-.]', $date); $date = "$month/$day/$year"; return $date; } } usage $firstDate=dateconvert($_POST['firstdate'],1); // for insertion in database $showDate=dateconvert($fetch->date_field,2) // to display on browser to clean data before doing some action with that variable function cleanID($data) { $success=0; $data=trim($data); $data=strtolower($data); $data=strip_tags($data); return $data; } usage cleanID($_POST[username]); cleanID($_GET[pid]); please share any basic function that must be used , and please give me some suggestion to make above function more better Thanks

    Read the article

  • C: 8x8 -> 16 bit multiply precision guaranteed by integer promotions?

    - by craig-blome
    I'm trying to figure out if the C Standard (C90, though I'm working off Derek Jones' annotated C99 book) guarantees that I will not lose precision multiplying two unsigned 8-bit values and storing to a 16-bit result. An example statement is as follows: unsigned char foo; unsigned int foo_u16 = foo * 10; Our Keil 8051 compiler (v7.50 at present) will generate a MUL AB instruction which stores the MSB in the B register and the LSB in the accumulator. If I cast foo to a unsigned int first: unsigned int foo_u16 = (unsigned int)foo * 10; then the compiler correctly decides I want a unsigned int there and generates an expensive call to a 16x16 bit integer multiply routine. I would like to argue beyond reasonable doubt that this defensive measure is not necessary. As I read the integer promotions described in 6.3.1.1, the effect of the first line shall be as if foo and 10 were promoted to unsigned int, the multiplication performed, and the result stored as unsigned int in foo_u16. If the compiler knows an instruction that does 8x8-16 bit multiplications without loss of precision, so much the better; but the precision is guaranteed. Am I reading this correctly? Best regards, Craig Blome

    Read the article

  • Are there legitimate uses for JavaScript's "with" statement?

    - by Shog9
    Alan Storm's comments in response to my answer regarding the with statement got me thinking. I've seldom found a reason to use this particular language feature, and had never given much thought to how it might cause trouble. Now, I'm curious as to how I might make effective use of with, while avoiding its pitfalls... So my question is, where have you found the with statement useful?

    Read the article

< Previous Page | 40 41 42 43 44 45 46 47 48 49 50 51  | Next Page >