Skip to content

Instantly share code, notes, and snippets.

@ivand58
ivand58 / ihex.vim
Created May 30, 2017 12:59 — forked from charleskeepax/ihex.vim
Vim Script Intel HEX Checksum
function IHexChecksum()
let l:data = getline(".")
let l:dlen = strlen(data)
if (empty(matchstr(l:data, "^:\\(\\x\\x\\)\\{5,}$")))
echoerr("Input is not a valid Intel HEX line!")
return
endif
let l:byte = 0
@ivand58
ivand58 / between.fs
Last active December 28, 2017 18:44
Forth
: between (x a b -- flag )
-rot over
<=
-rot >=
and
;
\ LONG VERSION
: sign_ ( x -- sign(x)
?dup if
0> if 1 else -1 then
else 0 then ;
\ SHORT VERSION
: sig dup if 0> if 1 else -1 then then ;
\ more optimized
: sig dup 0< over 0 > negate + ;
@ivand58
ivand58 / tables.tex
Created January 12, 2018 08:34
Latex table shrinking
%\title{LaTeX Table spacing example}
% Example by John Hammersley
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\begin{document}
\section*{Table with default spacings}
% A table with the default row and column spacings
@ivand58
ivand58 / stack.tex
Last active January 19, 2018 08:33
stack
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\newcounter{shifty} \setcounter{shifty}{0}
\foreach \n/\w in {A/1,B/2,A/1,A/1,B/2}{
\node[yshift=\theshifty cm,draw,minimum height=1cm,minimum width=\w cm,anchor=west,outer sep=0pt]{\n};
\draw[yshift=\theshifty cm,thick] (0,.6cm)--(0,-.6cm);
\addtocounter{shifty}{\w}
}
@ivand58
ivand58 / autocorrelation.py
Created January 30, 2018 13:14
Autocorrelation
import random
x = [random.random() for i in range(128)]
N = 5
#x = range(22)
y = x[-N:] + x[:-N]
y2 = [i + 0.9*random.random() for i in y]
mx, my = sum(x)/len(x), sum(y)/len(y)
my2 = sum(y2)/len(y2)
mx, my, my2 = 0,0,0
@ivand58
ivand58 / progress.py
Last active February 5, 2018 12:03
percentage progress bar
class CProgress:
"""Uses the Bresenham algorithm for line segments in the first octant."""
def __init__(self,title='', mx=100):
self.deltax = mx
self.deltay = 40
self.error, self.progress_y = 0, 0
sys.stdout.write(title + ": [" + "-"*40 + "]" + chr(8)*41)
sys.stdout.flush()
def progress(self):
@ivand58
ivand58 / printf2.fs
Created April 5, 2018 12:01
print fixed point, two digs after dec point
\ print fixed point, two digs after dec point
: f.2 ( df -- )
0,005 d+ \ rounding
0 <# #s 2drop \ whole part
[char] . hold< \ decimal separator
f# f# \ frac part
0 #> \ finish
type space \ print
;
#ifdef __GNUC__
#define INLINE inline __attribute__((always_inline))
#else
#define INLINE
#endif
{
@ivand58
ivand58 / morse.c
Created April 23, 2018 06:21
text to morse and morse to text
#include <stdio.h>
#include <string.h>
char X[] =
" ETIANMSURWDKGOHVF:L:PJBXCYZQ::54:3:::2&:+::::16=/:::(:7:::8:90"
"::::::::::::?_::::\"::.::::@:::'::-::::::::;!:):::::,:::::";
int j,w,h,f,u,d,g,e,n,i,l,a,r,p,c,m,o,t,s,Q=32,T[32],W[32],I=13000;
int main(int v, char** b) {