This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def moving_average(data_set, period=3): | |
avgs = [] | |
for idx, item in enumerate(data_set[period-1:]): | |
avgs.append(round(sum(data_set[idx:period+idx]) / float(period), 2)) | |
return avgs | |
data = [1, 2, 3, 6, 9, 12, 20, 28, 30, 25, 22, 20, 15, 12, 10] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def moving_average(data_set, periods=3): | |
weights = np.ones(periods) / periods | |
return np.convolve(data_set, weights, mode='valid') | |
data = [1, 2, 3, 6, 9, 12, 20, 28, 30, 25, 22, 20, 15, 12, 10] | |
ma = moving_average(np.asarray(data), 3) | |
assert (np.around(ma, decimals=2)==np.array([2.0, 3.67, 6.0, 9.0, 13.67, 20.0, 26.0, 27.67, 25.67, 22.33, 19.0, 15.67, 12.33])).all() == True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import numpy as np | |
def naive(): | |
x = 0 | |
y = 0 | |
for i in range(1, 1001): | |
x += pow(i, 2) | |
y += i | |
return pow(y, 2) - x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void *rtp_thread(void *args) | |
{ | |
struct ap_info* thread_info = args; | |
struct ast_frame *f = NULL; | |
struct ast_rtp *astRtp = NULL; // XXX <-- Replaced by rtp_engine | |
int pktCnt=0; | |
int res = 0; | |
astRtp = ast_rtp_new_fd(thread_info->sockFd); // XXX <-- Doesn't event exist anymore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Struct to hold all my application's commonly used packages | |
type MySpecialContext struct { | |
Render render.Render | |
Logger *log.Logger | |
Session sessions.Session | |
Db *mgo.Database | |
Ctx martini.Context | |
App *ApplicationConfig | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"github.com/go-martini/martini" | |
"log" | |
"net/http" | |
"path" | |
"time" | |
"strings" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example of accessing the notes slides of a presentation. | |
Requires python-pptx 0.5.6 or later. | |
[email protected] | |
""" | |
from pptx.util import lazyproperty, Pt | |
from pptx.parts.slide import BaseSlide, Slide, _SlideShapeTree, _SlidePlaceholders | |
from pptx.shapes.shape import BaseShape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;NASM=nasm | |
;LD=ld | |
;LIBS=-lc | |
;LD_INCLUDES=-I/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 | |
; | |
; | |
;echoserver: echoserver.o | |
; ${LD} ${LIBS} ${LD_INCLUDES} -o echoserver echoserver.o | |
; | |
;echoserver.o: echoserver.s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PATH=/home/rday/Development/os/rump/qemu/bin:$PATH:/home/rday/Development/os/rump/rumprun/app-tools | |
cython --embed -v -3 -Werror main.py | |
x86_64-rumprun-netbsd-gcc main.c -I../Python-3.4.3/pythondist/include/python3.4m -L../Python-3.4.3/pythondist/lib -lpython3.4m -lutil -lm -lz -lssl -lcrypto | |
rumpbake hw_virtio a.bin a.out | |
rumprun qemu -D 1234 -i \ | |
-I if,vioif,'-net tap,ifname=tap0,script=no'\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import struct | |
import fcntl | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sockfd = sock.fileno() | |
#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */ | |
SIOCGIFADDR = 0xc0206921 |