Skip to content

Instantly share code, notes, and snippets.

View glesica's full-sized avatar

George Lesica glesica

View GitHub Profile
convolution <- function(A, B) {
# Computes the convolution of two vectors.
#
# Args:
# A, B: column vectors representing polynomial coefficients.
#
# Returns:
# The coefficient vector resulting from multiplying the polynomial
# represented by A by the polynomial represented by B.
Ap <- c(A, B*0)
@glesica
glesica / update-hosts.sh
Last active January 18, 2024 17:37
A quick shell script that will automatically update a Linux HOSTS file to block ads and malicious domains.
#!/usr/bin/env sh
# Filename: update-hosts.sh
# Author: George Lesica <george@lesica.com>
# Description: Replaces the HOSTS file with a customized version that blocks
# domains that serve ads and malicious software, creating a backup of the old
# file.
HOSTS_URL="http://someonewhocares.org/hosts/zero/hosts"
NEW_HOSTS="hosts"
@glesica
glesica / example1.py
Created April 20, 2013 18:08
Simple drawing example using Pycairo.
from math import pi
from cairo import SVGSurface, Context, Matrix
WIDTH = 6 * 72
HEIGHT = 4 * 72
s = SVGSurface('example1.svg', WIDTH, HEIGHT)
c = Context(s)
# Transform to normal cartesian coordinate system
@glesica
glesica / benchmark.py
Created April 15, 2020 17:14
A naive count-min sketch implementation in Python.
import sys
import time
from cmsketch import CMSketch
RECEIVED = 1000000
EVENTS = 1000
if len(sys.argv) != 3:
print("usage: benchmark.py <error> <prob>")
@glesica
glesica / swgo.bash
Created March 27, 2018 02:16
Switch Go (swgo): A very simple and intensely opinionated Go version manager
# Switch Go (swgo)
# A very simple and intensely opinionated Go version manager.
#
# Author: George Lesica <george@lesica.com>
#
# To use, create a file called ".swgo" in any project directory.
# Inside of this file, set two variables: GOROOT_ and GOPATH_
# to the values you want assigned to GOROOT and GOPATH,
# respectively. Then, while in that directory, just run "swgo"
# and your GOROOT, GOPATH, and PATH will be updated accordingly.
@glesica
glesica / bootstrap-sile.sh
Last active March 21, 2017 23:39
Install dependencies for SILE on Ubuntu 16.04
#!/bin/sh
sudo apt-get install libharfbuzz-dev libfreetype6-dev libfontconfig-dev lua5.1 lua-lpeg-dev lua-expat-dev lua-zlib-dev lua-filesystem-dev liblua5.1-0-dev

Keybase proof

I hereby claim:

  • I am glesica on github.
  • I am glesica (https://keybase.io/glesica) on keybase.
  • I have a public key whose fingerprint is 4378 8FCD 8E05 A920 2EA7 71DE E23B F398 FEBF A545

To claim this, I am signing this object:

"""
Contouring using the Marching Squares algorithm.
George Lesica
"""
from cairo import SVGSurface, Context
WIDTH = 8 * 72.0
HEIGHT = 8 * 72.0
@glesica
glesica / contour.jl
Created September 17, 2013 02:15
Contouring algorithm in Julia.
# contour(A, v)
# Implements the Marching Squares contouring algorithm (see:
# https://en.wikipedia.org/wiki/Marching_squares for details). The
# matrix `A` is an m x n scalar field and the scalar `v` is the
# value to be contoured. The return value is an (m-1) x (n-1) matrix
# of contour line type indices (see the Wikipedia article).
# TODO: Implement in parallel
function contour(A, v)
rows, cols = size(A)
@glesica
glesica / sentiment.r
Created February 24, 2013 23:30
A really simple sentiment analysis function implemented in R that illustrates some of the nifty features of the R language.
sentiment <- function(str, words, weights=NULL) {
if (is.null(weights)) {
weights <- rep(1, length(words))
}
if (length(words) != length(weights)) {
stop('Length of words and weights not equal')
}
str.wts <- rep(0, length(str))