Hi,
I have this table:
id
feed_id
...
Let's say that I have 500 rows and I want to select 3 entries for each feed_id? And 50 as total limit.
How to write this SQL?
...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.
can anybody help me. the sample code is
function capturecurrent() {
var win = chrome.extension.getExtensionTabs();
return win;
}
its not returning any domwindowarray. if i calculate win.length, it always gives me 0;
Learning C#, I feel so guilty for loving it. I'm a microsoft hater. Anyways I'm trying out gtk# and just trying out some simple stuff. I've made a class for the main window and MonoDevelop is complaining about this code, which I swear was just fine a second ago.
public class mwin{
protected Window win = new Window("test program--");
public mwin(){ //Configure the parts
win.SetDefaultSize(300,500);
}
public void showWin(){
win.ShowAll();
}
}
win.SetDefaultSize(300,500);
}--<(here it says "} expected")
But obviously I have a closing brace! Am I missing something?
[edit]
here's whole code. The color stuff was some stuff I was playing around with to color the window, but I didn't finish because the error started. I'm sure it's not the color stuff because it still has an error when I comment them out. http://codepaste.net/b2mwys
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?
Is there anyway to use atrm command to remove queue job from PHP web application?
I wrote a shell script to remove the queue job but it doesn't work well.
#! /bin/sh
export PATH=/usr/local/bin:$PATH
echo atrm 3700 2>&1
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 ?
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";
}
}
}
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.
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.?
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
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");
}
}
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 am using a list view inside that in item template i am using a label and a checkbox.
I want that whenever user clicks on the check box the value should be updated in a table.i am using a datakeys in listview.on the basis of datakey value should be updated in the table
query is
string updateQuery = "UPDATE [TABLE] SET [COLUMN] = " +
Convert.ToInt32(chk.Checked) + " WHERE PK_ID =" + dataKey + " ";
also i want some help in displaying the result as it is inside the table.means if the value for column in table for a particular pkid is 1 then the checkbox shoul be checked.
here is the code snippet
<asp:ListView ID="lvFocusArea" runat="server"
DataKeyNames="PK_ID" onitemdatabound="lvFocusArea_ItemDataBound" >
<LayoutTemplate>
<table border="0" cellpadding="1" width="400px">
<tr style="background-color: #E5E5FE">
<th align="left">
Focus Area
</th>
<th>
Is Current Focused
</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td width="80%">
<asp:Label ID="lblFocusArea" runat="server" Text=""><%#Eval("FOCUS_AREA_NAME") %></asp:Label>
</td>
<td align="center" width="20%">
<asp:CheckBox ID="chkFocusArea" runat="server" OnCheckedChanged="chkFocusArea_CheckedChanged"
AutoPostBack="true"/>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: #EFEFEF">
<td>
<asp:Label ID="lblFocusArea" runat="server" Text=""><%#Eval("FOCUS_AREA_NAME") %></asp:Label>
</td>
<td align="center">
<asp:CheckBox ID="chkFocusArea" runat="server" oncheckedchanged="chkFocusArea_CheckedChanged" AutoPostBack="true" />
</td>
</tr>
</AlternatingItemTemplate>
<SelectedItemTemplate>
<td> item selected</td>
</SelectedItemTemplate>
</asp:ListView>
help me.
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?
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.
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 have two .rtf file....
The first one have this content:
Apple, Orange, Banana, Noodle, Chip
The Second File is something like this:
Apple I love eat Apple.
Banana I hate Banana.
Zoo I want to go Zoo.
Noodle Noodle can be a very very very very very very very very very very very long, but still is one line.
Chip Don't eat so many chip.
Orange Orange is great, not Apple plx. Noodle
Water Drinking water is boring.
The first file is a "key" of second file. In the second file, the first word is the key of each line. Each key and sentence in second file ONLY have one line. The Second File have many lines with key, but not all the key is shown on file1, but file1's key MUST in the second file.
How can I get the result like this: (Need to sort by the key from File1)
Apple, Apple I love eat Apple.
Orange, Orange is great, not Apple plx.
Banana, I hate Banana.
Noodle, can be a very very very very very very very very very very very long, but still is one sentence.
Chip, Don't eat so many chip.
I use the following Vim macro a lot (it puts the current line inside tags):
I<e>^[A</e>
So I saved it into my .vimrc
let @e='I<e>^[A</e>'
But it does not work.
The ^[ part means Escape but it is not understood as such when using .vimrc
How can I save this macro, or any macro that contains "Escape" ?
Let's say I've defined this model:
class Identifier(models.Model):
user = models.ForeignKey(User)
key = models.CharField(max_length=64)
value = models.CharField(max_length=255)
Each user will have multiple identifiers, each with a key and a value. I am 100% sure I want to keep the design like this, there are external reasons why I'm doing it that I won't go through here, so I'm not interested in changing this.
I'd like to develop a function of this sort:
def get_users_by_identifiers(**kwargs):
# something goes here
return users
The function will return all users that have one of the key=value pairs specified in **kwargs. Here's an example usage:
get_users_by_identifiers(a=1, b=2)
This should return all users for whom a=1 or b=2. I've noticed that the way I've set this up, this amounts to a disjunctive normal form...the SQL query would be something like:
SELECT DISTINCT(user_id) FROM app_identifier
WHERE (key = "a" AND value = "1") OR (key = "b" AND value = "2") ...
I feel like there's got to be some elegant way to take the **kwargs input and do a Django filter on it, in just 1-2 lines, to produce this result. I'm new to Django though, so I'm just not sure how to do it. Here's my function now, and I'm completely sure it's not the best way to do it :)
def get_users_by_identifiers(**identifiers):
users = []
for key, value in identifiers.items():
for identifier in Identifier.objects.filter(key=key, value=value):
if not identifier.user in users:
users.append(identifier.user)
return users
Any ideas? :)
Thanks!
Hello, i have a query about why is my image not being displayed in my background of my program. I mean i did all the steps necessary and still it would'nt be displayed. The code runs perfectly but without having the image displayed. The directory is written in the good location of the image. I am using java with gui. If anyone could help me solve my problem, i would appreciate :) here is the code below:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class hehe extends JPanel{
public hehe(){
setOpaque(false);
setLayout(new FlowLayout());
}
public static void main (String args[]){
JFrame win = new JFrame("yooooo"); // it is automaticcally hidden
JPanel mainPanel = new JPanel(new BorderLayout());
win.add(mainPanel);
JLabel titleLabel = new JLabel("title boss");
titleLabel.setFont(new Font("Arial",Font.BOLD,18));
titleLabel.setForeground(Color.blue);
mainPanel.add(titleLabel,BorderLayout.NORTH);
win.setSize(382,269); // the dimensions of the image
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
public void paint(Graphics g) {
Image a = Toolkit.getDefaultToolkit().getImage("C:\\Users\\andrea\\Desktop\\Gui\\car"); // car is the name of the image file and is in JPEG
g.drawImage(a,0,0,getSize().width,getSize().height,this);
super.paint(g);
}
}
Howdy,
So I've got a simple table with an ID field that's incrementally generated on INSERT.
I've set the mapping up in NHibernate to reflect this:
<id name="ID">
<generator class="identity" />
</id>
And it all works fine.
Trouble is, I need to get the generated ID after I've saved a new model to use elsewhere:
var model = new MyModel();
session.SaveOrUpdate(model);
But at this stage model.ID == null, not the ID.
Any ideas?
Anthony
I've been able to make this code work using CodeIgniter's db->query as follows:
$sql =
'SELECT mapping_code,zone_name,installation_name
FROM installations,appearances,zones
WHERE
installations.installation_id = zones.installation_fk_id
AND appearances.installation_fk_id = installations.installation_id
AND appearances.zone_fk_id = zones.zone_id
AND
appearances.barcode = ?
';
return $this->db->query($sql,array($barcode));
The 'appearances' table throws a 'not unique table' error if I try
this using the Active Record class.
I need to join appearances on
both the zone and installations tables.
How can I do this?