Inserting Specific function within a Block. Scripting
Consider you have a file test.cpp with below lines
Test(func_class,func1)
{
Test_Func1();
Test_Func2();
Test_Func3();
}
Test(func_class,func3)
{
Test_Func1();
Test_Func9();
Test_Func3();
}
Test(func_class,func2)
{
Test_Func6();
Test_Func7();
Test_Func3();
}
Now i want to insert a new line in between the curly braces for e:g in
Test(func_class,func1/2/3) after inserting will be like
Test(func_class,func1)
{
Test_Func1();
Test_newFunc6();
Test_Func2();
Test_Func3();
}
Test(func_class,func3)
{
Test_Func1();
Test_newFunc6();
Test_Func9();
Test_Func3();
}
Test(func_class,func2)
{
Test_Func6();
Test_newFunc6();
Test_Func7();
Test_Func3();
}
this can be done using scripting . can anyone please suggest shell script
or perl python to do this,
Thursday, October 3, 2013
Wednesday, October 2, 2013
has_many / belongs_to associations in RoR
has_many / belongs_to associations in RoR
I've read the guide on associations but I feel like I'm still not
completely comprehending so I want to ask a couple of questions just to be
sure. Let's say I am making an app that will, among other things, list
large cities all over the world. I would plan on having a view that starts
at continent level and can be filtered down. So I would start with a
Continent model. And then a Country model. Now, within the Continent model
I would define an association as has_many :countries. And in the Country
model I would use belongs_to :continents. That much I grasp. So my next
model would be a model for states / province. Let's just call it Province
since that is more common throughout the world. So now I have my Province
model, and I would use belongs_to :country. And likewise Countries would
have has_many :provinces. My first question is, how do I describe the
association between Province and Continent? Has_many through describes
associations where both models have many. A Province only has one
Continent. Has_one through describes a relationship between objects that
have a one to one relationship via a third object. Again, this isn't the
case because a Continent will have many Provinces. So that is my primary
question.. how to describe relationships that exist in a one to many
through context. My second question would be just asking for tips on
writing the migrations for this in a situation where I add another layer,
say County, later on. But the main problem is just understand how to
express the relationships I described. Or if they even need to be
expressed.
I've read the guide on associations but I feel like I'm still not
completely comprehending so I want to ask a couple of questions just to be
sure. Let's say I am making an app that will, among other things, list
large cities all over the world. I would plan on having a view that starts
at continent level and can be filtered down. So I would start with a
Continent model. And then a Country model. Now, within the Continent model
I would define an association as has_many :countries. And in the Country
model I would use belongs_to :continents. That much I grasp. So my next
model would be a model for states / province. Let's just call it Province
since that is more common throughout the world. So now I have my Province
model, and I would use belongs_to :country. And likewise Countries would
have has_many :provinces. My first question is, how do I describe the
association between Province and Continent? Has_many through describes
associations where both models have many. A Province only has one
Continent. Has_one through describes a relationship between objects that
have a one to one relationship via a third object. Again, this isn't the
case because a Continent will have many Provinces. So that is my primary
question.. how to describe relationships that exist in a one to many
through context. My second question would be just asking for tips on
writing the migrations for this in a situation where I add another layer,
say County, later on. But the main problem is just understand how to
express the relationships I described. Or if they even need to be
expressed.
Getting back urls while loading multiple urls with YQL
Getting back urls while loading multiple urls with YQL
I'm using YQL to fetch a bunch of pages, some of which could be offline
(obviously I don't know which ones). I'm using this query:
SELECT * FROM html WHERE url IN ("http://www.whooma.net",
"http://www.dfdsfsdgsfagdffgd.com", "http://www.cnn.com")
Where the first and the last one are actual sites, while the second one
obviously doesn't exist. Two results are actually returned but the url
from where they were loaded doesn't appear anywhere. So what would be the
way to find out which html page belongs to which url, if not every page in
the query is loaded?
Thank you very much indeed!
Matteo
I'm using YQL to fetch a bunch of pages, some of which could be offline
(obviously I don't know which ones). I'm using this query:
SELECT * FROM html WHERE url IN ("http://www.whooma.net",
"http://www.dfdsfsdgsfagdffgd.com", "http://www.cnn.com")
Where the first and the last one are actual sites, while the second one
obviously doesn't exist. Two results are actually returned but the url
from where they were loaded doesn't appear anywhere. So what would be the
way to find out which html page belongs to which url, if not every page in
the query is loaded?
Thank you very much indeed!
Matteo
Formatting the output of a String in C#
Formatting the output of a String in C#
I am new to C#. I am studying it in a module in college. We have been
given an assignment which involves us having to create a simple booking
application using the various components included in the toolbox in Visual
Studio.
The UI has a ListBox which enables the user to select multiple names of
people that will attend the event. The selected items are concatenated to
a String and output in a Label when the user confirms the selection.
This is the code where I get the values from the ListBox
protected void btnRequest_Click(object sender, EventArgs e)
{
//Update the summary label with the details of the booking.
n = name.Text;
en = eventName.Text;
r = room.SelectedItem.ToString();
d = cal.SelectedDate.ToShortDateString();
foreach (ListItem li in attendees.Items)
{
if (li.Selected)
{
people += li.Text + " ";
}
}
confirmation.Text = r + " has been booked on " + d + " by " + n + "
for " + en + ". " + people + " will be attending.";
}
Below is my entire code:
public partial class _Default : System.Web.UI.Page
{
//Variables
public TextBox name;
public TextBox eventName;
public Label confirmation;
public DropDownList room;
public Calendar cal;
public Button btn;
public ListBox attendees;
//Booking variables - store all information relating to booking in
these variables
public String n; //name of person placing booking
public String en; //name of event
public String r; //room it will take place
public List<String> att; //list of people attending
public String d; //date it will be held on
public String people;
protected void Page_Load(object sender, EventArgs e)
{
//Get references to components
name = txtName;
eventName = txtEvent;
room = droplistRooms;
attendees = attendeelist;
cal = Calendar1;
btn = btnRequest;
confirmation = lblSummary;
}
protected void btnRequest_Click(object sender, EventArgs e)
{
//Update the summary label with the details of the booking.
n = name.Text;
en = eventName.Text;
r = room.SelectedItem.ToString();
d = cal.SelectedDate.ToShortDateString();
foreach (ListItem li in attendees.Items)
{
if (li.Selected)
{
people += li.Text + " ";
}
}
confirmation.Text = r + " has been booked on " + d + " by " + n +
" for " + en + ". " + people + " will be attending.";
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
d = cal.SelectedDate.ToShortDateString();
}
The output is this:
Room 2 has been booked on 08/10/2013 by Jason Manford for Comedy Gig. Jack
Coldrick Bill Gates Larry Page Jimmy Wales will be attending.
However I would like to add an and to the last name of the person
attending the event. How would I go about doing this. Would I have to use
a List?
Many Thanks...
I am new to C#. I am studying it in a module in college. We have been
given an assignment which involves us having to create a simple booking
application using the various components included in the toolbox in Visual
Studio.
The UI has a ListBox which enables the user to select multiple names of
people that will attend the event. The selected items are concatenated to
a String and output in a Label when the user confirms the selection.
This is the code where I get the values from the ListBox
protected void btnRequest_Click(object sender, EventArgs e)
{
//Update the summary label with the details of the booking.
n = name.Text;
en = eventName.Text;
r = room.SelectedItem.ToString();
d = cal.SelectedDate.ToShortDateString();
foreach (ListItem li in attendees.Items)
{
if (li.Selected)
{
people += li.Text + " ";
}
}
confirmation.Text = r + " has been booked on " + d + " by " + n + "
for " + en + ". " + people + " will be attending.";
}
Below is my entire code:
public partial class _Default : System.Web.UI.Page
{
//Variables
public TextBox name;
public TextBox eventName;
public Label confirmation;
public DropDownList room;
public Calendar cal;
public Button btn;
public ListBox attendees;
//Booking variables - store all information relating to booking in
these variables
public String n; //name of person placing booking
public String en; //name of event
public String r; //room it will take place
public List<String> att; //list of people attending
public String d; //date it will be held on
public String people;
protected void Page_Load(object sender, EventArgs e)
{
//Get references to components
name = txtName;
eventName = txtEvent;
room = droplistRooms;
attendees = attendeelist;
cal = Calendar1;
btn = btnRequest;
confirmation = lblSummary;
}
protected void btnRequest_Click(object sender, EventArgs e)
{
//Update the summary label with the details of the booking.
n = name.Text;
en = eventName.Text;
r = room.SelectedItem.ToString();
d = cal.SelectedDate.ToShortDateString();
foreach (ListItem li in attendees.Items)
{
if (li.Selected)
{
people += li.Text + " ";
}
}
confirmation.Text = r + " has been booked on " + d + " by " + n +
" for " + en + ". " + people + " will be attending.";
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
d = cal.SelectedDate.ToShortDateString();
}
The output is this:
Room 2 has been booked on 08/10/2013 by Jason Manford for Comedy Gig. Jack
Coldrick Bill Gates Larry Page Jimmy Wales will be attending.
However I would like to add an and to the last name of the person
attending the event. How would I go about doing this. Would I have to use
a List?
Many Thanks...
Tuesday, October 1, 2013
Does it matter that I update the gcc 4.6 to 4.7 or higher in Ubuntu 12.04(LTS)
Does it matter that I update the gcc 4.6 to 4.7 or higher in Ubuntu
12.04(LTS)
I found that more and more open source libraries will use C++11 features,
and my Ubuntu Desktop 12.04 just has gcc 4.6, I want to use the
update-alternatives to change the default gcc version into 4.7 or 4.8. I
wonder that, if the libraries in the /usr/local/lib compiled by gcc 4.6
will need to be recompiled by the new gcc 4.7/4.8. In my opinion, if the
dependency libraries are still in the system, there is no need to
recompile. But, If one dependency library compiled by the new gcc 4.7, is
the dependency among libraries still right? Sorry for my poor English.
Thanks.
12.04(LTS)
I found that more and more open source libraries will use C++11 features,
and my Ubuntu Desktop 12.04 just has gcc 4.6, I want to use the
update-alternatives to change the default gcc version into 4.7 or 4.8. I
wonder that, if the libraries in the /usr/local/lib compiled by gcc 4.6
will need to be recompiled by the new gcc 4.7/4.8. In my opinion, if the
dependency libraries are still in the system, there is no need to
recompile. But, If one dependency library compiled by the new gcc 4.7, is
the dependency among libraries still right? Sorry for my poor English.
Thanks.
What is wrong with getchar (as program is exiting without a check at do while loop)?
What is wrong with getchar (as program is exiting without a check at do
while loop)?
In this in the main function the usage of getchar in do while loop is
creating problem (as per what i m figuring out) and using getch resolves
it..plz help why so..
#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;
const int size = 10;
int main()
{
int stack[size];
int top = -1;
char ch;
char chh;
do {
cout << "what you want to do? 1:Push,2:Pop,3:Display \n";
cin >> ch;
if (ch == '1')
{
int a;
cout << "enter element to be entered";
a = getchar();
int r = push(stack, &top, a);
if (r == -1) cout << "array already full \n";
}
if (ch == '2')
{
pop(stack, &top);
}
if (ch == '3')
{
display(stack, &top);
}
cout << "enter y to continue";
chh = getchar();
} while (chh == 'y');
return 0;
}
while loop)?
In this in the main function the usage of getchar in do while loop is
creating problem (as per what i m figuring out) and using getch resolves
it..plz help why so..
#include <iostream>
#include <cstring>
#include <stdio.h>
using namespace std;
const int size = 10;
int main()
{
int stack[size];
int top = -1;
char ch;
char chh;
do {
cout << "what you want to do? 1:Push,2:Pop,3:Display \n";
cin >> ch;
if (ch == '1')
{
int a;
cout << "enter element to be entered";
a = getchar();
int r = push(stack, &top, a);
if (r == -1) cout << "array already full \n";
}
if (ch == '2')
{
pop(stack, &top);
}
if (ch == '3')
{
display(stack, &top);
}
cout << "enter y to continue";
chh = getchar();
} while (chh == 'y');
return 0;
}
About the generating function of the sum of roll dice values.
About the generating function of the sum of roll dice values.
I thought this exercise would be fairly easy, but it seems i can't find a
proper approach to it.
I have to prove that $f(x) = (1-x-x^2-x^3-x^4-x^5-x^6)^{-1}$ is the
function that generates the number of forms we can get a number $n$ as the
sum of the values given rolling a dice -as many times as is needed-.
My first excerpt is to note that $f(x) =
\displaystyle\frac{1}{1-(\sum_{i=1}^6x^i)}=\displaystyle\sum_{k=0}^{\infty}(x+\dots+x^6)^k$.
Now i would like to work from 'the other side' and see how many forms are
to write a number $n$ as the sum of numbers from 1 to 6. I have in mind
two steps:
(1) If i need to find the number of solution -without the restriction from
1 to 6- i'd have to find how many solutions are for each of the following
equations $x_1=n$; $x_1+x_2=n$, $\dots$; $x_1+\dots+x_n=n$. Then i found
out that for each $m$ there are $\sum_{k=0}^{m-1}\binom{m-1}{k}=2^{m-1}$.
(2) Now i woud like to know how many solutions are if i consider the
restriction $1\leq x_i \leq 6$. I'm not sure how to go from here, but i've
been thinking about the principle of inclusion and exclusion and maybe it
may goes as follows:
(2.1) There's only one sol. for $x_1=n$
(2.2) For $x_1+x_2=n$ with $0\leq x_i \leq 6$.
There are $\binom{2+n-1}{n}=\binom{1+n}{n}$ solutions with $x_i\leq 0$ Let
say that $x_1,x_2$ is a solution that sastisfies the condition $c_i$ if
$x_i>6$. The answer should be $N(\bar{c_1},\bar{c_2}).$ By symmetry
$N(c_1)=N(c_2)$. Now i'm looking the integer solutions for $x_1+x_2=n-7$
then $N(c_i)=\binom{2+(n-7)+1}{n-7}=\binom{n-4}{n-7}$, also $N(c_ic_j) =
\binom{2+(n-14)-1}{n-14}=\binom{n-11}{n-14}$.
Then $N(\bar{c_1},\bar{c_2})=
\binom{n+1}{n}-\binom{2}{1}\binom{n-4}{n-7}+\binom{2}{2}\binom{n-11}{n-14}$
gives the numer of solutions which satisfies $x_i\leq 6$?.
But how can i get rid of the solutions that involve $x_i = 0$?
Would be a good idea keep trying with this or there is an easier way?. I
thought that if i get the number of solutions for $x_1+\dots+x_n=n$ with
the restriction given i could find the generating function, but looking at
the $f(x)$ given i'm not sure if what i did may help somehow.
Any hints?.
I thought this exercise would be fairly easy, but it seems i can't find a
proper approach to it.
I have to prove that $f(x) = (1-x-x^2-x^3-x^4-x^5-x^6)^{-1}$ is the
function that generates the number of forms we can get a number $n$ as the
sum of the values given rolling a dice -as many times as is needed-.
My first excerpt is to note that $f(x) =
\displaystyle\frac{1}{1-(\sum_{i=1}^6x^i)}=\displaystyle\sum_{k=0}^{\infty}(x+\dots+x^6)^k$.
Now i would like to work from 'the other side' and see how many forms are
to write a number $n$ as the sum of numbers from 1 to 6. I have in mind
two steps:
(1) If i need to find the number of solution -without the restriction from
1 to 6- i'd have to find how many solutions are for each of the following
equations $x_1=n$; $x_1+x_2=n$, $\dots$; $x_1+\dots+x_n=n$. Then i found
out that for each $m$ there are $\sum_{k=0}^{m-1}\binom{m-1}{k}=2^{m-1}$.
(2) Now i woud like to know how many solutions are if i consider the
restriction $1\leq x_i \leq 6$. I'm not sure how to go from here, but i've
been thinking about the principle of inclusion and exclusion and maybe it
may goes as follows:
(2.1) There's only one sol. for $x_1=n$
(2.2) For $x_1+x_2=n$ with $0\leq x_i \leq 6$.
There are $\binom{2+n-1}{n}=\binom{1+n}{n}$ solutions with $x_i\leq 0$ Let
say that $x_1,x_2$ is a solution that sastisfies the condition $c_i$ if
$x_i>6$. The answer should be $N(\bar{c_1},\bar{c_2}).$ By symmetry
$N(c_1)=N(c_2)$. Now i'm looking the integer solutions for $x_1+x_2=n-7$
then $N(c_i)=\binom{2+(n-7)+1}{n-7}=\binom{n-4}{n-7}$, also $N(c_ic_j) =
\binom{2+(n-14)-1}{n-14}=\binom{n-11}{n-14}$.
Then $N(\bar{c_1},\bar{c_2})=
\binom{n+1}{n}-\binom{2}{1}\binom{n-4}{n-7}+\binom{2}{2}\binom{n-11}{n-14}$
gives the numer of solutions which satisfies $x_i\leq 6$?.
But how can i get rid of the solutions that involve $x_i = 0$?
Would be a good idea keep trying with this or there is an easier way?. I
thought that if i get the number of solutions for $x_1+\dots+x_n=n$ with
the restriction given i could find the generating function, but looking at
the $f(x)$ given i'm not sure if what i did may help somehow.
Any hints?.
Prove modular inequalities $ab + ac\le a(b+ac)$ and $(a+b)(a+c)\ge a+b(a+c)$
Prove modular inequalities $ab + ac\le a(b+ac)$ and $(a+b)(a+c)\ge a+b(a+c)$
How to prove
$$(a\cdot b)+(a\cdot c)\le a\cdot\big(b+(a\cdot c)\big)$$
and
$$(a+b)\cdot(a+c)\ge a+\big(b\cdot(a+c)\big)\;?$$
I have tried this. Using distributive property, I think we can get
$$a+(b\cdot c) \le (a+b)\cdot(a+c)$$
and
$$a\cdot(b+c) \ge (a\cdot b) + (a\cdot c)\;.$$
Now what should I do?
How to prove
$$(a\cdot b)+(a\cdot c)\le a\cdot\big(b+(a\cdot c)\big)$$
and
$$(a+b)\cdot(a+c)\ge a+\big(b\cdot(a+c)\big)\;?$$
I have tried this. Using distributive property, I think we can get
$$a+(b\cdot c) \le (a+b)\cdot(a+c)$$
and
$$a\cdot(b+c) \ge (a\cdot b) + (a\cdot c)\;.$$
Now what should I do?
Subscribe to:
Comments (Atom)