w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Create temporary directory for Junit test in static method for theory
Try using the @BeforeClass annotation on a method to setup the required directory or files as fields of the test class. The @AfterClass annotation can then be used to tear them down. private static File directory; @BeforeClass public static void setup() { directory = new File("/path/to/file"); if(!directory.exists()){ directory.mkdir(); } } @AfterClass public static void teardown() { if(directory.exists()){ FileUtils.deleteDirectory(directory); //apache-commons-io } } @BeforeClass Sometimes several tests need to share computationally expensive setup (like logging into a database). While this can compromise the independence of tests, sometimes it is a necessary optimization. Annotating a public static void no-arg method with

Categories : Java

Verifying the calling of a non-static method of a private static nested class of a static outer class
Since you said you wanted to find out if you're trying to invoke a non-static method at runtime, then this bit of reflection should help. Assuming m is the Method instance corresponding to your method, then Modifier.isStatic(m.getModifiers()) will return true if and only if the method is static, so you can do this check before you actually call invoke. If you don't already have the Method object, then something like Class's getMethod will be of use to you. Docs on Method, Modifier, and Class. EDIT: All of the above is helpful for checking whether or not the method is static before you call it via invoke. If you want to use something like jmockit to be able to find out that such a method has been called, then I'm personally wondering how that'll help the IllegalArgumentException that y

Categories : Java

Private static variable
Why we have to declare static member function to access private static variable? You don't have to: class Something { private: static int s_nValue; public: static int staticAccess() { return s_nValue; } int Access() { return s_nValue; } }; int Something::s_nValue = 1; // initializer int main() { Something s; Something::staticAccess(); s.Access(); return 0; } Both methods work as can bee seen here That being said, it doesn't really make sense to make a non-static member function to access a static variable (as you would need an instance of the class to be able to call it).

Categories : C++

C# private method as static
This is what MSDN say A call to a static method generates a call instruction in Microsoft intermediate language (MSIL), whereas a call to an instance method generates a callvirt instruction, which also checks for a null object references. However, most of the time the performance difference between the two is not significant. Which in simpler word means that there will some performance gain.

Categories : C#

private constructor for static methods
The error is happening because you're trying to create an anonymous inner class in a static context: private static final List<String> APPROVED_LENGTH= new ArrayList<String>() { { addAll(KM_APPROVED_LIST); addAll(LM_APPROVED_LIST); } }; I'm surprised that the compiler allows this to happen, but I suppose it doesn't do a lot of semantic checks (ie, verifying that the class can be instantiated). Regardless, here's how to fix it (and a better way to initialize static lists/maps in general): private static final List<String> APPROVED_LENGTH= new ArrayList<String>(); static { addAll(KM_APPROVED_LIST); addAll(LM_APPROVED_LIST); };

Categories : Java

Is that valid to use private static callbacks in PHP?
Very strange. I played around with it a bit dropping stack traces inside the callback. Thought maybe it was the static calls that were letting it play loose with visibility, but: class MyClass { private static $data = array( 'banana', 'cherry', 'apple' ); private function sort_by_text( $first, $second ) { return strcasecmp( $first, $second ); } public function sorted_data() { usort( self::$data, array( __CLASS__, 'sort_by_text' ) ); return self::$data; } } class MyClass2 { public function __construct() { $mc = new MyClass(); print_r($mc->sorted_data()); } } $bleh = new MyClass2(); This works too, and the call stack looks as it should. That's PHP for you. Of course, I'd forgo the whole mess and just use a closure now.

Categories : PHP

Shall we mark private methods as "static" as more as possible?
Personally, I would mark it as static but it is not an extreme performance benefit, and is more organizational. If you work better with it static, make it static. If you are better with it being an instance method anyway, by all means do so. It's marked private, so you're free to do whatever you need/prefer to do to make it work. While it is certainly acceptable to mark your private methods as static when appropriate, there is no need to try to persuade others to do this. Private methods are designed so others' private methods need not concern you here, as would be in your case. There's no need to beg FooDev to make his method static, as he's the only one calling it anyway.

Categories : Java

Factory static methods and private constructors
The what you want to do is make Foo a singleton and make Bar assign to bar by Foo::getInstance(); For example: class Foo { private static $instance; private function __construct(){} public static function getInstance(){ if (!isset(self::$instance)){ self::$instance = new Foo(); } return self::$instance; } public function __clone(){ throw new Exception("Cannot Clone Singletons... bad programmer"); } } class Bar { static function getFooInstance() { return Foo::getInstance(); } } There is no need to replay the singleton pattern within Bar as Foo already polices it's own instantiation.

Categories : PHP

Jquery get url not fixed/static
At the time of dynamic generation of the file on the server, also write the path of the file in a static file. Use the client to retrieve the path from the static file and then make the actual request to the dynamically generated file. hope i understood your question right.

Categories : Javascript

(Mis)usage of private constructor and static methods (Java)?
This looks like a singleton pattern. It is part of the great familly of designs patterns you might know them. The point of this is to ensure that there is only one instance of this object used throughout your application. Indeed when you call getManager() it will return a new instance the first time and next times it will return the formerly created instance.

Categories : Java

C++ Private structure and non static const variables initialization
You cannot initialize class members when you declare them. Instead, you need a constructor: struct someStruct { someStruct(): next(NULL), number(0) {} someStruct *next; int number; }; Alternatively, for POD (plain old data), you could use your original class with no constructors and use someStruct *newElement = new someStruct(); to create a someStruct. This initializes the members to zero. Also, C++11 supports in-class member initializers.

Categories : C++

How to allow public or private downloads of static files with PHP 5.4 Web Server?
if(php_sapi_name() === 'cli-server') { if(is_file(__DIR__.preg_replace('#(?.*)$#', '', $_SERVER['REQUEST_URI']))) { return false; } } The solution for PHP 5.4 web server, along with starting the server itself with: php -S localhost: 80 -t /path/to/web /path/to/web/index.php This way, if /css/style.css exists it will be served statically, but /files/dynamic.css will pass through the front controller.

Categories : PHP

Calling a private static variable in java from a different class
So the above code runs and then from another class I call Test.returnValue(); and this returns 0 When you say above code runs, does not mean that your test method will execute automatically, without being called from anywhere. If you call your test method first and then try to get the Test.returnValue() then the value should not be 0.

Categories : Java

Should I use static fields or private using an instance of the class to access
It all depends on how you want to use the members of your class and how you want control access to those members. It has nothing to do with writing less code. In the example you provided if you wanted to use the same DataSet across all instances of "myClass", or across the your application if the property were public/internal, then make it static. If you require a new DataSet each time you create an instance of "myClass", then make it non-static.

Categories : C#

specify a point where to change from static to fixed
That is because when you reach the .footer $(window).scrollTop() is still bigger than stickyRibbonTop and your code will never get to the part where it sets position back to static. Try switch conditions jQuery(window).scroll(function(){ if(jQuery(window).scrollTop() > jQuery('.footer').offset().top) { jQuery('.content_to_stick').css({position: 'static', top: '0px'}); } else if(jQuery(window).scrollTop() > stickyRibbonTop) { jQuery('.content_to_stick').css({position: 'fixed', top: '0px'}); } else { jQuery('.content_to_stick').css({position: 'static', top: '0px'}); } });

Categories : Javascript

How to access a private member inside a static void* function
A function declared static in a class isn't associated with any instance of this class (i.e. there's no this pointer accessible within its body). Thus you just can't access any non-static member variable (be it private, protected or public, it doesn't matter). Either make your function non-static (and call it on an instance of your class), or make the boost::unordered_map static. (As I don't know what you really want to do, you'll have to figure out which method fits your need)

