w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Running only one instance of an application,(Quit new instance and Display old instance or give Focus)
What you need to do is to add this to your main class: [DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr hWnd); Then you need to obtain a reference to the process that is already running, and then call the SetForegroundWindow method like this: SetForegroundWindow(SameProcess.MainWindowHandle); You do not need to kill the current process like you are currently doing, just return after focusing the other process' main window as shown above This is a full working example: [DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr hWnd); /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { var currentProcess = Process.GetCurrentProcess(); foreach (Process p in Process.GetP

Categories : C#

Adding SSH Keys to remote servers
I think yo want to copy the users' public keys to the server and then add'em to the ssh, right? To do that you need to do the following: Copy keys to server copy from my machine to a remote machine: scp key_name.pub git@serverIP:key_name.pub Then cat it to the authorized_keys file cat key_name.pub >> .ssh/authorized_keys

Categories : GIT

Why this Interface Instance give error when reference to an class Instance which implement that interface
You get this error because ClassA does not implement Interface B. Always remember that a parent type in java can refer to Subtype. Type IntefaceB is no way related to type ClassA here. And for below to work InterfaceB obj = new ClassA(); ClassA need to have its parent type to be InterfaceB(either directly or by anyother type which implements InterfaceB(a class) or extends InterfaceB(interface).

Categories : Java

Best way to make sql server instance available remotely? Linked Servers or replication? Other?
Not really an answer but I have more space... SQL Azure is a the 'cloud' version of SQL Server. A VPN is a way of creating your own private network over the internet. Do some research on these terms. Many applications are going cloud nowadays. You should really consider the likelihood that there will be no internet access. With regards to replication, you can 'roll your own' replication if you own this application and you are happy to support it. The basic premise is: Create a trigger on every table which writes the PK of every change to a log table Create a process which manages copying and merging only changed info (based on the log table) using subscribers and publishers

Categories : C#

Give key names to an array with numerical keys
The answer here is to use array_combine($keys, $values); Note that the function will fail if the number of elements in the $keys and $values array are different.

Categories : PHP

How do I give my instance variable a getter?
class Something attr_writer :var def initialize @var end def var @var ||= 12 end end foo = Something.new foo.var # => 12 foo.var = 15 foo.var # => 15

Categories : Ruby

How do I give an instance a name when created with the aws sdk for ruby?
After you've created the instance you need to add a tag to it. You can add up to 10 arbitrary key value pairs and if the key is "Name" then the aws console will display that value by default. You can also configure the console to display any other tags you find useful. Something like this should do the trick, assuming your instance had the is "i-123abc". ec2 = AWS::EC2.new ec2.client.create_tags(:resources => ["i-123abc"], :tags => [ { :key => 'Name', :value => 'an instance' } ])

Categories : Ruby

Why won't CloudFormation execute my command?
Your commands block should be nested inside the config block, at the moment it is at the same level in the hierarchy. "AWS::CloudFormation::Init" : { "config" : { "files" : { "c:\Packages\WebDeploy_amd64_en-US.msi" : { "source" : "http://download.microsoft.com/download/1/B/3/1B3F8377-CFE1-4B40-8402-AE1FC6A0A8C3/WebDeploy_amd64_en-US.msi" } }, "commands" : { "1-installwebdeploy" : { "command" : "msiexec.exe /i c:\Packages\WebDeploy_amd64_en-US.msi ADDLOCAL=ALL /qn /norestart" } } }, }

Categories : Amazon

Why won't my CloudFormation script download a file?
Jonathon, I tried your template and the file downloaded successfully for me. You can check the cfn logs on the instance. They are in c:cfnlog. My cfn-init.log shows: 2013-07-19 21:30:18,269 [DEBUG] Parent directory c: est does not exist, creating 2013-07-19 21:30:18,269 [DEBUG] Writing content to c: estgoogle-logo.png 2013-07-19 21:30:18,269 [DEBUG] Retrieving contents from http://www.google.com/images/srpr/logo4w.png 2013-07-19 21:30:18,316 [DEBUG] No mode specified for c: estgoogle-logo.png 2013-07-19 21:30:18,316 [WARNING] Unsupported OS for setting owner/group: nt And my cfn-wire.log shows: 2013-07-19 21:30:18,269 [DEBUG] Request: GET http://www.google.com/images/srpr/logo4w.png [headers: {'Accept-Encoding': 'identity, deflate, compress, gzip', 'Accept': '*/*', 'User-Agent': 'pyth

Categories : Amazon

AWS - Automatic deployment (.NET) to CloudFormation stack
cloud-init is used with windows too. See the documentation for bootstrapping Windows stacks.

Categories : Amazon

Is it possible to create a SNS subscription with CloudFormation without creating a topic?
As you already discovered, AWS CloudFormation doesn't provide the expected AWS::SNS::Subscription resource (yet) and I'm not aware of this being possible by any other means, unfortunately - guess the rationale is that both are either managed within a template or externally, but your use case is sound and I can see no fundamental reason why this shouldn't be available (maybe they'll add it at some point, AWS is usually expanding their APIs over time to address such inconsistencies/missings).

