Skip to content

Instantly share code, notes, and snippets.

@elvinio
elvinio / Books
Last active August 29, 2015 14:09
Books on Programming and Computer Science
C++
The C++ Programming Language, Fourth Edition
By: Bjarne Stroustrup
Programming: Principles and Practice Using C++, Second Edition
By: Bjarne Stroustrup
A Tour of C++
By: Bjarne Stroustrup
@elvinio
elvinio / Useful Linux Commands
Last active August 29, 2015 14:09
Useful Linux Commands
# doing a strace on a process
strace -c -f ./D4Adaptor
# listening on multicast group in iperf
/usr/local/bin/iperf -s -i 1 -u -B 224.0.28.46 -p 6313
# spamming multicast
/usr/local/bin/iperf -c 224.0.28.46 -u -T 32 -t 60 -i 5 -p 6313
@elvinio
elvinio / gist:60304c57242a67a22d64
Created December 4, 2014 06:02
C++ Atomic Compare Exchange
struct BufferPos{
uint8_t write;
uint8_t read;
};
std::atomic<BufferPos> bufferPos;
--
Thread 1
@elvinio
elvinio / FizzBuzz.py
Last active August 29, 2015 14:14
FizzBuzz in Python
#!/usr/bin/env python
for x in range(0, 100):
if x%3==0 and x%5==0:
print 'FizzBuzz'
elif x%3==0:
print 'Fizz'
elif x%5==0:
print 'Buzz'
else:
print x
@elvinio
elvinio / gist:9c5eed9399f2beac6869
Created February 15, 2015 13:54
Node.js Socket Server
net.createServer(
function(sock) {
console.log("Received connection from " + sock.remoteAddress + ':' + sock.remotePort);
sock.on('data', function(data){
string = data.toString('ascii')
setTimeout(function(){
sock.write(data.slice(0, 20));
}, 3000);
});
sock.on('close', function(data){
@elvinio
elvinio / ReverseString.c
Last active August 29, 2015 14:15
Reverse a string in place in different languages
// C
#include <stdio.h>
int main(void){
char string[] = "elvino";
int len = strlen(string);
int mid = len / 2;
len--;
int i = 0;
char tmp;
while(i!=mid){
@elvinio
elvinio / ReverseString.hs
Created February 18, 2015 01:24
Reverse string in haskell
reverse' :: [a] -> [a]
reverse' [] = []
reverse' [x] = [x]
reverse' (x:xs) = reverse'(xs) ++ [x]
@elvinio
elvinio / ReverseString.py
Last active August 29, 2015 14:15
Reverse string in python
#!/usr/bin/env python
# iterative
string = "testing"
newstring = ""
for s in string[:]:
newstring = s + newstring
print newstring
# recursive
palindrome :: (Eq a) => [a]->Bool
palindrome (xs)
| xs == reverse(xs) = True
| otherwise = False