Categories : C++

MySQL fixed ids for categories, how to ensure they are static
Yes, this is what foreign key constraints are for. They also allow for rules on how to handle deletes -- for example, allowing a delete to cascade through dependent records, which is of course very dangerous and not what you would want in this situation. A simple basic constraint will do. HOWEVER!!!! This is the important thing to understand about mysql. The default mysql engine (myisam) has absolutely no support for foreign key constraints. You need to use an engine that supports them -- most commonly innodb. If you specify a constraint when you're generating your DDL, a myisam table will accept the constraint but simply ignore it, so make sure all your related tables are setup/altered to be innodb tables before you add your constraint(s). How do you add a constraint? ALTER TABLE

Categories : Mysql

How to keep first element from jCarousel static or fixed to it's position?
.stays-at-top { background-color: #f99; position: fixed; width: 200px; } FIDDLE DEMO

Categories : PHP

Bootstrap:Fixed nav-static-top on top but scrollable nav-collapse
This doesn't completely fix your problem, but it definitely looks better if you do this: <div class="nav-collapse collapse navbar-responsive-collapse" style="overflow-y: scroll;max-height:400px"> <ul class="nav"> instead of <div class="nav-collapse collapse navbar-responsive-collapse"> <ul class="nav" style="overflow: scroll;max-height:400px"> I don't know about doing it on Android, but if it really doesn't work this way, you'll probably have write some JS or something.

Categories : Javascript

Java Classloaders - Invoking a static method inside a private class
The classloader isn't creating a new instance: you're telling the VM to create a new instance here: Object mainMethodInstance = mainClass.newInstance(); Don't do that. Just pass in null as the target of the static method call: Object result = mainMethod.invoke(null, serverArgConverted);

Categories : Java

Static and Sticky fixed header transition misfunction
Not sure what you mean by background, as all backgrounds in the CSS you show are solid. Binding an event to scroll with jQuery's .on() can get slow on some browsers. Meaning that it won't fire as often as it should, delaying any function bound the the scroll event. Also, since you're taking 1000ms to fade in the div, that will make the delay seem longer.

Categories : Jquery

Jackson fails to ignore private static field with complex object type
This is not a jackson problem, it is in your classpath. It is a static field thus it will be initialized when the class is loaded. The error says it does not find discoversingleton class, you need the jar containing this class in your classpath. Nothing to do with Jackson

Categories : Java

jquery fixed position block, swtich to static certaint point
Try using the distance between the bottom block's offset.top() and the current document's scrollTop(). The following code is supposed to work. Notice you can set multiple settings with the same .css() call. Also notice the second if condition was redundant and could be replaced with an else condition. The logic is that if the scrollTop has reached 550px, but the bottom content starts from 500px, the #fixed_content element will start from top: -50px. That way we're preventing the overflowing. var top_positio_saver = $('#fixed_content').offset().top; $(document).on('scroll', function() { if (top_positio_saver <= $(document).scrollTop()) { var distance = $('#bottom_content').offset().top - $(document).scrollTop(); var newTop = Math.min(0, distance); $('#fixed_content').c

Categories : Javascript

If a class is not used directly from main yet has a static private member could it be left out when compiling and linking with maximal optimization?
The behaviour differs between compilers. Some years ago I implemented such as factory in some code that was compiled on different platforms. It worked fine on the platform where I first wrote it but failed totally on the next one. If I remember correctly it was GCC that worked and msvc that eliminated the entire class. So m don't trust compilers and linkers to behave the same. You have to test each one to know.

Categories : C++

Connection and authentication with usb 3g dongle using at-commands
What exactly do you expect? You get a connection and you are free to exchange data using one of the virtual serial ports. You may get an interface if you use something like DirectIP by SierraWireless, but then you need a driver for that. Still, you get an interface and I'm not sure if you don't need to ask for an IP using DHCP.

Categories : Misc

Does Android 4.2.2 support usb bluetooth dongle?
It is my understanding that Android dropped BlueZ and it now relies on bluedroid by broadcom, I don't know how but what I would do is look for the drivers for that bt dongle online and build the system with: PRODUCT_COPY_FILES += drivers on your AndroidProducs.mk file

Categories : Android

USB Bluetooth Dongle isn't recognized by BeagleBone Black
In case you are running a 3.8 kernel: usb hotplugging seems to have issues. no. 1 recommendation is booting the BBB with the usb device plugged in already until hotplugging is fixed. the power adapter should be sufficient with 2.5 amps.

Categories : Misc

Linux: Start daemon on connected USB-serial dongle
Create a udev rule like # cat /etc/udev/rules.d/95-serialdaemon.rules KERNEL=="ttyUSB0", ENV{SYSTEMD_WANTS}="serialdaemon.service" Create a systemd service like # cat /lib/systemd/system/serialdaemon.service [Unit] Description=USB serial to socket bridge After=remote-fs.target After=syslog.target [Service] ExecStart=/mnt/serialdaemon.sh Create the executable file # cat /mnt/serialdaemon.sh #!/bin/sh date +%F-%T >> /var/log/serialdaemon.log /usr/local/serialdaemon/serialdaemon -serial /dev/ttyUSB0 -port 15789 -baud 38400 >> /var/log/serialdaemon.log 2>&1 date +%F-%T >> /var/log/serialdaemon.log

Categories : Linux

can we use Bluetooth dongle both on Host (xp) and Guest android OS at a time
I think what you want to do is not possible (I also wanted to do it but couldn't make it work). What would be interesting, is if it's possible to connect 2 separate BT dongles to a single computer and get them to pair.

Categories : Android

Casting without dongle and multi device "screen sharing"
I suspect you are confusing chrome the web browser (https://en.wikipedia.org/wiki/Google_Chrome) with chrome the operating system (http://en.wikipedia.org/wiki/Chrome_OS). Chromecast as currently available is only good for accepting comands from compatible software (chrome the browser, the youtube app on android or ios etc) at which point it then streams the requested data from the internet, not from your phone/tablet/computer. Your idea is not supported, which is stunning as Android has had built in support for screen mirroring via miracast since v4.2. There's also no mention of direct content streaming, for instance via DLNA, an open protocol designed for EXACTLY THAT. In fact, a better approach here would have been to make the chromecast dongle a DLNA device and then implement support

Categories : Google Chrome

Is there any pattern that provide similarities of public static, private and public methods and vars in JS?
"Static" methods in JavaScript are usually achieved by simply assigning a function to a property of the constructor function object: function MyClass() {} // Constructor MyClass.staticMethod = function () {};

Categories : Javascript

Mocking private static method from a final class (utility class)
Here is an example using PowerMock to mock public static methods. In case of a private method there must be some public static method somewhere to mock that calls this private method, as you can not call it directly. If you are only interested in an exception, you might throw the exception earlier (maybe - many assumptions)

Categories : Java

how to send voice from microphone or play recorded audio from hsdpa dongle C#
For your modem, you have 3 COM port available. One is for sending AT command, the second one is for sending data (voice data), and the last one is for monitoring the asynchronous status change. When you place a call (with ATD), you'll have to wait for "^CONN: 1, 0" on the monitoring port. Then you need a sound source with 8KHz, 16 bit signed, 1 channel. Write 320 bytes of this source on the data port, each 20ms. You'll also read 320 bytes of data from this port, each 20ms for the other side speaking. When you get "^CEND: ...", then the call is terminated. Beware of few catch however. You'll get "^CONN: 1, 0" even if the other side rejected you call. So, try to read data from the data port first to check if the other side is still there after a ^CONN message.

Categories : C#

When to declare a spring bean as private static when the bean is singleton?
If by declaring the bean as static, you mean something like @Bean public static MyBean myBean() { return new MyBean(); } then the benefit of this is to have your bean generated before the instance method beans. You would use this for example with a BeanFactoryPostProcessor which states: Application contexts can auto-detect BeanFactoryPostProcessor beans in their bean definitions and apply them before any other beans get created. The Spring Java configuration way for these to be auto-detected and initialized before the rest of your beans is to declare and initialize them with static methods. For example, @Bean public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { return new PropertySourcesPlaceholderConfigurer(); } Spring will de

Categories : Spring

how to mock a class's inner static class's private field
You can use reflection to access and modify any property of any object you want. There are several questions on SO that answer this quite well already, for example: Change private static final field using Java reflection. Accessing private variables in Java via reflection Instantiate private inner class with java reflection

Categories : Testing

Static or relatively positioned element that respects height of position:fixed element?
Just to put the answer as an actual answer: No, there is no way to have a static/relative element respect the height of the position:fixed element without using JavaScript. You can do this pretty easily with something like the following jsfiddle: $('#not-fixed').css('padding-top', $('#fixed').outerHeight() + 10); http://jsfiddle.net/VYrsU/1/

Categories : HTML

CSS footer in theory
#footer { position: fixed; width:100%; bottom: 0; /* <--- distance from #footer's bottom to #page's bottom */ height: 3em; margin: 0; padding: 1em; background-color: #00F; }

Categories : CSS

Theory of how to sync. (two) databases
The theory behind true replication (something like MySQL to MySQL) is very complicated and difficult. I wouldn't recommend trying to implement something like that for MySQL to SQL Server. Some things to look at: Look at Mule ESB (http://www.mulesoft.org/) You can get off the ground pretty fast with JDBC connections to MySQL and SQL Server. Then it's just a matter of how often you want to poll one endpoint to push to another endpoint. (For example, poll MySQL every 15 minutes and take the results and write to SQL Server.) You can write your own syncing program. Maybe export data from one system every 15 minutes and write to the file system. Have another program watch that directory and import anything it sees. (Disadvantage is you have to touch the disk.) To be really creative, you can w

Categories : Database

NUnit Theory with an exception
You should be able to achieve your requirements with this: enum ABigEnum { A, B, C, D } [Theory] public void Test(ABigEnum enumValue) { bool someValue = enumValue != ABigEnum.D; Assert.That(someValue, Is.True, "an amazing assertion message"); } This will give you false when passing in D and true for all other values. Because this logic is not something that can "known" by the system you will have to make some kind of decision whether it is an if / else or switch. However, this "Test" looks more like a method than a pure test and you might want to re-think what it is you are testing and trying to achieve because as you highlight you don't really want a lot of logic in a test.

Categories : C#

PayPal IPN theory and method
I'd go with Method 1. Writing a script to keep your tables/images clean should be trivially easy. with Method 2, I'd question whether PayPal would pass all that data around for you. Method 1 is much cleaner. Another option would be to store unpaid ads in a temporary table that mirrors the paid for one. You could use the temporary table for previews and such. When the IPN POST comes in, just copy data from temporary holding table to the live table. Then, as with method 1, run a cron job every few days to clear up old/unpaid items.

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.