Skip to content

Instantly share code, notes, and snippets.

Avatar
:bowtie:
workin' on some stuff

Francesc Campoy campoy

:bowtie:
workin' on some stuff
View GitHub Profile
View udf.js
function checkAssembly(row, emit) {
emit({ b: WebAssembly != undefined });
}
bigquery.defineFunction(
'checkAssembly',
['x'],
[{ 'name': 'b', 'type': 'boolean' }],
checkAssembly
);
View main.js
const fs = require('fs');
const memory = new WebAssembly.Memory({ initial: 256, maximum: 256 });
const env = {
'abortStackOverflow': _ => { throw new Error('overflow'); },
'table': new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }),
'tableBase': 0,
'memory': memory,
'memoryBase': 1024,
'STACKTOP': 0,
'STACK_MAX': memory.buffer.byteLength,
View dynamic.c
#include <stdio.h>
#include <dlfcn.h>
int main()
{
int (*sum)(int, int);
void *dl = dlopen("sum.so", RTLD_LAZY);
if (!dl)
{
fprintf(stderr, "%s\n", dlerror());
return 1;
View main.c
#include <stdio.h>
extern int sum(int a, int b);
int main() {
printf("%d\n", sum(39, 3));
return 0;
}
View sum.c
int sum(int a, int b)
{
return a + b;
}
View udf.js
function intdiv(row, emit) {
emit({ d: row.x / row.y, m: row.x % row.y });
}
bigquery.defineFunction(
'intdiv',
['x', 'y'],
[{ 'name': 'd', 'type': 'integer' },
{ 'name': 'm', 'type': 'integer' }],
intdiv
);
View udf.js
function identity(row, emit) {
emit({ y: row.x });
}
bigquery.defineFunction(
'identity',
['x'],
[{ 'name': 'y', 'type': 'float' }],
identity
);
View main.go
modelBytes, _ := assets.Asset("model.pb")
graph := tf.NewGraph()
graph.Import(modelBytes, "")
input := graph.Operation("input").Output(0)
output := graph.Operation("output").Output(0)
sess, _ := tf.NewSession(graph, &tf.SessionOptions{})
feed, _ := tf.NewTensor([][]float32{})
result, _ := sess.Run(
map[tf.Output]*tf.Tensor{input: input1},
[]tf.Output{output}, nil)
@campoy
campoy / Dockerfile
Created Mar 29, 2018
One liner gemini
View Dockerfile
FROM ubuntu:16.04
# install java 8 and other tools
RUN apt-get update && apt-get install -y --no-install-recommends default-jdk curl git && \
rm -rf /var/lib/apt/lists/* && \
# needed to install cassandra
apt-get install -y --no-install-recommends curl && \
echo "deb http://www.apache.org/dist/cassandra/debian 311x main" >> /etc/apt/sources.list.d/cassandra.sources.list && \
curl https://www.apache.org/dist/cassandra/KEYS | apt-key add - && \
apt-key adv --keyserver pool.sks-keyservers.net --recv-key A278B781FE4B2BDA && \
@campoy
campoy / main.go
Created Feb 23, 2018
a more idiomatic solution
View main.go
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"sync"