How to get qrcode with qrcode 0.3 Grails Plugin - grails

I have some problem to activate qrcode 0.3 plugin. I already install on my project, and how to get print qrcode?
This is my code
def beforeInsert() {
Integer count = Batch.count()+1
String bc = sprintf('%04d',count)
if( packNoLevel1 != null){
number = prodDate.format('MM/dd/yy') + '/' + packNoLevel1 + '/' + item.code + '/' + bc
}else{
number = prodDate.format('MM/dd/yy') + '/' + packNoLevel2 + '/' + item.code + '/' + bc
}
and how to generate number to qrcode ??
thanks..

First is this beforeInsert an event in your domain? If so generating qr inside your domain does not help with rendering it. Either you need to move that logic into your controller or save that number in database and use it later from a controller when you want to display the qrcode.
I assumed you were able to move the logic into a controller then you just need to pass that number into your view and the view will render the qrCode for you based on that number.
YourController.groovy
def show() {
// this logic needs be tweaked if you decide to have it in controller
//Integer count = Batch.count()+1
//String bc = sprintf('%04d',count)
// if( packNoLevel1 != null){
// number = prodDate.format('MM/dd/yy') + '/' + packNoLevel1 + '/' + item.code + '/' + bc
// }else{
// number = prodDate.format('MM/dd/yy') + '/' + packNoLevel2 + '/' + item.code + '/' + bc
// }
def number = calculateMe()
[...,qrNumber:number]
}
list.gsp
<qrcode:image text="${qrNumber}"/>

Related

How can I select only the last closed order(s) on Metatrader 4?

Right now I select all history trades using a loop whenever there is a new history trade (onTimer handler with 1 second timer period):
/*
3.) History Trades
*/
static int historyTradesTotal=0;
if(OrdersHistoryTotal()==historyTradesTotal) return;
historyTradesTotal = OrdersHistoryTotal();
int i,hstTotal = OrdersHistoryTotal();
string historical_trades = "";
for(i=hstTotal; i >= 0; i--)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
historical_trades = historical_trades +
"historical_trades|" +
version + "|" +
DID + "|" +
IntegerToString(AccountNumber()) + "|" +
IntegerToString(OrderTicket()) + "|" +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "|" +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "|" +
IntegerToString(OrderType()) + "|" +
DoubleToString(OrderLots(),2) + "|" +
OrderSymbol() + "|" +
DoubleToString(OrderOpenPrice(),5) + "|" +
DoubleToString(OrderClosePrice(),5) + "|" +
DoubleToString(OrderStopLoss(),5) + "|" +
DoubleToString(OrderTakeProfit(),5) + "|" +
DoubleToString(OrderCommission(),2) + "|" +
DoubleToString(OrderSwap(),2) + "|" +
DoubleToString(OrderProfit(),2) + "|" +
"<" + OrderComment() + ">|";
}
}
So now how can I just select the orders that have been closed between the last onTimer event to avoid looping through all trades whenever a new one is closed all the time?
The solution should also consider the rare case if two or more trades are closed parallely within one second e.g..
int i = OrdersHistoryTotal();
int a = OrdersHistoryTotal() - 10;
int b = OrdersHistoryTotal();
for (i = a;i < b ;i++)
{
if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY) == true)
{
Alert("orders found"+ OrderTicket() + " " + OrderCloseTime());
}
}
This code works and it's starts from the 10th order from the most previous order in history but if you wanted to check just the previous order you could subsitute 10 for 1 in int a. if you want to check only the last 5 orders change 10 to 5. Simple.
That is not possible in MQL4. Orders are stored and returned by their ids, you cannot apply custom sort. so you have to loop over them all starting from the last to find the one you need. Alternative is to keep all the open orders in CArrayInt or array (add when a new trade is open, delete when found a closed one, read/write when doing init/deinit) and check the live_trades_array elements are still open. That might be much faster if your ea has just several orders and several different ea's on the platform.

Check if number of OrdersHistoryTotal in Metatrader 4 trade history changed

I would like to fire a function as soon as a trade was closed (= the OrdersHistoryTotal increased by at least 1).
Is there any handler in MQL4 for such scenarios?
In my particular setup I have the following function pushSocket which should only push data in case the OrdersHistoryTotal changed.
int i,hstTotal=OrdersHistoryTotal();
string historical_trades = "";
for(i=0;i<hstTotal;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
historical_trades = historical_trades +
"historical_trades|" +
version + "|" +
DID + "|" +
AccountNumber() + "|" +
IntegerToString(OrderTicket()) + "," +
TimeToString(OrderOpenTime(), TIME_DATE|TIME_SECONDS) + "," +
TimeToString(OrderCloseTime(), TIME_DATE|TIME_SECONDS) + "," +
IntegerToString(OrderType()) + "," +
DoubleToString(OrderLots(),2) + "," +
OrderSymbol() + "," +
DoubleToString(OrderOpenPrice(),5) + "," +
DoubleToString(OrderClosePrice(),5) + "," +
DoubleToString(OrderStopLoss(),5) + "," +
DoubleToString(OrderTakeProfit(),5) + "," +
DoubleToString(OrderCommission(),2) + "," +
DoubleToString(OrderSwap(),2) + "," +
DoubleToString(OrderProfit(),2) + "," +
"<" + OrderComment() + ">|";
}
pushSocket.send(StringFormat("%s", historical_trades, true));
I tried to insert a counter to compare it but the counter is deleted every time on memory clean-up.. The above function is nested in a onTick function which executes every second.
There is a function OnTradeAction() in MQL5 that is called every time some trading action is done. But unfortunately this function is not available in MQL4. On the other hand, you can implement a function inside OnTick() that will check that HistoryTraderTotal() increased compared to the previously saved value, and do all the steps you like in that case. A bit more work but almost the same.
OnTimer(){
Mt4OnTradeAction();
otherLogic();
}
Mt4OnTradeAction(){
static int historyTradesTotal=0;
if(HistoryTradesTotal()==historyTradesTotal) return;
historyTradesTotal = HistoryTradesTotal();
processingTrade();
}

