Laravel 4 Fluent Databasse error for my SQL query
I am getting this error building my SQL query with PHP's Laravel 4 Fluent
Databasse library
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::table()
Here is my code...
$timeCards = TimeCard::table('timeclock_timecard')
->select(DB::raw('DATE_FORMAT(clock_in_datetime, "%Y-%m-%D") AS
clock_in_datetime, timecard_id'))
->where('clock_in_datetime', 'LIKE', '%$year-$month%')
->get();
here is what the query looks like when used outside of laravel in regular
PHP and it works
$sql = "SELECT timecard_id, DATE_FORMAT(clock_in_datetime,'%Y-%m-%D') AS
clock_in_datetime FROM timeclock_timecard WHERE clock_in_datetime LIKE
'%$year-$month%'";
Anyone know how to fix this in Laravel 4?
Buttaccio
Sunday, 1 September 2013
Serialization issues while sending struct over socket
Serialization issues while sending struct over socket
I am developing a Client/Server based on UDP I want to send different
messages to the client from the server. There are different C structures
defined for each message.
I would like to understand what is wrong in the way I am serializing the
data.
struct Task
{
int mType;
int tType;
int cCnt;
int* cId;
char data[128];
};
Serialization/Deserialization functions
unsigned char * serialize_int(unsigned char *buffer, int value)
{
buffer[0] = value >> 24;
buffer[1] = value >> 16;
buffer[2] = value >> 8;
buffer[3] = value;
return buffer + 4;
}
unsigned char * serialize_char(unsigned char *buffer, char value)
{
buffer[0] = value;
return buffer + 1;
}
int deserialize_int(unsigned char *buffer)
{
int value = 0;
value |= buffer[0] << 24;
value |= buffer[1] << 16;
value |= buffer[2] << 8;
value |= buffer[3];
return value;
}
char deserialize_char(unsigned char *buffer)
{
return buffer[0];
}
Sender side code to serialize the structure
unsigned char* serializeTask(unsigned char* msg, const Task* t)
{
msg = serialize_int(msg,t->mType);
msg = serialize_int(msg,t->tkType);
msg = serialize_int(msg,t->cCnt);
for(int i=0; i<t->cCnt; i++)
msg = serialize_int(msg,t->cId[i*4]);
for(int i=0; i<strlen(data); i++)
msg = serialize_char(msg,t->data[i]);
return msg;
}
Receiver side code to de-serialize data
printf("Msg type:%d\n", deserialize_int(message) );
printf("Task Type:%d\n", deserialize_int(message+4) );
printf("Task Count:%d\n", deserialize_int(message+8));
Output
Msg type:50364598 //Expected value is 3
Task Type:-2013036362 //Expected value is 1
Task Count:1745191094 //Expected value is 3
Question 1:
Why is the de-serialized value not same as expected?
Question 2:
How is serialization/de-serialization method different from memcpy?
Task t;
memcpy(&t, msg, sizeof(t)); //msg is unsigned char* holding the struct data
I am developing a Client/Server based on UDP I want to send different
messages to the client from the server. There are different C structures
defined for each message.
I would like to understand what is wrong in the way I am serializing the
data.
struct Task
{
int mType;
int tType;
int cCnt;
int* cId;
char data[128];
};
Serialization/Deserialization functions
unsigned char * serialize_int(unsigned char *buffer, int value)
{
buffer[0] = value >> 24;
buffer[1] = value >> 16;
buffer[2] = value >> 8;
buffer[3] = value;
return buffer + 4;
}
unsigned char * serialize_char(unsigned char *buffer, char value)
{
buffer[0] = value;
return buffer + 1;
}
int deserialize_int(unsigned char *buffer)
{
int value = 0;
value |= buffer[0] << 24;
value |= buffer[1] << 16;
value |= buffer[2] << 8;
value |= buffer[3];
return value;
}
char deserialize_char(unsigned char *buffer)
{
return buffer[0];
}
Sender side code to serialize the structure
unsigned char* serializeTask(unsigned char* msg, const Task* t)
{
msg = serialize_int(msg,t->mType);
msg = serialize_int(msg,t->tkType);
msg = serialize_int(msg,t->cCnt);
for(int i=0; i<t->cCnt; i++)
msg = serialize_int(msg,t->cId[i*4]);
for(int i=0; i<strlen(data); i++)
msg = serialize_char(msg,t->data[i]);
return msg;
}
Receiver side code to de-serialize data
printf("Msg type:%d\n", deserialize_int(message) );
printf("Task Type:%d\n", deserialize_int(message+4) );
printf("Task Count:%d\n", deserialize_int(message+8));
Output
Msg type:50364598 //Expected value is 3
Task Type:-2013036362 //Expected value is 1
Task Count:1745191094 //Expected value is 3
Question 1:
Why is the de-serialized value not same as expected?
Question 2:
How is serialization/de-serialization method different from memcpy?
Task t;
memcpy(&t, msg, sizeof(t)); //msg is unsigned char* holding the struct data
Why my google +1 button doesn't show statistics/numbers?
Why my google +1 button doesn't show statistics/numbers?
I have more than 1K +1 for my website. And I want to show that number next
to my +1 button as it shows in all other websites. But mine is not
working.
If you are not understanding what i am trying to say then look at my
website http://come2chat.com
look at the top center of my webpage. It has a google +1 button but it
doesn't show how many +1 I have on it.
to see the number of +1, i have to visit my google plus one profile at
https://plus.google.com/107969039583165788589/posts
how to fix this problem?
I have more than 1K +1 for my website. And I want to show that number next
to my +1 button as it shows in all other websites. But mine is not
working.
If you are not understanding what i am trying to say then look at my
website http://come2chat.com
look at the top center of my webpage. It has a google +1 button but it
doesn't show how many +1 I have on it.
to see the number of +1, i have to visit my google plus one profile at
https://plus.google.com/107969039583165788589/posts
how to fix this problem?
CreateFile fails on opening lsass.exe
CreateFile fails on opening lsass.exe
I'm working on a program, which collects some statistics about processes,
which are running on the system.
I've got a code, which retrieves some routine information, such as
executable file version, publisher and so on.
The code works fine for me until I open lsass.exe. When I try to open file
for reading, CreateFile fails with error ERROR_FILE_NOT_FOUND.
Here is the code:
auto FileHandle
= CreateFile(file_to_process.c_str(), // C:\Windows\System32\lsass.exe
GENERIC_READ,
FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if ( INVALID_HANDLE_VALUE == FileHandle )
{
int err_v = GetLastError(); // ERROR_FILE_NOT_FOUND
}
This code is a part of a system service, which is running with 'SYSTEM'
privileges.
I'm working on a program, which collects some statistics about processes,
which are running on the system.
I've got a code, which retrieves some routine information, such as
executable file version, publisher and so on.
The code works fine for me until I open lsass.exe. When I try to open file
for reading, CreateFile fails with error ERROR_FILE_NOT_FOUND.
Here is the code:
auto FileHandle
= CreateFile(file_to_process.c_str(), // C:\Windows\System32\lsass.exe
GENERIC_READ,
FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if ( INVALID_HANDLE_VALUE == FileHandle )
{
int err_v = GetLastError(); // ERROR_FILE_NOT_FOUND
}
This code is a part of a system service, which is running with 'SYSTEM'
privileges.
Saturday, 31 August 2013
This is 2013. C++11 and C++14 is on us. But why still no dedicated IDE for C++?
This is 2013. C++11 and C++14 is on us. But why still no dedicated IDE for
C++?
I'm 26 years old. C++ is nearly 35 years old.
I'm really baffled at seeing the evolution of C++ in my 15 years of
programming. I started with Turbo C and its blue screen in late 90's to
vim/emacs in early 2000's. From there on, I have moved to Java, Python and
Ruby. All beautiful languages having extensive set of IDE's which makes
programming easy and fun.
But As for C++. With it's latest iteration already in (C++11) and next
iteration already announced (C++14), Why is it that there's still no
dedicated editor, fully supporting latest standards and libraries along
with other goodies like intellisense and documentation? This is really
ironic, since today, almost every language have extensive toolsets
published and updated periodically.
C++ is not as easy to learn. An IDE will surely go a long way getting new
programmers on-boarding process easy to a great extent.
If anyone knows any reason behind it, please edify us.
Update
First of all, I understand that most seasoned programmers don't care for
IDEs. They spin-off their own toolchains and programming environments with
emacs, gdb, binutils etc. I get that! But this question is to enquire as
to why, when other languages all have extensive IDE and tool support
(Dreamweaver, NetBeans, Eclipse, PyCharm, IntelliJ Idea, Octave, R Studio,
and list goes on) then why C++ doesn't have any.
C++?
I'm 26 years old. C++ is nearly 35 years old.
I'm really baffled at seeing the evolution of C++ in my 15 years of
programming. I started with Turbo C and its blue screen in late 90's to
vim/emacs in early 2000's. From there on, I have moved to Java, Python and
Ruby. All beautiful languages having extensive set of IDE's which makes
programming easy and fun.
But As for C++. With it's latest iteration already in (C++11) and next
iteration already announced (C++14), Why is it that there's still no
dedicated editor, fully supporting latest standards and libraries along
with other goodies like intellisense and documentation? This is really
ironic, since today, almost every language have extensive toolsets
published and updated periodically.
C++ is not as easy to learn. An IDE will surely go a long way getting new
programmers on-boarding process easy to a great extent.
If anyone knows any reason behind it, please edify us.
Update
First of all, I understand that most seasoned programmers don't care for
IDEs. They spin-off their own toolchains and programming environments with
emacs, gdb, binutils etc. I get that! But this question is to enquire as
to why, when other languages all have extensive IDE and tool support
(Dreamweaver, NetBeans, Eclipse, PyCharm, IntelliJ Idea, Octave, R Studio,
and list goes on) then why C++ doesn't have any.
Pygame .Rect won't "collide" with mouse
Pygame .Rect won't "collide" with mouse
I am working on a simple game and with small circle "systems". I would
like to be able to click each system so that I can do more with it later
in game but I am having difficulty recognizing only a single click. I pass
the randomly generated coords to a dictionary and then the collision for
each rect should be checked with the mouse position but for some reason
that is not working anymore. Any help is appreciated.
Here is some of the more relevent code.
for i in range(NumSystems):
SysSize = random.randint(3,SystemSize)
SysY = random.randint(SystemSize*2,GVPHEIGHT-SystemSize*2)
SysX = random.randint(OverLayWidth+SystemSize*2,WINWIDTH-SystemSize*2)
SysList[str('SysNum')+str(i)] = ((SysSize,(SysX,SysY)))
SysCoords[str('SysNum')+str(i)] = pygame.draw.circle(DISPLAYSURF,
WHITE, (SysX,SysY), SysSize, 0)
pygame.display.update()
#time.sleep(.25)
#Code above is putting the random Coords into a dictionary.
while True:
MousePos=mouse.get_pos()
for event in pygame.event.get():
if event.type == QUIT:
pygame.QUIT()
sys.exit()
elif event.type == KEYDOWN:
# Handle key presses
if event.key == K_RETURN:
#Restarts the map
main()
elif event.type == MOUSEBUTTONDOWN:
if event.button == 1:
SysClicky(MousePos)
if SysClicked == True:
print('Clicked System')
elif SysClicked == False:
print('Something Else Clicked')
def SysClicky(MousePos):
for i in range(NumSystems):
print('Made to the SysClicky bit')
if SysCoords['SysNum'+str(i)].collidepoint(MousePos):
SysClicked = True
print(SysClicked)
return SysClicked
else:
SysClicked = False
return SysClicked
I am working on a simple game and with small circle "systems". I would
like to be able to click each system so that I can do more with it later
in game but I am having difficulty recognizing only a single click. I pass
the randomly generated coords to a dictionary and then the collision for
each rect should be checked with the mouse position but for some reason
that is not working anymore. Any help is appreciated.
Here is some of the more relevent code.
for i in range(NumSystems):
SysSize = random.randint(3,SystemSize)
SysY = random.randint(SystemSize*2,GVPHEIGHT-SystemSize*2)
SysX = random.randint(OverLayWidth+SystemSize*2,WINWIDTH-SystemSize*2)
SysList[str('SysNum')+str(i)] = ((SysSize,(SysX,SysY)))
SysCoords[str('SysNum')+str(i)] = pygame.draw.circle(DISPLAYSURF,
WHITE, (SysX,SysY), SysSize, 0)
pygame.display.update()
#time.sleep(.25)
#Code above is putting the random Coords into a dictionary.
while True:
MousePos=mouse.get_pos()
for event in pygame.event.get():
if event.type == QUIT:
pygame.QUIT()
sys.exit()
elif event.type == KEYDOWN:
# Handle key presses
if event.key == K_RETURN:
#Restarts the map
main()
elif event.type == MOUSEBUTTONDOWN:
if event.button == 1:
SysClicky(MousePos)
if SysClicked == True:
print('Clicked System')
elif SysClicked == False:
print('Something Else Clicked')
def SysClicky(MousePos):
for i in range(NumSystems):
print('Made to the SysClicky bit')
if SysCoords['SysNum'+str(i)].collidepoint(MousePos):
SysClicked = True
print(SysClicked)
return SysClicked
else:
SysClicked = False
return SysClicked
Clear boost::asio::io_service after stop()
Clear boost::asio::io_service after stop()
I am using (single threaded) a boost::asio:io_service to handle a lot of
tcp connections. For each connection I use a deadline_timer to catch
timeouts. If any of the connections times out, I can use none of the
results of the other connections. Therefore I want to completely restart
my io_service. I thought that calling io_service.stop() would allow
"finished" handlers in the queue to be called and would call handlers in
the queue with an error.
However it looks like the handlers remain in the queue and therefore
calling io_service.reset() and later io_service.run() brings the old
handlers back up. Can anyone confirm that the handlers indeed remain in
the queue even after io_service.stop() is called. And if so, what are the
possibilities to completly reset the io_service, e.g. remove all queued
handlers?
I am using (single threaded) a boost::asio:io_service to handle a lot of
tcp connections. For each connection I use a deadline_timer to catch
timeouts. If any of the connections times out, I can use none of the
results of the other connections. Therefore I want to completely restart
my io_service. I thought that calling io_service.stop() would allow
"finished" handlers in the queue to be called and would call handlers in
the queue with an error.
However it looks like the handlers remain in the queue and therefore
calling io_service.reset() and later io_service.run() brings the old
handlers back up. Can anyone confirm that the handlers indeed remain in
the queue even after io_service.stop() is called. And if so, what are the
possibilities to completly reset the io_service, e.g. remove all queued
handlers?
Subscribe to:
Comments (Atom)