Categories : Amazon

Installing Windows applications/extensions with Amazon CloudFormation
For your example of WebDeploy, you could add this: "C:\Webdeploy\WebDeploy_amd64_en-US.msi" : { "source" : "http://download.microsoft.com/download/1/B/3/1B3F8377-CFE1-4B40-8402-AE1FC6A0A8C3/WebDeploy_amd64_en-US.msi" } as a element of this section of the template "WindowsServer": { "Type" : "AWS::EC2::Instance", "Metadata" : { "AWS::CloudFormation::Init" : { "config" : { "files" : { You could then add this command: "1-installwebdeploy" : { "command" : "msiexec.exe /i C:\Webdeploy\WebDeploy_amd64_en-US.msi ADDLOCAL=ALL /qn /norestart" } to the list of commands.

Categories : Amazon

Generating subnet CIDR blocks programmatically in CloudFormation templates (or adding integers together)
My solution for these kinds of issues was to use a legitimate programming language to compile a template into a CloudFormation JSON document. I used PHP 5.4, Twig and Symfony Console, but YMMV. Essentially, you do the math ahead of time in the programming language, then use that data as you write-out your JSON document.

Categories : Amazon

array loop keep a certain number of keys and replace the keys with an associative key based on the elements
For deleting the array elments you can use array_splice() in php $input = array("red", "green", "blue", "yellow"); array_splice($input,3); print_r($input); Ouptput Array ( [0] => red [1] => green [2] => blue ) So you can do array_splice($val,65);

Categories : PHP

Will junction table contain the foreign keys or the primary keys of the individual tables
Correct. Your 'junction' table or 'association' table will the contain the PK values of the tables on either end of the M2M relationship. Often times these are the only two columns in the association/junction table and they can/usually form the PK of the association/junction table.

Categories : Database

Oracle Statement performance: Retrieve primary keys exluding combined foreign keys
You could try this structure: select yourfields from yourtables where whatever and somefield in (select somefield fromyourtables where the conditions are the same as above minus select the same field from whereever where you want to exclude it) If it were my problem, I'd consider it worth trying.

Categories : SQL

how to construct a string of physical subnet ids to create db subnet group on the fly in a cloudformation script?
I run into the same issue, after working with AWS support I understood that List of String does not mean what we initially thought. Also, if you want to place the DB inside a VPC you must not use AWS::RDS::DBSecurityGroup objects. Here is a full sample, it took me a while to get it working: "dbSubnetGroup" : { "Type" : "AWS::RDS::DBSubnetGroup", "Properties" : { "DBSubnetGroupDescription" : "Availability Zones for RDS DB", "SubnetIds" : [ { "Ref" : "subnetPrivate1" }, { "Ref" : "subnetPrivate2" } ] } }, "dbInstance" : { "Type" : "AWS::RDS::DBInstance", "Properties" : { "DBInstanceIdentifier" : { "Fn::Join" : [ "", [ { "Ref" : "AWS::St

Categories : Amazon

Why .sendKeys(Keys.chord(Keys.CONTROL, "a")) does not work in Chrome
Have you tried to use action builder? For example, from our automation suite: public void selectAndDeleteTextViaKeyboard() { selectTextViaKeyboard() deleteViaKeyboard() } public void deleteViaKeyboard() { Actions builder = new Actions(webDriverProxy.getWebDriver()); builder.sendKeys(Keys.DELETE) .release().perform(); } public void selectTextViaKeyboard() { Actions builder = new Actions(webDriverProxy.getWebDriver()); Action select= builder .keyDown(Keys.CONTROL) .sendKeys("a") .keyUp(Keys.CONTROL) .build(); select.perform(); }

Categories : Selenium

Generate ID keys in a table with composite keys using Doctrine2 and Symfony2
Back to basics. I'd suggest starting here: http://docs.doctrine-project.org/en/latest/reference/association-mapping.html class KUser { /** * @ORMId * @ORMColumn(name="id", type="integer", nullable=false) * @ORMGeneratedValue(strategy="AUTO") */ protected $id; class Interest { /** * @ORMId * @ORMColumn(name="id", type="integer", nullable=false) * @ORMGeneratedValue(strategy="AUTO") */ protected $id; /** * @ORMManyToOne(targetEntity="UserBundleEntityKUser") * @ORMJoinColumn(name="kuser_id", referencedColumnName="id") */ protected $kuser; That is all you need to establish a one-way ManyToOne relation between Interest and KUser. If you need it bi-directional then add an

Categories : Symfony2

Relational Database Inheritance foreign keys and primary keys
It would probably make sense to have the child class tables reference the parent class, instead of the other way around. Then you can have an id column on the Entity table which is unique and foreign keys from the children to their parent instances. Presumably this will help when you want to use the data to instantiate an object in your code as well, since you should know which class you are instantiating and only care about its ancestors, not its children.

Categories : Database

R - data.table by group by - order of keys and missing keys
How about... myJ <- function(key,...) do.call(data.table,list(...))[,key,with=FALSE] DT1[myJ(B=1,A='A',key=key(DT1))] or myJ1 <- function(...) myJ(key(DT1),...) DT1[myJ1(B=1,A='A')] This way, you have to label the items correctly.

Categories : R

Code First - Two foreign keys as primary keys, unable to add migration
You specify a composite key by either adding the [Column] attribute to the data annotations... [Key, Column(Order = 1)] public int PollId { get; set; } [Key, Column(Order = 2)] public int UserId { get; set; } ...or by using an anonymous object with Fluent API: this.HasKey(x => new { x.UserId, x.PollId }); this.HasRequired(x => x.User) .WithMany(u => u.PollVotes) .HasForeignKey(x => x.UserId); this.HasRequired(x => x.Poll) .WithMany(p => p.PollVotes) .HasForeignKey(x => x.PollId); Don't forget the lambda expressions for the inverse navigation properties in WithMany, as shown above, and remove the redundant configurations in UserConfig and PollConfig.

Categories : Entity Framework

Python duplicate keys, cannot find keys in dict
I think you think that there's a difference between self.currentDict and self.currentDict keys... and that somehow the first is giving you the first element of your tuple, and the second one the second... To check if a tuple exists as a key: if ('state', 'value') in self.currentDict And to assign, you should do: self.currentDict[('state', 'value')] = 'some value' (note: the parentheses aren't strictly necessary, but imho make it clearer)

Categories : Python

Should I use composite primary keys if I use JPA and the keys can change?
As you said, according specification JPA does not support update of primary keys: The application must not change the value of the primary key[10]. The behavior is undefined if this occurs.[11] ... [10] This includes not changing the value of a mutable type that is primary key or an attribute of a composite primary key. [11] The implementation may, but is not required to, throw an exception. Portable applications must not rely on any such specific behavior. Using surrogate key is in my opinion best option, most of the time also auto incremented one. Other option would be removal of entity with original key and recreating it with new key (and other values from original entity). That is plenty of work, especially for entities with many relationships.

Categories : Database

given array keys only return keys from form
Are you looking for array_intersect? $possible = array('email', 'phone', ...); $existing = array_intersect($possible, array_keys($_POST)); var_dump($existing);

Categories : PHP

ListBox Map J and K Keys to Up/Down Arrow Keys
You can use your DependencyClass on the commands. Define the commands in ListBox.InputBindings: XAML <ListBox Name="SampleListBox" Width="200" Height="200" KeyboardNavigation.DirectionalNavigation="Cycle" SelectedIndex="{Binding MySelectedIndex}"> <ListBox.InputBindings> <KeyBinding Command="{Binding NextCommand}" Gesture="CTRL+J" /> <KeyBinding Command="{Binding PrevCommand}" Gesture="CTRL+K" /> </ListBox.InputBindings> <ListBoxItem>Sample 1</ListBoxItem> <ListBoxItem>Sample 2</ListBoxItem> <ListBoxItem>Sample 3</ListBoxItem> <ListBoxItem>Sample 4</ListBoxItem> </ListBox> Code behind public partial class MainWindow : Window { public MainWindow() {

Categories : Wpf

Error too many keys specified; max 64 keys allowed
Given the replies here: mysql error 1069 Too many keys specified; max 64 keys allowed and here http://forums.mysql.com/read.php?22,53666,53666 (old thread from 2005, but still relevant), it seems that recompiling and publishing seems to be your only option. This of course is difficult in case your hosting won't allow you to manually deploy a mySql installation.

Categories : Mysql

How do you search for keys with a value? For example get all KEYS where the value is "somevalue"
Redis is not a relational database. You need to anticipate this access path, and maintain a reverse index. # This is your index SADD CO:1:A 1 2 SADD CO:2:A 1 5 6 SADD CO:3:A 5 SADD CO:4:A 1 # Here is the reverse index SADD REV:1 1 2 4 SADD REV:2 1 SADD REV:5 2 3 SADD REV:6 2 Now you can query in reverse way: SMEMBERS REV:1 1) "1" 2) "2" 3) "4" ... meaning CO:1:A. CO:2:A, CO:4:A

Categories : PHP

Does the order of keys in dictionary.keys() in a python dictionary change if the values are changed?
No, a python dictionary has an ordering for the keys but does not guarantee what that order will be or how it is calculated. Which is why they are not guaranteed to be ordered in the first place. The values stored in the dictionary do not have an effect on the hash values of the keys and so will not change ordering. Taken from the Python Documentation: The keys() method of a dictionary object returns a list of all the keys used in the dictionary, in arbitrary order (if you want it sorted, just apply the sorted() function to it). To check whether a single key is in the dictionary, use the in keyword.

Categories : Python

Can a child instance access dynamic parent instance attributes and attribute values?
You're misusing inheritance. Rule doesn't need to inherit from Map to access a Map's attributes, and attaching a Rule to a Map won't make it see the Map's attribute values as its own. Inheriting from Map means a Rule is a Map, not that it's linked to or managed by a Map. If you want a Rule to know about its Map, have it record which Map it's associated with: class Rule(object): def __init__(self, number, map): super(Rule, self).__init__() self.number = number self.map = map def __str__(self): # __str__, not __repr__, because __repr__ should be unambiguous, # have a clear beginning and ending, and obviously indicate the type. return "Map {} rule number {}".format(self.map.mapName, self.number) Rule(1, map) # makes a rule associated

Categories : Python

Pass in an instance variable to a static method -- and modifies another instance variance?
Am I correct in saying that it is impossible for the other HashMap to be modified by foo as a result of just this one method call? Answer is may be. It is true that if you dont pass the reference of a object to method, you can not access it. But Map stores key-value Object pair refernece, it does not store the Objects, if both map share Object as key or value, then it would effect.

Categories : Java

Newly created instance takes the primary id of a deleted instance with same Account name
This is a known behavior of AUTO_INCREMENT fields in MySQL: http://forums.mysql.com/read.php?10,167180 If this is really your problem, you will have to find an other strategy to keep track of deleted user accounts. For more information, see Stop MySQL Reusing AUTO_INCREMENT IDs

Categories : SQL

Is there a way to reset a class instance's initialized attribute to the value entered when the instance was created?
There's nothing in Ruby that saves the initial value passed on, so nothing in Ruby that will let you automatically reset it. However, you can certainly save the value in an another instance variable and reset it as you wish, as in: def initialize(..., meat_quality) ... @original_meat_quality = @meat_quality = meat_quality end def reset_meat_quality @meat_quality = @original_meat_quality end

Categories : Ruby

Are object of my classes being created everytime there is a request or does it only create one instance of a class per instance server
Instances of resource classes are created "per-request" by default. You can mark them as singletons however and then one instance would be used for all requests. To do this you can use the following annotations: @com.sun.jersey.spi.resource.Singleton for Jersey 1.x (JAX-RS 1.1) @javax.inject.Singleton for Jersey 2.x (JAX-RS 2.0)

Categories : Java

Error: unbound method Dragon( ) must be called with Enemy instance as first argument (got Player instance instead)
You have to create an instance of a class first before you call any functions from it: myenemy = Enemy() myenemy.Dragon() In your code, it looks like you created self.enemy, but later you call self.enemy = Enemy.Dragon(self). Instead of this last line, put self.enemy = self.enemy.Dragon(self). It seems to be a recurring issue in the rest of your code as well. Commands = {'explore': Player.explore} should probably be Commands = {'explore': p.explore} (after you have created the instance p). Since your updated code, I think you're getting functions and classes mixed up. Dragon is a function, and when you do enemy = m.Dragon, you are simply copying the function onto enemy. And thus when you do enemy.name, thinking it's a class, an error is raised, because enemy is now a function, not a

Categories : Python

Objects and Arrays of one instance are getting referenced by new instance of Backbone model
There is a hack I have used to solve this problem. Reset all the objects and arrays used as attributes in Backbone model in initialize method. var myModel = Backbone.Model.extend({ defaults: { exp: [], name: '', json: { } }, getExp: function() { return this.get('exp'); }, getJSON: function() { return this.get('json'); }, initialize: function() { this.set('exp', []); this.set('json', {}); } }); var m1 = new myModel(); var experiences = m1.getExp(); experiences.push('arrayitem1'); experiences.push('arrayitem2'); m1.set('name', 'my name'); var json = m1.getJSON(); json.key = 'somevalue'; var m2 = new myModel(); console.log(m1.attributes); console.log(m2.attributes); Working Demo at JSBIN

Categories : Javascript

WPF, how to make a single instance and shows the MainWindow when another instance is launched in c#
If I havent misunderstood your question try something like this [STAThread] public static void Main(string[] args) { Task task = new Task(() => { Thread.Sleep(200); MessageBox.Show("what a marvelous engineering"); }); task.Start(); //If you want application not to run untill task is complete then just use wait task.Wait(); App app = new App(); app.InitializeComponent(); app.Run(); } But I am wondering if you want your C# work done before the your MainWindow instantiate why dont you just do your other wor just before App app=new App() and let the code run sequentially.

Categories : C#

Assign instance id when the wpf app has multiple controls on page identified as one instance
An addendum to AdrianHHH's excellent suggestion is to iterate through the FindMatchingControls collection and figure out which one is the one you want. If it's always collection[3] then you can identify it and act on it as such. Your code would look like this: var button = new WinButton(winWindowChild(mainParentCtName, childParentCtName)); //if you pass parents when you construct an object it can speed up find button.SearchProperties.Add(/*any identifying properties*/); var allButtons = button.FindMatchingControls(); //test code foreach (var btn in allButtons) Mouse.Click(btn); //watch this to figure out what order the buttons are iterating through, then remove loop Mouse.Click(allButtons[3]); Mouse.DoubleCli

Categories : Wpf

Calling an Instance method when user inputs the instance name as a String
You can use a Map for this. E.g.: Map<String, Skill> skills = new HashMap<String, Skill>(); To insert the values you put the values into the Map: skills.put(skill.getName(), skill); To retrieve your skill you can get the skill by name: Skill skill = skills.get(name);

Categories : Java

How to use Angular.js service instance inside module config and keep the same instance
From the doc - Services as singletons All Angular services are application singletons. This means that there is only one instance of a given service per injector. Since Angular is lethally allergic to global state, it is possible to create multiple injectors, each with its own instance of a given service, but that is rarely needed, except in tests where this property is crucially important. It mean if you do injector.get for a single injector, it will always returns the singleton like this var injector = angular.injector(['app.services']); var singletonService1 = injector.get('singletonService'); var singletonService2 = injector.get('singletonService'); console.log(singletonService1 === singletonService2) // prints true However if you inject it to another the controller

Categories : Javascript



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