Skip to content

Instantly share code, notes, and snippets.

View glesica's full-sized avatar

George Lesica glesica

View GitHub Profile
perceptron <- function(x, y, w, a, verbose=F) {
# Uses the Perceptron algorithm to find a weight vector that
# satisfies the given data.
#
# Args:
# x: an m by n matrix representing the data under study
# y: objective vector of m elements
# w: initial guess for the weight vector, n elements
# a: learning rate, should be in (0,1]
# verbose: echo information w at each iteration (default: False)
@glesica
glesica / particle.r
Created November 26, 2012 17:52
Particle filter assignment.
# particle.r
# George Lesica
# CSCI 555 - FA 2012
# Homework 7.5
# Solution to problem 2
samp <- function(S) {
return(sample(S$X, length(S$X), replace=T, prob=S$W))
}
# value_iteration.r
# George Lesica
# CSCI 555 - FA 2012
# Homework 5
# Solution to problem 3
INTENDED <- 0.8
LEFT <- 0.1
RIGHT <- 0.1
[xcb] Unknown sequence number while appending request
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
invader: ../../src/xcb_io.c:160: append_pending_request: Assertion `!xcb_xlib_unknown_seq_number' failed.
Program received signal SIGABRT, Aborted.
0x00007ffff75ab445 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0 0x00007ffff75ab445 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
@glesica
glesica / petersburg.r
Created August 26, 2012 03:37
R functions to simulate the Petersburg Paradox.
pburg <- function() {
p <- 1
while (sample(1:2, 1)[1] == 1) {
p <- p * 2
}
return(p)
}
ipburg <- function(n) {
r <- sapply(1:n, function(x) { return(pburg()) })
# In views.py
import flask
from flask import request, session, g
from datably import app, crypt, db
from datably import operations as ops
@app.route('/login', methods=('GET', 'POST'))
def login():
context = {}
>>> a = re.compile(r'^[0-9_]+|\W|[_]+$')
>>> a.findall('__hello world')
['__', ' ']
>>> a.sub('', '__username@gmail.com_table name hello')
'usernamegmailcom_tablenamehello'
>>> a.sub('', 'a')
'a'
>>> a.sub('', '_')
''
>>> a.sub('', '0')
@glesica
glesica / subsequence.py
Created April 28, 2012 01:54
Function to find a subsequence with the largest sum from a list.
"""
Function to find the contiguous subsequence in a
list that has the greatest sum.
"""
def max_subsequence(L):
"""
Implements a linear time algorithm.
>>> max_subsequence([1,2,3,4,5])
/*
shotgun.c
Author: George Lesica <glesica@gmail.com>
Description: An ANSI C implementation of the shotgun sorting algorithm.
*/
#include <stdlib.h>
/* Private utility functions. */
@glesica
glesica / install.sh
Created April 4, 2012 21:10
A script for linking dot files into a home directory.
#!/bin/bash
# install.sh
# Author: George Lesica <glesica@gmail.com>
# Description: Deploy script for my dotfiles repo.
# License: Public Domain (where it exists), any OSI-approved
# license elsewhere.
#
# Configuration