Skip to content

Instantly share code, notes, and snippets.

View astagi's full-sized avatar
💫

Andrea Stagi astagi

💫
View GitHub Profile
@astagi
astagi / centerresize
Created December 23, 2013 17:16
Resize images 200x200 centered
im.resize({
srcPath: src ,
dstPath: dst,
width: 200,
height: "200^",
customArgs: [
"-gravity", "center",
"-extent", "200x200"
]
}, function(err, stdout, stderr) {
@astagi
astagi / README.md
Last active January 7, 2016 09:42
Programming Sphero BB-8

Programming Sphero BB-8

Install dependencies

$ sudo npm install cylon cylon-ble -g
$ npm install sphero noble

Get your BB-8 UUID

$ cylon-ble-scan

@astagi
astagi / rot.py
Created September 13, 2012 20:49
Encode and decode letters and numbers using ROT13 and ROT5
#!/usr/bin/env python
# ROT: encode and decode letters and numbers using ROT13 and ROT5
# Author: Andrea Stagi <stagi.andrea@gmail.com>
# License: c'mon default header, don't be silly :D
def rot_encode(clr_str):
rot_chars = []
@astagi
astagi / _newmath.c
Last active September 14, 2018 21:58
#define Py_LIMITED_API
#include <Python.h>
#include "libnewmath.h"
PyObject *sum_wrapper(PyObject *obj, PyObject *args) {
const long a, b;
if (!PyArg_ParseTuple(args, "LL", &a, &b))
return NULL;
@astagi
astagi / newmath.go
Last active September 14, 2018 21:58
package main
import "C"
//export sum
func sum(a, b int) int {
return (a + b)
}
#include <Python.h>
// ...
int is_a_long(PyObject * p) {
return PyLong_Check(p);
}
#define Py_LIMITED_API
#include <Python.h>
int PyArg_ParseTuple_LL(
PyObject * args,
long long * a,
long long * b
) {
return PyArg_ParseTuple(args, "LL", a, b);
}
@astagi
astagi / newmath.go
Last active September 14, 2018 21:59
package main
// #cgo pkg-config: python3
// #include <Python.h>
// int PyArg_ParseTuple_LL(PyObject *, long long *, long long *);
import "C"
import (
"fmt"
)
@astagi
astagi / trysum.py
Last active September 14, 2018 21:59
from newmath import sum
print (sum(5,4))
@astagi
astagi / newmath.c
Last active September 17, 2018 09:07
Extending Python with Go - Part 1
#include <Python.h>
static PyObject *sum(PyObject *self, PyObject *args) {
const long a, b;
if (!PyArg_ParseTuple(args, "LL", &a, &b))
return NULL;
return PyLong_FromLong(a + b);
}
static PyMethodDef MathMethods[] = {