Skip to content

Instantly share code, notes, and snippets.

@smcl
smcl / test_compose.py
Last active August 5, 2025 20:09
doodling a bit with piping/composition/partials in Python
from functools import reduce, partial
"""
After PHP announced the pipe operator[0] I got wondering what it might look
like in Python. I actually fucked up and started implementing something
different - the >> operator rather than the |> one. Oops.
Anyway it turns out that it is pretty easy to do simple composition with
partial functions. It's quite a crummy approximation of proper functional
programming like in ML or Haskell. There isn't a nice |> operator nor any
@smcl
smcl / donut.cs
Created October 3, 2012 18:47
Donut.c in c# (sorry)
using System;namespace
donut.net{class Program{static
void Main(string[] args){double A=0
,B=0,i,j;var z=new double[7040];var b=
new char[1760];while(true){memset(b,' ',1760);
memset(z,0.0f, 7040);for(j=0;6.28>j;j+=0.07)for(
i=0;6.28>i;i+=0.02){double c = Math.Sin(i);double d
=Math.Cos(j);double e=Math.Sin(A);double f=Math.Sin(j);
double g=Math.Cos(A); double h=d+2;double D=1
/(c*h*e+f*g+5);double l=Math.Cos(i);double m=
@smcl
smcl / gpsspeedo.py
Created July 10, 2013 20:45
GPS Speedometer for Python/SL4A
import android
import math
import time
droid = android.Android()
droid.startLocating(5000, 30)
interval = 10
# earth radius = 6371km
rad = 6371
@smcl
smcl / WC2022-predictions.md
Last active November 12, 2022 12:38
WC2022 group stage predictions

Group A

  • Qatar to be punished horribly, new record negative goal-difference
  • NL win, Senegal runners up

Group B:

  • Wales to fall to US + Iran but sneak a draw against England
  • England win group, US runners up

Group C:

  • Saudi to struggle. Lewandowski to continue WC goal drought.
#include <EEPROM.h>
#define BUFFER_LEN 256
char sram_buffer[BUFFER_LEN];
// benchmark sram
void benchmark_sram() {
for (int i = 0; i < BUFFER_LEN; i++) {
var m=600,w=[m,[0,-m,0],9,9,0,m,2,1,[0,0,3],9,0,0,m,3,1,[-2,1,4],0,9,0,9,4,1,[2,1,4],0,0,9,m,5],A=2,B=[8,[2,2,0]],D=Math,E=D.sqrt,F=D.max,G=0,H=document.getElementById("c"),I=H.getContext("2d"),J=I.getImageData(0,0,m,m),K=J.data;H.width=H.height=m;function O(p,g){return p[0]*g[0]+p[1]*g[1]+p[2]*g[2]}function P(p,g,z){return[p[0]-g[0]*z,p[1]-g[1]*z,p[2]-g[2]*z]}function Q(p,g,z,C){t=m;for(v=q=0;r=w[q++];q+=6)if(j=P(p,w[q],1),a=2*O(g,g),b=-2*O(j,g),d=E(b*b-2*a*(O(j,j)-r*r)))for(e=2;e--;d=-d)f=(b-d)/a,z<f&&f<C&&f<t&&(v=q,t=f);return v}function R(p,g,z,C){if(!(s=Q(p,g,z,m)))return 0;N=P(X=P(p,g,-t),w[s],1);n=O(N,N);i=A;for(l=0;u=B[l++];)k=O(N,L=P(B[l++],X,1)),i+=u*!Q(X,L,1/m,1)*(F(0,k/E(O(L,L)*n))+F(0,D.pow(O(M=P(L,N,2*k/n),g)/E(O(M,M)*O(g,g)),w[s+4])));p=w[s+c]*i*2.8;z=w[s+5]/9;return C--?R(X,P(g,N,2*O(N,g)/n),1/m,C)*z+p*(1-z):p}for(y=h=m/2;y-- >-h;)for(x=-h;x++<h;){for(c=0;4>++c;)K[G++]=R([0,1,0],[x/m,y/m,1],1,2);K[G++]=255}I.putImageData(J,0,0);
#!/usr/bin/python
from cStringIO import StringIO
import time, commands, os
from sys import argv
def method1():
out_str = ''
for num in xrange(loop_count):
out_str += `num`
@smcl
smcl / gist:ebce87271f9d6fb9b74735a2e11ff050
Last active March 10, 2020 17:57
Transcript of Biden's gun debate with an Trump supporter about gun control
From https://twitter.com/AynRandPaulRyan/status/1237420335802093570?fbclid=IwAR0Xaf0outETgQo9ub82o7YhvafbMDMzf028LEOXEawkzFq3U4vbOwkpdV4
Biden: You're full of shit. Now there is ... shush! I support the second amendment. The second amendment is like right now if you yell "Fire!" that's not free speech. From the very beginning I had a shotgun, I have a 20 gauge, a 12 gauge, my sons hunt, guess what ... you're not allowed to own any weapons. I'm not taking your gun away. At all. You need a hundred rounds you ...
Guy: You really did though, when you said you'd take our guns away
Biden: I did not say that. That's not t... I did not say that
Guy: It was a viral video!
@smcl
smcl / Bernie vs Pete
Last active February 26, 2020 15:24
Transcript of Pete trying to talk over Bernie
From https://twitter.com/nowthisnews/status/1232557081082957825
Bernie:
Let us be clear. Do we think heathcare for all, Pete, is some kind of radical, communist idea? Do we think raising the minimum wage to a living wage [is]? Do we think building the millions of units of affordable housing that we need [is]? Do we think raising taxes on billionaires is a radical idea? Do we think criminal justice reform is a radical idea? Do we think immigration reform ... the truth is, Pete, that the American people support my agenda. That is why I am beating Trump in virtually every poll that is done. And that is why I will defeat him
Pete:
I'm glad you brought this up. Let's talk about this. I'm happy to respond to the question because this is really important. This is really important. If you're gonna ask that rhetorical question, let's go behind the [inaudible] for example. Let's talk about this. Let's talk about what's radical about that plan. Senator, please. Senator. The things you just named are things we favour
int boxSize = 50;
boolean bitmap[][] = new boolean[3][8];
void setup() {
size(150, 400);
background(225, 219, 203);
// horizontal lines
for (int i=1; i<3; i++) {
line(i * boxSize, 0, i * boxSize, height);