Skip to content

Instantly share code, notes, and snippets.

View etale-cohomology's full-sized avatar

Diego etale-cohomology

View GitHub Profile
import pymc3, numpy, sys, seaborn, re
def get_dist(fn):
y = [0, 0, 0, 0, 0]
for line in open(fn):
try:
num = re.split('\D', line)[0]
y[int(num) - 1] += 1
except:
print fn, 'can not parse:', line
@dabeaz
dabeaz / aecho.py
Last active October 17, 2023 03:26
Live-coded examples from my PyCon Brasil 2015 Keynote
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
@technosaurus
technosaurus / xcbiv.c
Created November 7, 2015 04:19
simple xcb image viewer using nanosvg and stb-image
#include <xcb/xcb.h>
#include <xcb/xcb_image.h>
#define STBI_NO_HDR
#define STBI_NO_LINEAR
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define NANOSVG_IMPLEMENTATION
#include "nanosvg.h"
#define NANOSVGRAST_IMPLEMENTATION
#include "nanosvgrast.h"
@karpathy
karpathy / min-char-rnn.py
Last active May 4, 2025 03:00
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@barosl
barosl / add.c
Created July 26, 2015 07:26
Function overloading in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int addi(int a, int b) {
return a + b;
}
char *adds(char *a, char *b) {
char *res = malloc(strlen(a) + strlen(b) + 1);
module type CELL = sig
type 'a cell
type 'a exp
val return : 'a -> 'a exp
val (>>=) : 'a exp -> ('a -> 'b exp) -> 'b exp
val cell : 'a exp -> 'a cell exp
val get : 'a cell -> 'a exp
@kylemcdonald
kylemcdonald / smootheststep.txt
Last active December 19, 2019 23:22
Derivation of 7th-order smoothstep function with zeros in third derivative.
7th-order spline and first three derivatives
f(t) = a_7 t^7+a_6 t^6+a_5 t^5+a_4 t^4+a_3 t^3+a_2 t^2+a_1 t+a_0
f'(t) = 7 a_7 t^6+6 a_6 t^5+5 a_5 t^4+4 a_4 t^3+3 a_3 t^2+2 a_2 t+a_1
f''(t) = 42 a_7 t^5+30 a_6 t^4+20 a_5 t^3+12 a_4 t^2+6 a_3 t+2 a_2
f'''(t) = 210 a_7 t^4+120 a_6 t^3+60 a_5 t^2+24 a_4 t+6 a_3
Constraints
f(0) = 0 = a_0
f(1) = 1 = a_7 + a_6 + a_5 + a_4 + a_3 + a_2 + a_1 + a_0
f'(0) = 0 = a_1
@rossant
rossant / heatmap.py
Created November 25, 2014 22:37
Vispy heatmap
import numpy as np
from vispy import app, gloo
vertex = """
uniform vec4 viewport;
attribute vec2 position;
attribute vec2 texcoord;
varying vec2 v_texcoord;
varying vec2 v_pixcoord;
@sogko
sogko / app.js
Last active February 21, 2025 08:34
gulp + expressjs + nodemon + browser-sync
'use strict';
// simple express server
var express = require('express');
var app = express();
var router = express.Router();
app.use(express.static('public'));
app.get('/', function(req, res) {
res.sendfile('./public/index.html');
@patriciogonzalezvivo
patriciogonzalezvivo / GLSL-Math.md
Last active January 17, 2025 00:51
GLSL Math functions

Trigonometry

const float PI = 3.1415926535897932384626433832795;
const float PI_2 = 1.57079632679489661923;
const float PI_4 = 0.785398163397448309616;

float PHI = (1.0+sqrtf(5.0))/2.0;