Search Results

Search found 2536 results on 102 pages for 'initialize'.

Page 60/102 | < Previous Page | 56 57 58 59 60 61 62 63 64 65 66 67  | Next Page >

  • Best way to make an attribute always an array?

    - by Shadowfirebird
    I'm using my MOO project to teach myself Test Driven Design, and it's taking me interesting places. For example, I wrote a test that said an attribute on a particular object should always return an array, so -- t = Thing.new("test") p t.names #-> ["test"] t.names = nil p t.names #-> [] The code I have for this is okay, but it doesn't seem terribly ruby to me: class Thing def initialize(names) self.names = names end def names=(n) n = [] if n.nil? n = [n] unless n.instance_of?(Array) @names = n end attr_reader :names end Is there a more elegant, Ruby-ish way of doing this? (NB: if anyone wants to tell me why this is a dumb test to write, that would be interesting too...)

    Read the article

  • Extreamely fast way to clone the values of an array into a second array?

    - by George
    I am currently working on an application that is responsible for calculating random permutations of a multidemensional array. Currently the bulk of the time in the application is spent copying the array in each iteration (1 million iterations total). On my current system, the entire process takes 50 seconds to complete, 39 of those seconds spent cloning the array. My array cloning routine is the following: public static int[][] CopyArray(this int[][] source) { int[][] destination = new int[source.Length][]; // For each Row for (int y = 0; y < source.Length; y++) { // Initialize Array destination[y] = new int[source[y].Length]; // For each Column for (int x = 0; x < destination[y].Length; x++) { destination[y][x] = source[y][x]; } } return destination; } Is there any way, safe or unsafe, to achieve the same effect as above, much faster?

    Read the article

  • why a .net 1.1 code gets compiled in 2.0 and throws an error?

    - by Sanjeev
    Hi I have a web projects which is build in VS2003/1.1 framework and deployed in a webserver with IIS setting specified to 1.1 framework.lets say project X I also have another web project which is build with VS2008/2.0. IIS setting - ASP version 2.0 is selected and all pages are assigned to run with 2.0* dlls. Lets say project Y Now the problem seem to be when I hit project x, sometimes it throws errors like "error BC30456: 'Initialize Culture' is not a member of 'ASP.**" During troubleshooting this issue, I browsed through 2.0 Temporary ASP.Net files "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\" and found temp files generated for project X. (HUH?) How/why 1.1 project gets compiled in 2.0 only when it errors out.( or we could put it this way that it errors out every time it gets compiled in 2.0 which it is not supposed to) I'm confused as to why this is happening when project X has nothing to do with .net 2.0.

    Read the article

  • How can I store and access SQLite databases from a central location?

    - by Brian Ramsay
    I have installed SQLite on my UNIX system, and am planning on accessing it from PHP. However, the database is created in the directory I initialize it in, and if a script runs in a different directory a new database is created in the same directory. Is there an option for SQLite (or the PHP wrappers) to create the databases in one location, and have those databases accessible just by name outside of that directory? Ideally, I'd like to be able to do something like $db=new SQLiteDatabase("db.test"); in any directory and have it reference the same database, if that makes sense.

    Read the article

  • [C++] Run codes for only 60 times each second.

    - by djzmo
    Hello there, I'm creating a directx application that relies on the system time (because it must be accurate), and I need to run lines of code for 60 times each second in the background (in a thread created by boost::thread). that's equal to 60 FPS (frame per second), but without depending on the main application frame rate. //................. void frameThread() { // I want to run codes inside this loop for *exactly* 60 times in a second. // In other words, every 16.67 (1000/60) milliseconds for(;;) { DoWork(); //......... } } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { initialize(); //.....stuffs boost::thread framethread(frameThread); //...... } Is there a way to do this? Any kind of help would be appreciated :)

    Read the article

  • Ruby forwarding method calls

    - by JP
    I have an instance of a master class which generates instances of a subclass, these subclasses need to forward some method calls back to the master instance. At the moment I have code looking something like this, but it feels like I should be able to do the same thing more efficiently (maybe with method_missing?) class Master def initalize(mynum) @mynum = mynum end def one_thing(subinstance) "One thing with #{subinstance.var} from #{@mynum}" end def four_things(subinstance) "Four things with #{subinstance.var} from #{@mynum}" end def many_things(times,subinstance) "#{times} things with #{subinstance.var} from #{@mynum}" end def make_a_sub(uniqueness) Subthing.new(uniqueness,self) end class Subthing def initialize(uniqueness,master) @u = uniqueness @master = master end # Here I'm forwarding method calls def one_thing master.one_thing(self) end def four_things master.four_things(self) end def many_things(times) master.many_things(times,self) end end end m = Master.new(42) s = m.make_a_sub("very") s.one_thing === m.one_thing(s) s.many_things(8) === m.many_things(8,s) I hope you can see what's going on here. I would use method_missing, but I'm not sure how to cope with the possibility of some calls having arguments and some not (I can't really rearrange the order of the arguments to the Master methods either) Thanks for reading!

    Read the article

  • C++0x: how to get variadic template parameters without reference?

    - by Sydius
    Given the following contrived (and yes, terrible) example: template<typename... Args> void something(Args... args) { std::tuple<Args...> tuple; // not initializing for sake of example std::get<0>(tuple) = 5; } It works if you call it like so: int x = 10; something<int>(x); However, it does not work if you call it like this: int x = 10; something<int&>(x); Because of the assignment to 5. Assuming that I cannot, for whatever reason, initialize the tuple when it is defined, how might I get this to work when specifying the type as a reference? Specifically, I would like the tuple to be std::tuple<int> even when Args... is int&.

    Read the article

  • how to redirect on youtube in androi

    - by rajshree
    public class MovieDescription extends Activity { Vibrator vibrator; TextView tv_title,tv_year,tv_banner,tv_desc; RatingBar ratingBar; ImageView iv_watch,iv_poster; private static final String TAG_CONTACTS = "Demo"; private static final String TAG_ID = "id"; private static final String TAG_TITLE = "title"; private static final String TAG_YEAR = "year"; private static final String TAG_RATING = "rating"; private static final String TAG_BANNER= "category"; private static final String TAG_DESC = "description"; private static final String TAG_URL = "url"; private static final String TAG_POSTER = "poster"; String id,title,year,rating,banner,description,poster, movieUrl; static JSONArray contacts = null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.movie_description); initialize(); String movieDescUrl = "http://vaibhavtech.com/work/android/movie_description.php?id="+MainActivity.movie_Id; MovieDescriptionParser jParser = new MovieDescriptionParser(); JSONObject json = jParser.getJSONFromUrl(movieDescUrl); try { contacts = json.getJSONArray(TAG_CONTACTS); for (int i = 0; i < contacts.length(); i++) { /**********************************Value Parse FromUrl**********************************/ JSONObject c = contacts.getJSONObject(i); id = c.getString(TAG_ID); title = c.getString(TAG_TITLE); year = c.getString(TAG_YEAR); rating = c.getString(TAG_RATING); banner=c.getString(TAG_BANNER); description = c.getString(TAG_DESC); movieUrl = c.getString(TAG_URL); poster = c.getString(TAG_POSTER); /**********************************Valeu Assing to UI Component**********************************/ Log.i(id, title); } } catch (JSONException e) { e.printStackTrace(); } tv_title.setText(title); tv_year.setText(year); tv_banner.setText(banner); tv_desc.setText(description); Float rat=Float.parseFloat(rating); ratingBar.setRating(rat); Bitmap bimage= getBitmapFromURL("http://vaibhavtech.com/work/android/admin/upload/"+poster); iv_poster.setImageBitmap(bimage); iv_watch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub vibrator.vibrate(40); LayoutInflater inflater=getLayoutInflater(); View view=inflater.inflate(R.layout.customtoast,(ViewGroup)findViewById(R.id.custom_toast_layout)); Toast toast=new Toast(getApplicationContext()); toast.setDuration(Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0); toast.setView(view); toast.show(); Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(movieUrl)); startActivity(intent); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub int currentapiVersion = android.os.Build.VERSION.SDK_INT; Log.i("Device Versoin is", ""+currentapiVersion); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN){ ActionBar actionBar = getActionBar(); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); getMenuInflater().inflate(R.menu.main, menu); } return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub switch (item.getItemId()) { case android.R.id.home: onBackPressed(); return true; case R.id.home: Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); Log.i("Home", "Press"); return true; } return super.onOptionsItemSelected(item); } public void initialize() { tv_banner=(TextView) findViewById(R.id.tv_movie_description_banner); tv_desc=(TextView) findViewById(R.id.tv_movie_description_decription); tv_title=(TextView) findViewById(R.id.tv_movie_description_name); tv_year=(TextView) findViewById(R.id.tv_movie_description_year); ratingBar=(RatingBar) findViewById(R.id.ratingBar1); iv_watch=(ImageView) findViewById(R.id.iv_movie_description_watch); iv_poster=(ImageView) findViewById(R.id.iv_movie_description_poster); vibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);; } public static Bitmap getBitmapFromURL(String src) { try { Log.i("src",src); URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); Bitmap myBitmap = BitmapFactory.decodeStream(input); Log.i("Bitmap","returned"); return myBitmap; } catch (IOException e) { e.printStackTrace(); Log.e("Exception",e.getMessage()); return null; } } } when i am clciking on watch now button its giving me 4 options -by mozilz,by chrome,by youtube, i want that when i click on watch now button it get redirect on youtube url link,..how can i do this please give me any suggetion.:(

    Read the article

  • Obj-C memory management for an NSView * instance variable

    - by massimoperi
    My custom view has a subview as an instance variable. Here is a sample interface: @interface MyCustomView : NSView { NSView *aSubview; } @end Then, in the .m file, I initialize aSubView and add it to the custom view. - (id)init { self = [super initWithFrame:CGRectMakeFrame(0.0, 0.0, 320.0, 480.0); if (self) { aSubview = [[NSView alloc] initWithFrame(0.0, 0.0, 100.0, 100.0); [self addSubview:aSubview]; } return self; } Where should I release aSubView? In the -dealloc method? - (void)dealloc { [aSubView release]; [super dealloc]; } Or directly after adding it to the custom view in the -init method? - (id)init { [...] [self addSubview:aSubview]; [aSubview release]; [...] } Which one is the best implementation?

    Read the article

  • In C# is there a thread scheduler for long running threads?

    - by LogicMagic
    Hi, Our scenario is a network scanner. It connects to a set of hosts and scans them in parallel for a while using low priority background threads. I want to be able to schedule lots of work but only have any given say ten or whatever number of hosts scanned in parallel. Even if I create my own threads, the many callbacks and other asynchronous goodness uses the ThreadPool and I end up running out of resources. I should look at MonoTorrent... If I use THE ThreadPool, can I limit my application to some number that will leave enough for the rest of the application to Run smoothly? Is there a threadpool that I can initialize to n long lived threads?

    Read the article

  • How is does this module code work?

    - by phsr
    I'm new to ruby and I am trying to figure out how the following code works The following code is inside a class in a module. The method is called later with the following code: @something ||= Module::Class.config class << self def config &block options = OpenStruct.new yield options if block_given? init_client! Client.new(options) end def init_client!(client) base_eigenclass = class << Base; self; end base_eigenclass.send :define_method, :client do @client = client end client end end The class has some constants in it, and when the classes initialize is called, the instance member are set to option.variable || VARIABLE_CONSTANT. I understand that if there is no value for option.variable then VARIABLE_CONSTANT is used, but I don't understand that calling Module::Class.config do |options| #some block end set the @client until config is called again with options The code definitely works, but I want to understand how it does

    Read the article

  • Is void *p = 0L valid?

    - by Artefacto
    In this answer, sassman initializes a pointer with: zend_class_entry* ce = 0L; My question is – is this valid? I would say it isn't, to initialize the variable with a null pointer either an unadorned (and possibly casted to void *) 0 constant, or some macro that evaluates to that such as NULL should be used. However, I can't find definitive language in the standard that supports this interpretation. All it says is: An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.

    Read the article

  • In Ruby, how do I make a hash from an array?

    - by Wizzlewott
    I have a simple array: arr = ["apples", "bananas", "coconuts", "watermelons"] I also have a function f that will perform an operation on a single string input and return a value. This operation is very expensive, so I would like to memoize the results in the hash. I know I can make the desired hash with something like this: h = {} arr.each { |a| h[a] = f(a) } What I'd like to do is not have to initialize h, so that I can just write something like this: h = arr.(???) { |a| a => f(a) } Can that be done?

    Read the article

  • How to manage member variable in C++

    - by rhapsodyn
    In brief, my question is about member variables as pointers in unmanaged C++. In java or c#, we have "advanced pointer". In fact, we can't aware the "pointer" in them. We usually initialize the member of a class like this: member = new Member(); or member = null; But in c++, it becomes more confusing. I have seen many styles: using new, or leave the member variable in stack. In my point of view, using boost::shared_ptr seems friendly, but in boost itself source code there are news everywhere. It's the matter of efficiency,isn't it? Is there a guildline like "try your best to avoid new" or something?

    Read the article

  • How does this module code work?

    - by phsr
    I'm new to ruby and I am trying to figure out how the following code works The following code is inside a class in a module. The method is called later with the following code: @something ||= Module::Class.config class << self def config &block options = OpenStruct.new yield options if block_given? init_client! Client.new(options) end def init_client!(client) base_eigenclass = class << Base; self; end base_eigenclass.send :define_method, :client do @client = client end client end end The class has some constants in it, and when the classes initialize is called, the instance member are set to option.variable || VARIABLE_CONSTANT. I understand that if there is no value for option.variable then VARIABLE_CONSTANT is used, but I don't understand that calling Module::Class.config do |options| #some block end set the @client until config is called again with options The code definitely works, but I want to understand how it does

    Read the article

  • Running a packaged exe in the same folder as the installed firefox extension

    - by mustafabar
    I have read this thread, and some other How to run a local exe in my firefox extension The problem is, at deployment and using firefox 4.0.1, if I install the .xpi extension, the xpi is put inside the \Profiles...\extensions as **.xpi, which is a compressed format All the solutions assume that the the extension is put in a folder, thus they are accessing the folder as is, which I cannot do for example this guy says //**** get profile folder path **** var dsprops = Components.classes['@mozilla.org/file/directory_service;1'] .getService(Components.interfaces.nsIProperties); var ProfilePath = dsprops.get("ProfD", Components.interfaces.nsIFile).path; //**** initialize file **** var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath(ProfilePath); //**** append each step in the path **** file.append("extensions"); file.append("guid"); file.append("sample.exe"); guid in my case is installed as {f13b157f-b174-47e7-a34d-4815ddfdfeb8}.xpi which cannot be accessible this way

    Read the article

  • NSString inheritance

    - by Stef
    Hi, I'm doing an useless thing for my first step in Obj-C @interface String : NSString { int m_isnull; } - (id) init; - (int) isNull; @end @implementation String - (id) init { self = [super init]; m_isnull=1; return self; } - (int) isNull { return m_isnull; } @end test : String *a; a=@"ok"; Works fine, but just 2 little questions 1) When I'm compiling I have this warning warning: incompatible Objective-C types assigning 'struct NSString *', expected 'struct String *' I don't know how to avoid it !? 2) a=@"ok" is a fastest way to initialize a string, but when I'm debugging, I don't stop by at my init constructor why ?

    Read the article

  • Understanding memory leak in Android app.

    - by sat
    After going through few articles about performance, Not able to get this statement exactly. "When a Drawable is attached to a view, the view is set as a callback on the drawable" Soln: "Setting the stored drawables’ callbacks to null when the activity is destroyed." What does that mean, e.g. In my app , I initialize an imageButton in onCreate() like this, imgButton= (ImageButton) findViewById(R.id.imagebtn); At later stage, I get an image from an url, get the stream and convert that to drawable, and set image btn like this, imgButton.setImageDrawable(drawable); According to the above statement, when I am exiting my app, say in onDestroy() I have to set stored drawables’ callbacks to null, not able to understand this part ! In this simple case what I have to set as null ? I am using Android 2.2 Froyo, whether this technique is required, or not necessary.

    Read the article

  • What is the differance between those two Strings in Java

    - by user1816808
    why when we declare string in java we can't use == to compare this string and always will turn to false while if we initialize the string from the beginning it will be true . for example : import java.util.Scanner; public class MyString { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); String s = input.nextLine(); if(s=="Hello") system.out.println("Hello"); String d = "Hello"; if(d=="Hello") system.out.println("Hello"); } } I need an explanation please ??

    Read the article

  • Python - multi-line array

    - by Ockonal
    Hi guys, in c++ I can wrote: int someArray[8][8]; for (int i=0; i < 7; i++) for (int j=0; j < 7; j++) someArray[i][j] = 0; And how can I initialize multi-line arrays in python? I tried: array = [[],[]] for i in xrange(8): for j in xrange(8): array[i][j] = 0

    Read the article

  • Why don't hardware failures show up at the programming language level?

    - by Julian Cienfuegos
    I am wondering if anyone can give my a good answer, or at least point me in the direction of a good reference to the following question: How come I have never heard of a computer breaking in a very fundamental way? How come when I declare x to be a double it stays as a double? How come there is never a short circuit that robs it of some bytes and makes it an integer? Why do we have faith that when we initialize x to 10, there will never be a power surge that will cause it to become 11, or something similar? I think I need a better understanding of memory. Thanks, and please don't bash me over the head for such a simple/abstract question.

    Read the article

  • Problem with NSMutableArray?

    - by RRB
    Hi, i initialize instance variables in .h file, NSInteger saveValue0, saveValue1, saveValue2, saveValue3; NSMutableArray *nodeArray; Now in .m file, in viewWillAppear event, saveValue0 = 0; saveValue1 = 2; saveValue2 = 3; saveValue3 = 0; nodeArray = [[NSMutableArray alloc] initWithObjects:saveValue0, saveValue1, saveValue2, saveValue3, nil]; But above variable does not inserted in the array. When i trying to see the objects in array using break point, it gives me 0 objects present in nodeArray. Why it will give me 0 objects. Any reason behind that?

    Read the article

  • Running a loop (such as one for a mock webserver) within a thread

    - by bob c
    I'm trying to run a mock webserver within a thread within a class. I've tried passing the class' @server property to the thread block but as soon as I try to do server.accept the thread stops. Is there some way to make this work? I want to basically be able to run a webserver off of this script while still taking user input via stdin.gets. Is this possible? class Server def initialize() @server = TCPServer.new(8080) end def run() @thread = Thread.new(@server) { |server| while true newsock = server.accept puts "some stuff after accept!" next if !newsock # some other stuff end } end end def processCommand() # some user commands here end test = Server.new while true do processCommand(STDIN.gets) end In the above sample, the thread dies on server.accept

    Read the article

  • Execute code when Eclipse workbench loads

    - by Krt_Malta
    Hi! I'm writing an Eclipse plug-in and I've bumped into an issue. Amongst others I'm creating a new custom perspective. I need to execute some code when the workbench loads. I'm using a WorkbenchAdvisor and putting the code in the initialize method. However as it is now it's not being called... Apparently I need to call this PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor(); but I don't know where to put this... I can't put it in the createInitialLayout of the perspective because this is only called when the perspective is created for the first time. Any ideas please? Thanks and regards, Krt_Malta

    Read the article

  • UITable View Issue,

    - by abc
    hello i am having same issue, i tried your solution but it didnt help me in my case.. i am not getting exception but view is not getting changed.. my piece of code is as below printf("hi"); //Get the selected country NSString *selectedCountry = [listOfItems objectAtIndex:indexPath.row]; //Initialize the detail view controller and display it. DetailViewController *aSecondView = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil]; // aSecondView.selectedCountry = selectedCountry; [self.navigationController pushViewController:aSecondView]; [aSecondView release]; aSecondView = nil; printf("bye.."); both hi and bye gets printed but view doesnt change.. i have wasted 2 days around it .. plz help me out..

    Read the article

< Previous Page | 56 57 58 59 60 61 62 63 64 65 66 67  | Next Page >