Skip to content

Instantly share code, notes, and snippets.

@yrps
yrps / linkedList.c
Created January 3, 2016 02:39
linked list implementation in vanilla C (2014)
#include <stdio.h>
#include <stdlib.h>
// define a struct for a single node: two data fields and a next pointer
struct listNode {
int number;
char *name;
struct listNode *next;
};
@yrps
yrps / stats.c
Created January 3, 2016 02:37
simple statistics package in vanilla C (2014)
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h> // basename
#include <math.h> // sqrt
double get_sum(const double vals[], const size_t n);
double get_mean(const double sum, const size_t n);
double get_median(const double sorted[], const size_t n);
double get_mode(const double sorted[], const size_t n, int* has_mode);
double get_variance(const double vals[], const size_t n, const double mean);
@yrps
yrps / ContainerDemo.java
Created January 3, 2016 02:10
anonymous Components in Swing can be recovered with getComponents (2014)
import javax.swing.*;
import java.awt.*;
/**
* Class to demonstrate creation and manipulation of a Container's anonymous Components.
* We can use methods like getComponent, getComponents, getComponentCount and getContentPane to
* extract components that have been added to a container.
*/
public class ContainerDemo extends JApplet {
/**
@yrps
yrps / Arrays.rb
Created January 3, 2016 02:06
exploring the Enumerable API in Ruby (2014)
# Experiments with the Array library, including the Enumerable mixins
################################################################################
# initialization
# Array.[] denotes array literally, or can be used as factory method
[-2, 'a string', __FILE__] # => [-2, "a string", "(irb)"]
Array.[](-2, 'a string', __FILE__) # => [-2, "a string", "(irb)"]
# empty
@yrps
yrps / listTest.py
Created January 3, 2016 01:30
poking lists in Python (2014)
__author__ = 'ncoop'
class Thing:
def __init__(self, val):
self.val = val
def __str__(self):
return "~%d" % self.val
@yrps
yrps / diag.php
Created January 3, 2016 01:27
some simple $_SERVER diagnostics
<?php
function dumpSERVER() {
$ary = $_SERVER;
echo "<hr>\n<h3>\$_SERVER: ".count($ary)."-entry array</h3>";
echo "<dl>\n";
foreach (array_keys($ary) as $key) {
echo "<dt>$key</dt>";
echo "<dd>$ary[$key]</dd>";
}
@yrps
yrps / TOCmaker.html
Created January 3, 2016 01:24
generate a table of contents index from a collection of scraped html pages
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>TOC maker</title>
<style type="text/css">
body {
font-family: sans-serif;
background-color: lightgreen;
@yrps
yrps / MPAE_04_17.m
Created January 3, 2016 01:20
"MATLAB Programming with Applications for Engineers" exercises from 2014
%{
"MATLAB Programming with Applications for Engineers", Stephen Chapman, 2013
Chapter 4: Branching Statements and Program Design; Exercise 17
Purpose:
- For a ray or light passing between two regions, calculate the angle of
incidence into the second region given the indices of refraction.
- Properly handle cases where no light is refracted into the second region.
- Plot the incident ray, the boundary, and the refracted ray.
@yrps
yrps / clean_ru.py
Created December 31, 2015 05:34
remove non-existent files from user's recently-used.xbel (XFCE4)
#!/usr/bin/env python3
def parseArgs():
from sys import stderr
import argparse
from os.path import expanduser, isfile
parser = argparse.ArgumentParser()
parser.add_argument(
'-f', '--file', help='file to be cleaned',
@yrps
yrps / matrix-convert.rb
Last active December 4, 2015 22:54
extend Ruby's standard Matrix module to facilitate Rational matrices
require 'matrix'
class Matrix
# Attempt to recast each entry of the matrix to clazz
def to(clazz)
self.each_with_index do |entry, i, j|
self[i, j] = send(clazz.name.to_sym, entry)
end
end
end