Skip to content

Instantly share code, notes, and snippets.

@vedantk
vedantk / nqueens.py
Created December 19, 2010 08:31
A solution to N-Queens using the Min-Conflicts local search algorithm
#!/usr/bin/python
# A solution to N-Queens using the Min-Conflicts local search algorithm
# Vedant Kumar <vminch@gmail.com>
import random
def nqueens(nr):
show(min_conflicts(list(range(nr)), nr), nr)
def show(soln, nr):
@vedantk
vedantk / tagged_ptr.rs
Created September 7, 2015 22:58
A safe version of tagged pointers in rust
use std::mem;
use std::ops::{Deref, DerefMut};
#[derive(Copy, Clone, Debug)]
struct Tagged<'a, T: 'a> {
pointer: &'a T
}
impl<'a, T> Tagged<'a, T> {
fn tag(&'a mut self) -> &'a mut Tagged<'a, T> {
from __future__ import print_function
import lldb
def doit(dbg, cmd):
print('::', cmd)
dbg.HandleCommand(cmd)
def should_stop_stepping(process):
state = process.GetState()
@vedantk
vedantk / gist:2d0cc1df9bea9f0fa74ee101d240b82c
Created November 8, 2019 00:19
Steps involved in clang installing the llvm SIGPIPE handler after signal(SIGPIPE, SIG_IGN) in lldb
=== Really doing llvm handler registration ===
0 lldb 0x0000000107b0fe98 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 lldb 0x0000000107b0f858 RegisterHandlers() + 328
2 lldb 0x0000000107b04d3e llvm::EnablePrettyStackTrace() + 46
3 lldb 0x0000000107b04103 llvm::InitLLVM::InitLLVM(int&, char const**&) + 147
4 lldb 0x0000000107aeaa9f main + 47
5 libdyld.dylib 0x00007fff722ba3d5 start + 1
6 libdyld.dylib 0x000000000000000e start + 18446603338600700986
=== (in lldb) Should have installed llvm handlers ^ ===
=== (in lldb) Blocking SIGPIPE ===
@vedantk
vedantk / opt-check-dbg-invar.sh
Created June 21, 2018 19:19
Script to check whether an opt invocation is debug info invariant
#!/bin/bash
OPT=$1
shift 1
TEST_FILE=$1
shift 1
strip_cmd() {
$OPT -disable-verify -strip -strip-dead-prototypes -strip-named-metadata -o - $*
@vedantk
vedantk / bst.erl
Created December 5, 2011 02:54
Binary search trees in Erlang
-module(bst).
-export([bst_create/0, bst_insert/2, bst_search/2]).
bst_create() -> [].
bst_insert(Bst, N) ->
case Bst of
[] -> [N, [], []];
[Root, Lhs, Rhs] ->
if
// Test driver for https://reviews.llvm.org/D41149
#include <cstdint>
#include <limits>
#include <iostream>
#include <vector>
// Instructions:
// - Compile this program with a baseline compiler and a patched compiler.
// - Check that the output of the two executables is the same.
@vedantk
vedantk / taylor.rkt
Created January 26, 2011 04:39
Taylor Polynomials: generate them in Racket
(require plot)
(define (factorial n)
(if (< n 2) 1 (* n (factorial (- n 1)))))
(define (taylor-poly func n c)
(define (calc-coeff dfn level)
(/ (dfn c) (factorial level)))
(define (find-coeff fn level coeffs)
(if (= level (+ n 1))
@vedantk
vedantk / PushupCounter.c
Created April 25, 2013 10:37
A pushup counter using sonar and the arduino uno
#define trigPin 13
#define echoPin 12
#define delayMilis 100
/* 0: Noisy state.
* 1: You went below the low threshold.
* 2: You went above the low threshold.
* 3: You went above the high threshold.
* 4: You went below the high threshold, pushup done.
*/
@vedantk
vedantk / foil_optimizer.cpp
Created March 8, 2016 23:32 — forked from socantre/foil_optimizer.cpp
CppCon 2015: Chandler Carruth "Tuning C++: Benchmarks, and CPUs, and Compilers! Oh My!" functions to disable compiler optimization
static void escape(void *p) {
asm volatile("" : : "g"(p) : "memory");
}
static void clobber() {
asm volatile("" : : : "memory");
}