{{ message }}

Instantly share code, notes, and snippets.

# m1el

Last active Mar 28, 2021
sdutils
View sdist.plt
 set term svg set output 'sdist_under.svg' set xrange [-4:4] set yrange [0:0.45] set samples 1000 plot \ x < 1 ? exp(-x*x/2)/sqrt(6.283185307179586) : 1/0 with filledcurves x1 lc rgb "grey", \ exp(-x*x/2)/sqrt(6.283185307179586) lw 2 lc rgb "black" set output 'sdist_inside.svg'
Last active Feb 4, 2021
View solve_mastermind.py
 from collections import defaultdict from itertools import permutations from pprint import pprint # this is going to calculate the output of the game # the number of colors guessed correctly and the number of # colors placed correctly def calculate_score(correct, guess): correct_colors = sum(1 for color in guess if color in correct) correct_place = sum(1 for (a, b) in zip(correct, guess) if a == b) return (correct_colors - correct_place, correct_place)
Created Jan 23, 2021
View pratt_25519_certificate.py
 # http://www.russinoff.com/papers/pratt.pdf import math number = 2**255 - 19 certificate = [2, [2, 3, 65147, 74058212732561358302231226437062788676166966415465897661863160754340907], [2, 1, 1, 1], [[], [], [], [2,
Last active Jan 7, 2021
View GeneratePagination.cs
 IEnumerable GeneratePagination(int currentPage, int pageCount) { var itemsAroundCurrent = 1; var itemsAtEnds = 1; var minimumSkip = 2; var pagesOnScreen = (itemsAtEnds + minimumSkip + itemsAroundCurrent - 1) * 2 + 1; if (pageCount <= pagesOnScreen) { return Enumerable.Range(1, pagesOnScreen); } var skipEdge = itemsAtEnds + minimumSkip;
Last active Dec 18, 2020
View base256.js
 // http://hewo.xedoloh.com/2015/04/base-256/ const BASE_START = "bghjklnpqrstvwyz"; const BASE_MID = "aeio"; const BASE_END = "cdfm"; const b256_encode = (source) => { let buffer = ''; for (let byte of source) { buffer += BASE_START[(byte >> 4)]; buffer += BASE_MID[((byte >> 2) & 0b11)];
Last active Aug 11, 2020
View swap_ranges.rs
 fn swap_ranges_copy(vec: &mut [u8], offset1: usize, offset2: usize, len: usize) { let tmp = vec.to_vec(); vec[offset1..offset1+len].copy_from_slice(&tmp[offset2..offset2+len]); vec[offset2..offset2+len].copy_from_slice(&tmp[offset1..offset1+len]); } fn swap_ranges(vec: &mut [u8], mut offset1: usize, mut offset2: usize, mut len: usize) { if offset1 < offset2 && offset1 + len >= offset2 { // The ranges have the following layout here: // [o1--------]
Last active Jun 19, 2020
View lambdas.py
 ZERO = (lambda hf: (lambda ax: ax)) TWENTY_SIX = lambda vf: lambda vx: \ vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vf(vx)))))))))))))))))))))))))) INCREMENT = (lambda jnum: lambda jf: lambda jx: jf(jnum(jf)(jx))) Z_COMBINATOR = (lambda gf: ((lambda gx: gf(lambda gy: gx(gx)(gy))) (lambda gx: gf(lambda gy: gx(gx)(gy))))) TRUE = (lambda bx: lambda by: bx)
Created May 4, 2020
View field_offset.rs
 macro_rules! field_offset { ($ty:path,$field:ident$(.$cfield:ident)*) => { unsafe { union Transmuter { p: *const T, r: &'static T, i: usize, } let base = Transmuter::<\$ty> { p: core::ptr::NonNull::dangling().as_ptr(),
Last active Apr 26, 2020
View makefile
 all: rustc -O -Clto=fat -Cpanic=abort --crate-type=staticlib --emit=obj shellcode.rs -o shellcode.obj cl.exe /Zi /nologo test.c shellcode.obj test.exe
Last active Apr 22, 2020
View circle_from_tangent_points.rs
 /// Construct a circle from three tangent points. /// /// Returns None if there is no unique solution. This happens when /// the triangle formed by three points has zero area. /// /// The algorithm goes as follows: /// Construct two segment bisectors, defined parametrically: /// /// Bisector for segment ab: /// mid_ab + t * norm_ab = p, where t \in Real