Skip to content

Instantly share code, notes, and snippets.

George Lesica glesica

View GitHub Profile
@glesica
glesica / example1.py
Created Apr 20, 2013
Simple drawing example using Pycairo.
View example1.py
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 Apr 15, 2020
A naive count-min sketch implementation in Python.
View benchmark.py
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 / update-hosts.sh
Last active Aug 17, 2019
A quick shell script that will automatically update a Linux HOSTS file to block ads and malicious domains.
View update-hosts.sh
#!/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 / swgo.bash
Created Mar 27, 2018
Switch Go (swgo): A very simple and intensely opinionated Go version manager
View swgo.bash
# 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 Mar 21, 2017
Install dependencies for SILE on Ubuntu 16.04
View bootstrap-sile.sh
#!/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
View convolution.r
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)
View keybase.md

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:

View contour.py
"""
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 Sep 17, 2013
Contouring algorithm in Julia.
View contour.jl
# 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 Feb 24, 2013
A really simple sentiment analysis function implemented in R that illustrates some of the nifty features of the R language.
View sentiment.r
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))
You can’t perform that action at this time.