Skip to content

Instantly share code, notes, and snippets.

View paulw54jrn's full-sized avatar

Paul paulw54jrn

  • Sydney, Australia
View GitHub Profile
int read_msg_from_socket(int sock_fd,struct sm_msg *msg){
char buffer[sizeof(struct sm_msg)] = {};
size_t buffer_len = 0;
int nbytes = 0;
if( NULL == msg ){
return -1;
}
do{
nbytes = recv(sock_fd,buffer + buffer_len,sizeof(struct sm_msg) - buffer_len,MSG_WAITALL);
@paulw54jrn
paulw54jrn / RE-3
Last active August 29, 2015 14:02
void removeDot(char *str){
int size = strlen(str);
char *memory = malloc(size);
memset(memory,0,size);
int i,j;
for( i=0;j=0;i<size;i++){
if( str[i] != "." ){
memory[j++] = str[i];
}
@paulw54jrn
paulw54jrn / RE4
Last active August 29, 2015 14:02
int func(int number){
long result = number * 0x4EC4EC4F;
int higher = result >> 34;
int lower = result & 0x00000000FFFFFFFF;
lower = lower >> 31;
return higher - lower;
}
/*
* robotMaze.js
*
* The blue key is inside a labyrinth, and extracting
* it will not be easy.
*
* It's a good thing that you're a AI expert, or
* we would have to leave empty-handed.
*/
/***************
* pointers.js *
***************
*
* You! How are you still alive?
*
* Well, no matter. Good luck getting through this
* maze of rooms - you'll never see me or the Algorithm again!
*/
/**********************
* superDrEvalBros.js *
**********************
*
* You're still here?! Well, Dr. Eval, let's see
* how well you can operate with one less dimension.
*
* Give up now. Unless you have a magic mushroom
* up your sleeve, it's all over.
*/
/*****************
* bossFight.js *
*****************
*
* NO FARTHER, DR. EVAL!!!!
* YOU WILL NOT GET OUT OF HERE ALIVE!!!!
* IT'S TIME YOU SEE MY TRUE FORM!!!!
* FACE MY ROBOT WRATH!!!!!
*/
@paulw54jrn
paulw54jrn / LRU
Last active August 29, 2015 14:05
Python LRU for Leetcode
class doubleLinkedListNode(object):
def __init__(self,key=None,elem=None):
self.prev = None
self.next = None
self.key = key
self.elem = elem
def moveFront(self,headNode):
if self.prev != None:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
import math
class Solution:
def __init__(self,x):
class Solution:
# @return a boolean
def isPalindrome(self, x):
if x < 0 :
return False
first_digit = rest_digit = x
res = 0
while rest_digit != 0 :
first_digit = rest_digit % 10