Twitter API link parser

I am having an issue and tried to do everything regarding this!! even HttpUtility.ParseQueryString won't help!
I am trying to parse twitter links coming from the API in the form of http://t.co/oEVQbihMWu. I need the fully resolved URL.
My code:
richTextBox1.Clear();
richTextBox1.Visible = true;
SearchOptions SO = new SearchOptions();
SO.GeoCode = richTextBox3.Text + "," + richTextBox2.Text + "mi";
TwitterResponse<TwitterSearchResultCollection> TweetSearchResult = TwitterSearch.Search(tokens, "#blogger", SO);
if (TweetSearchResult.Result != RequestResult.Success) richTextBox1.Text = "connection Error";
else
{
string a = null;
foreach (var tweet in TweetSearchResult.ResponseObject)
{
string b = tweet.User.Location.Contains(",") ? tweet.User.Location.Replace(",", "-") : tweet.User.Location;
a += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", tweet.CreatedDate, b, tweet.User.Id,
tweet.User.ScreenName, tweet.User.Name, tweet.User.NumberOfFollowers, tweet.User.Website, Environment.NewLine);
richTextBox1.AppendText(" " + tweet.CreatedDate + "\n" + tweet.User.Location + "\n" + tweet.User.Id + "\n" + tweet.User.ScreenName + "\n" + tweet.User.Name + "\n" + tweet.User.NumberOfFollowers +
"\n" + tweet.User.Website + "\n" + tweet.Text + "\n\n\n");
}
links being represented by tweet.user.website.
any help? :)
In the API response, there is entities.urls which contains an array of url and expanded_url mappings. Check your library's documentation for equivalent.
Alternatively, if you inspect the response for t.co links, you will find this:
<noscript><META http-equiv="refresh" content="0;URL=http://www.fitnessbydanielle.com"></noscript><title>http://www.fitnessbydanielle.com</title><script>window.opener = null; location.replace("http:\/\/www.fitnessbydanielle.com")</script>
Parse it to get the url.
I managed to crack it.
What I did:
foreach (var tweet in TweetSearchResult.ResponseObject)
{
if(tweet.User.Website != null)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(tweet.User.Website);
req.AllowAutoRedirect = false;
var resp = req.GetResponse();
string realUrl = resp.Headers["Location"];
string b = tweet.User.Location.Contains(",") ? tweet.User.Location.Replace(",", "-") : tweet.User.Location;
a += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", tweet.CreatedDate, b, tweet.User.Id,
tweet.User.ScreenName, tweet.User.Name, tweet.User.NumberOfFollowers, realUrl, Environment.NewLine);
richTextBox1.AppendText(" " + tweet.CreatedDate + "\n" + tweet.User.Location + "\n" + tweet.User.Id + "\n" + tweet.User.ScreenName + "\n" + tweet.User.Name + "\n" + tweet.User.NumberOfFollowers +
"\n" + realUrl + "\n" + tweet.Text + "\n\n\n");
}
}
File.AppendAllText(#".\BloggerTable.csv", a, Encoding.UTF8);
}
Wrapped it inside a condition so no users without website will show and used a webrequest to get the link. stored the location inside the httprequest header for each and every tweet.

why my label formatter is not working as expected in highcharts

I would like to do dynamic texting for my x axis's label. Basically if the label with same month year has been displayed, I do not want to repeat them.
However, in my jsfiddle example, it somehow doesn't work (even though it does return the wanted text). What am I doing wrong?
http://jsfiddle.net/daxu/md2zk/64/
if (labelYear == -1 || year != labelYear) {
$('#MessagePerformanceChartContainerID').data("FirstYear", year);
if (labelYear == -1)
{
usedLabels = [];
}
usedLabels.push(curr_month + ' ' + curr_year);
$('#MessagePerformanceChartContainerID').data("UsedLabels", usedLabels);
////first one so
return curr_month + ' ' + curr_year;
}
else{
var usedLabel = curr_month + ' ' + curr_year;
if ( $.inArray(usedLabel, usedLabels) != -1)
{
usedLabel = curr_day + ' ' + curr_month + ' ' + curr_year;
return 'a';
}
else
{
usedLabels.push(usedLabel);
$('#MessagePerformanceChartContainerID').data("UsedLabels", usedLabels);
alert(usedLabel);
return usedLabel;
}
}
Just formatter is called twice :) See JS console: http://jsfiddle.net/md2zk/66/ - each timestamp is listed twice.
As solution, I would clean up UsedLabels in tickPositioner:
$('#MessagePerformanceChartContainerID').data("UsedLabels", []);
Demo: http://jsfiddle.net/md2zk/67/

help with linq to sql

Help me with this algorithm please.
var companies = companyrepository.GetAll().OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize);
string where = "";
if (op == "eq")
where = field + "=" + data;
else if (op == "cn")
where = field + " LIKE '%"+data+"%'"; ///here lies my problem
companies = companies.Where(where);
its for adding dynamic where clauses to a linq query... op, field, and data are all strings that come with ajax from a jquery grid.
The problem is that it gives me an error when it tries to do the Like operator... it works just fine with the equals operator.
Based on this page, the following should work for you:
if (op == "eq")
where = field + "=" + data;
else if (op == "cn")
where = field + ".Contains(\"" + data + "\")";
I ran some tests on my own data, and it appears to work fine.

Resources