Sunday, 1 September 2013

Laravel 4 Fluent Databasse error for my SQL query

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?

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

How to generate filename appropiate to the list assigned "years"

How to generate filename appropiate to the list assigned "years"

How to generate filename appropiate to the list assigned "years". I need
to know how to generate the "calendar" name appropiate to the year_list. I
want to add 2000 to 2013 year_list at once, because right now I have to
edit and change every year number once I run the script to output
different year.
year_list = [2000]
FILENAME = "calendar_2000.txt"
What I need is year_list to be 2000, 2001, 2002.. up to 2013 and the
output file to be generated accordingly to the year_list numbers.

javascript image swap uploaded in a hosting

javascript image swap uploaded in a hosting

Hi guys i'm new to web design, i uploaded all my files on a hosting, and
using javascript for an image swap. What happens it everytime i visit the
page where the image swap is, it won't load the pictures but only one
image, i checked the image source, everything seems to be placed right. I
don't know why it's only loading 1 image so far? can you please tell me
what's wrong?
Here's a screenshot whenever i visit the image swap page...
http://s21.postimg.org/puvuq62jb/samp.jpg
is it because of internet slow speed? it's working on localhost...

Saturday, 31 August 2013

SOLR numeric value search with LUKE

SOLR numeric value search with LUKE

While Lucene numeric range search with LUKE exists, it doesn't answer the
question so I have no better idea than ask again. I am using Solr 3.6.2
(the app I work with is not 4.0 compatible) and Luke 3.5 -- not because I
am particularly attracted to Luke but because I can't find anything else.
Is there a better tool to debug Solr indexes?
Here's the field and the value:

I go to the search tab, click the Use XML Parser and then
<BooleanQuery>
<Clause fieldName="is_filter_by" occurs="must">
<NumericRangeQuery type="int" lowerTerm="1" upperTerm="3" />
</Clause>
</BooleanQuery>
No results. It gets parsed to +is_filter_by:[1 TO 3]. I can not find any
documentation on this XML format so I have no idea whether this is correct
or not.
I tried to set the default field to is_filter_by and enter 1 without XML,
still no results.
I tried two clauses. I tried occurs="should".
Reconstruct & edit says: Stored original 1.

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

Structural-type casting does not work with String?

Structural-type casting does not work with String?

Given these definitions:
type HasMkString = { def mkString(sep:String):String }
val name = "John"
val names = List("Peter", "Gabriel")
And given these facts:
name.mkString("-") // => "J-o-h-n"
name.isInstanceOf[HasMkString] // => true
names.isInstanceOf[HasMkString] // => true
While this works:
names.asInstanceOf[HasMkString].mkString("-")
// => Peter-Gabriel
This does not work:
name.asInstanceOf[HasMkString].mkString(", ")
java.lang.NoSuchMethodException: java.lang.String.mkString(java.lang.String)
at java.lang.Class.getMethod(Class.java:1624)
at .reflMethod$Method1(<console>:10)
at .<init>(<console>:10)
at .<clinit>(<console>:10)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
Why is that? Is it because String is a Java class? Can I work around this
problem? Is this a bug/shortcoming in the Scala implementation?