If I just want a sorted list of just dates, integers, or doubles is it really necessary to have to define a SortedList(of Integer, Integer)?
Seems intriguing to me, but may just be trival. I'd prefer just to use a SortedList(of Integer).
(This question is in relation to the .Net generic collections)
I am using Sql Server 2005
This is a part of my database diagram. I want to perform deletion on my database which will start from tblDomain up tp tblSubTopics.
Consider that each table has IsDeleted column which has to be marked true if request was made to delete data. But that data shoud remain their physically.
Tables which will have IsDeleted Column are
tblDomain
tblSubject
tblTopic
tblSubTopic
Now I want, if a user marks one domain as deleted then all the refrence field should also get marked as deleted. i.e.
1 domain is related to 5 subjects, those 5 subjects are related to 25 topics, those 25 topics are related to 500 subtopics and so on.
Then how should i mark all these fileds as Deleted. ?
Hi,
in my app i need to open a website with the corresponding TLD for that country. Lets say google.com, google.de, etc...
But i don't know which country codes the're specifically using in NSLocale's dict. Can i assume that the lowercase version of NSLocaleCountryCode can be appended as TLD?
Regards, Erik
How can I write this code more cleanly/concisely?
/// <summary>
/// Creates a set of valid URIs.
/// </summary>
/// <param name="levelVariantURIDicts">A collection of dictionaries of the form:
/// dict["filePath"] == theFilePath </param>
/// <returns></returns>
private ICollection<string> URIsOfDicts(ICollection<IDictionary<string, string>> levelVariantURIDicts)
{
ICollection<string> result = new HashSet<string>();
foreach (IDictionary<string, string> dict in levelVariantURIDicts)
{
result.Add(dict["filePath"]);
}
return result;
}
I'm trying to figure out the best way to represent some data. It basically follows the form Manufacturer.Product.Attribute = Value. Something like:
Acme.*.MinimumPrice = 100
Acme.ProductA.MinimumPrice = 50
Acme.ProductB.MinimumPrice = 60
Acme.ProductC.DefaultColor = Blue
So the minimum price across all Acme products is 100 except in the case of product A and B. I want to store this data in C# and have some function where GetValue("Acme.ProductC.MinimumPrice") returns 100 but GetValue("Acme.ProductA.MinimumPrice") return 50.
I'm not sure how to best represent the data. Is there a clean way to code this in C#?
I have recently tried sharpening my rails skills with this tool:
http://github.com/edgecase/ruby_koans
but I am having trouble passing some tests. Also I am not sure if I'm doing some things correctly since the objective is just to pass the test, there are a lot of ways in passing it and I may be doing something that isn't up to standards.
Is there a way to confirm if I'm doing things right?
a specific example:
in about_nil,
def test_nil_is_an_object
assert_equal __, nil.is_a?(Object), "Unlike NULL in other languages"
end
so is it telling me to check if that second clause is equal to an object(so i can say nil is an object) or just put assert_equal true, nil.is_a?(Object) because the statement is true?
and the next test:
def test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil
# What happens when you call a method that doesn't exist. The
# following begin/rescue/end code block captures the exception and
# make some assertions about it.
begin
nil.some_method_nil_doesnt_know_about
rescue Exception => ex
# What exception has been caught?
assert_equal __, ex.class
# What message was attached to the exception?
# (HINT: replace __ with part of the error message.)
assert_match(/__/, ex.message)
end
end
Im guessing I should put a "No method error" string in the assert_match, but what about the assert_equal?
I built an inventory database where ISBN numbers are the primary keys for the items. This worked great for a while as the items were books. Now I want to add non-books. some of the non-books have EANs or ISSNs, some do not.
It's in PostgreSQL with django apps for the frontend and JSON api, plus a few supporting python command-line tools for management. the items in question are mostly books and artist prints, some of which are self-published.
What is nice about using ISBNs as primary keys is that in on top of relational integrity, you get lots of handy utilities for validating ISBNs, automatically looking up missing or additional information on the book items, etcetera, many of which I've taken advantage. some such tools are off-the-shelf (PyISBN, PyAWS etc) and some are hand-rolled -- I tried to keep all of these parts nice and decoupled, but you know how things can get.
I couldn't find anything online about 'private ISBNs' or 'self-assigned ISBNs' but that's the sort of thing I was interested in doing. I doubt that's what I'll settle on, since there is already an apparent run on ISBN numbers.
should I retool everything for EAN numbers, or migrate off ISBNs as primary keys in general? if anyone has any experience with working with these systems, I'd love to hear about it, your advice is most welcome.
Okay I have two tables. They both have keys. I have another table that references both keys. How can I make a constraint when I add into that third if either of the keys don't exist in the first two tables it won't insert that tuple into the third table. I am inserting in phpMyAdmin. Thanks.
Something quite odd is happening with y types and I quite dont understand if this is justified or not. I would tend to think not.
This code works fine :
type DictionarySingleton private () =
static let mutable instance = Dictionary<string*obj, obj>()
static member Instance = instance
let memoize (f:'a -> 'b) =
fun (x:'a) ->
let key = f.ToString(), (x :> obj)
if (DictionarySingleton.Instance).ContainsKey(key)
then let r = (DictionarySingleton.Instance).[key]
r :?> 'b
else
let res = f x
(DictionarySingleton.Instance).[key] <- (res :> obj)
res
And this ones complains
type DictionarySingleton private () =
static let mutable instance = Dictionary<string*obj, _>()
static member Instance = instance
let memoize (f:'a -> 'b) =
fun (x:'a) ->
let key = f.ToString(), (x :> obj)
if (DictionarySingleton.Instance).ContainsKey(key)
then let r = (DictionarySingleton.Instance).[key]
r :?> 'b
else
let res = f x
(DictionarySingleton.Instance).[key] <- (res :> obj)
res
The difference is only the underscore in the dictionary definition.
The infered types are the same, but the dynamic cast from r to type 'b exhibits an error.
'this runtime coercition ... runtime type tests are not allowed on some types, etc..'
Am I missing something or is it a rough edge ?
To keep myself interested, I try to put little Easter Eggs in my projects (mostly to amuse myself). I've seen some websites where you can type a series of letters "aswzaswz" and you get a "secret function" - how would I achieve this in C#?
I've assigned a "secret function" in the past by using modifier keys
bool showFunThing = (Control.ModifierKeys & Keys.Control) == Keys.Control;
but wanted to get a bit more secretive (without the modifier keys) I just wanted the form to detect a certain word typed without any input ... I've built a method that I think should do it:
private StringBuilder _pressedKeys = new StringBuilder();
protected override void OnKeyDown(KeyEventArgs e)
{
const string kWord = "fun";
char letter = (char)e.KeyValue;
if (!char.IsLetterOrDigit(letter))
{ return; }
_pressedKeys.Append(letter);
if (_pressedKeys.Length == kWord.Length)
{
if (_pressedKeys.ToString().ToLower() == kWord)
{
MessageBox.Show("Fun");
_pressedKeys.Clear();
}
}
base.OnKeyDown(e);
}
Now I need to wire it up but I can't figure out how I'm supposed to raise the event in the form designer ... I've tried this:
this.KeyDown +=new System.Windows.Forms.KeyEventHandler(OnKeyDown);
and a couple of variations on this but I'm missing something because it won't fire (or compile). It tells me that the OnKeyDown method is expecting a certain signature but I've got other methods like this where I haven't specified arguments.
I fear that I may have got myself confused so I am turning to SO for help ... anyone?
...apart from the obvious looping through the list and a dirty great case statement!
I've turned over a few Linq queries in my head but nothing seems to get anywhere close.
Here's the an example DTO if it helps:
class ClientCompany
{
public string Title { get; private set; }
public string Forenames { get; private set; }
public string Surname { get; private set; }
public string EmailAddress { get; private set; }
public string TelephoneNumber { get; private set; }
public string AlternativeTelephoneNumber { get; private set; }
public string Address1 { get; private set; }
public string Address2 { get; private set; }
public string TownOrDistrict { get; private set; }
public string CountyOrState { get; private set; }
public string PostCode { get; private set; }
}
We have no control over the fact that we're getting the data in as KV pairs, I'm afraid.
Taking an example that is provided on the Fluent nHibernate website, I need to extend it slightly:
I need to add a 'Quantity' column to the StoreProduct table. How would I map this using nHibernate?
An example mapping is provided for the given scenario above, but I'm not sure how I would get the Quantity column to map:
public class StoreMap : ClassMap<Store>
{
public StoreMap()
{
Id(x => x.Id);
Map(x => x.Name);
HasMany(x => x.Employee)
.Inverse()
.Cascade.All();
HasManyToMany(x => x.Products)
.Cascade.All()
.Table("StoreProduct");
}
}
when I am editing a cell and press enter the next row is automatically selected, I want to stay with the current row... I want to happen nothing except the EndEdit.
I have this:
private void dtgProductos_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dtgProductos[e.ColumnIndex, e.RowIndex].Selected = true; //this line is not working
var index = dtgProductos.SelectedRows[0].Cells.IndexOf(dtgProductos.SelectedRows[0].Cells[e.ColumnIndex]);
switch (index)
{
case 2:
{
dtgProductos.SelectedRows[0].Cells[4].Selected = true;
dtgProductos.BeginEdit(true);
}
break;
case 4:
{
dtgProductos.SelectedRows[0].Cells[5].Selected = true;
dtgProductos.BeginEdit(true);
}
break;
case 5:
{
btnAddProduct.Focus();
}
break;
default:
break;
}
}
so when I edit a row that is not the last one I get this error:
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
Dear all,
i've a dictonary " dictSample " which contains
1 data1
2 data2
3 data3
4 data4
and an xml file"sample.xml" in the form of:
<node>
<element id="1" value="val1"/>
<element id="2" value="val2"/>
<element id="3" value="val3"/>
<element id="4" value="val4"/>
<element id="5" value="val5"/>
<element id="6" value="val6"/>
<element id="7" value="val7"/>
</node>
i need to match the dictonary keys with the xml attribute id and to insert the matching id and
the value of attribute"value" into another dictonary
now i'm using like:
XmlDocument XDOC = new XmlDocument();
XDOC.Load("Sample.xml");
XmlNodeList NodeList = XDOC.SelectNodes("//element");
Dictionary<string, string> dictTwo = new Dictionary<string, string>();
foreach (string l_strIndex in dictSample .Keys)
{
foreach (XmlNode XNode in NodeList)
{
XmlElement XEle = (XmlElement)XNode;
if (dictSample[l_strIndex] == XEle.GetAttribute("id"))
dictTwo.Add(dictSample[l_strIndex], XEle.GetAttribute("value").ToString());
}
}
please help me to do this in a simple way using LINQ
I am writing a recursive function to print out the differences between 2 multildimensional php arrays. The purpose of this code is to see the difference between jpeg headers to deteremine how adobe bridge cs3 is saving rating information within the jpg file.
When I am single-stepping through the code using my eclipse - zend debugger ide, it appears that even though the initial if statement is false (ie both values are arrays), the subsequent elseif statements are never executed. The function is attached below.
function array_diff_multi($array1,$array2,$level){
$keys = array_keys($array1);
foreach($keys as $key)
{
$value1 = $array1[$key];
if(array_key_exists($key,$array2) ){
$value2 = $array2[$key];
// Check if they are both arrays, if so recursion is needed
if (is_array($value1) && is_array($value2)){
array_diff_multi($value1,$value2,$level . "[ " . $key . " ]");
}
// the values aren't both arrays *** THE CODE IN THE ELSEIF BELOW IS NOT EXECUTED ***
elseif(is_array($value1) != is_array($value2)){
print "" . $level . $key ."=" . $value1 . "as array, compared to ". $value2 ."";
}
// the values don't match
elseif($value1 != $value2){
print "" . $level . $key ."=" . $value1 ." != " . $value2 ."";
}
else;
}
else{
print "" . $level. $key . "does not exist in array2";
}
}
}
How can I get some part of string that I need?
accountid=xxxxxx type=prem servertime=1256876305 addtime=1185548735 validuntil=1265012019 username=noob directstart=1 protectfiles=0 rsantihack=1 plustrafficmode=1 mirrors= jsconfig=1 [email protected] lots=0 fpoints=6076 ppoints=149 curfiles=38 curspace=3100655714 bodkb=60000000 premkbleft=25000000 ppointrate=116
I want data after email= but up to live.com.?
In my own computer, running MacOSX, I have this in ~/.ssh/config
Host *
ForwardAgent yes
Host b1
ForwardAgent yes
b1 is a virtual machine running Ubuntu 12.04. I ssh to it like this:
ssh pupeno@b1
and I get logged in without being asked for a password because I already copied my public key. Due to forwarding, I should be able to ssh to pupeno@b1 from b1 and it should work, without asking me for a password, but it doesn't. It asks me for a password.
What am I missing?
This is the verbose output of the second ssh:
pupeno@b1:~$ ssh -v pupeno@b1
OpenSSH_5.9p1 Debian-5ubuntu1, OpenSSL 1.0.1 14 Mar 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to b1 [127.0.1.1] port 22.
debug1: Connection established.
debug1: identity file /home/pupeno/.ssh/id_rsa type -1
debug1: identity file /home/pupeno/.ssh/id_rsa-cert type -1
debug1: identity file /home/pupeno/.ssh/id_dsa type -1
debug1: identity file /home/pupeno/.ssh/id_dsa-cert type -1
debug1: identity file /home/pupeno/.ssh/id_ecdsa type -1
debug1: identity file /home/pupeno/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 35:c0:7f:24:43:06:df:a0:bc:a7:34:4b:da:ff:66:eb
debug1: Host 'b1' is known and matches the ECDSA host key.
debug1: Found key in /home/pupeno/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/pupeno/.ssh/id_rsa
debug1: Trying private key: /home/pupeno/.ssh/id_dsa
debug1: Trying private key: /home/pupeno/.ssh/id_ecdsa
debug1: Next authentication method: password
pupeno@b1's password:
I have a problem to fix the URL on my website at http://www.abelputra.com
I need a solution:
I want to change www.abelputra.com/software.php into www.abelputra.com/software
I have read a tutorial like this:
For .htaccess:
RewriteEngine On
RewriteRule ^ ([a-zA-Z0-9_-] +) $ index.php? Key = $ 1
RewriteRule ^ ([a-zA-Z0-9_-]+)/$ index.php? Key = $ 1
Then in php:
index.php ---
$Key=$ _GET ['key'];
if ($key == 'home')
{
include ('index.php'); // Home page
}
else if ($ key == 'software')
{
include ('software.php'); //
}
else if ($ key == 'webdesign')
{
include ('webdesign.php'); //
}
The problem is:
When I implemented the menu software.php index.php to call the page:
www.abelputra.com/index.php?key=software
what happens is the page that is shown is two pages later software.php index.php page underneath.
Is it because calling functions "include ()"?
index.php structures:
Header
Content - contains the opening words
Footer
software.php structure:
Header
Content - contains an explanation of my software
Footer
Sorry my english bad. im from Indonesia.
Please solution ..
thanks
hi, i want to remove some pretty words in list of words.
public System.String CleanNoiseWord(System.String word)
{
string key = word;
if (word.Length <= 2)
key = System.String.Empty;
else
key = word;
//other validation here
return key;
}
public IList<System.String> Clean(IList<System.String> words)
{
var oldWords = words;
IList<System.String> newWords = new string[oldWords.Count()];
string key;
var i = 0;
foreach (System.String word in oldWords)
{
key = this.CleanNoiseWord(word);
if (!string.IsNullOrEmpty(key))
{
newWords.RemoveAt(i);
newWords.Insert(i++, key);
}
}
return newWords.Distinct().ToList();
}
but i can't add, remove or insert any thing in list! and exception NotSupportedException occured Collection was of a fixed size. how i can modify or add new item into generic list of string's?
Hello Everyone,
Right now i got an array which has some sort of information and i need to create a table from it. e.g.
Student{
[Address]{
[StreetAddress] =>"Some Street"
[StreetName] => "Some Name"
}
[Marks1] => 100
[Marks2] => 50
}
Now I want to create database table like which contain the fields name as :
Student_Address_StreetAddress
Student_Address_StreetName
Student_Marks1
Student_Marks2
It should be recursive so from any depth of array it can create the string in my format.
I'd like to run an Android background service that will act as a keylistener from the home screen or when the phone is asleep. Is this possible?
From semi-related examples online, I put together the following service, but get the error, "onKeyDown is undefined for the type Service". Does this mean it can't be done without rewriting Launcher, or is there something obvious I'm missing?
public class ServiceName extends Service {
@Override
public void onCreate() {
//Stuff
}
public IBinder onBind(Intent intent) {
//Stuff
return null;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN) {
switch(keyCode) {
case KeyEvent.KEYCODE_A:
//Stuff
return true;
case KeyEvent.KEYCODE_B:
//Stuff
return true;
//etc.
}
}
return super.onKeyDown(keyCode, event);
}
}
I realize Android defaults to the search bar when you type from the home screen, but this really is just for a very particular use. I don't really expect anyone but me to want this. I just think it'd be nice, for example, to use the camera button to wake the phone.