Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / m3u8_to_m3u.sh
Created January 23, 2016 00:43
m3u8 to m3u
#!/bin/sh
# convert all m3u8 playlists (UTF-8 encoding) in current dir to m3u (ASCII)
# required for compatibility with some media players
for pl in *.m3u8
do iconv -f UTF-8 -t ASCII//TRANSLIT "$pl" > "${pl%\.m3u8}.m3u"
echo "converted $pl"
done
@yrps
yrps / favicon.sh
Last active February 15, 2016 18:28
use ImageMagick to convert the given image to a favicon
#!/bin/sh
# use ImageMagick to convert the given image to a favicon
# http://www.imagemagick.org/Usage/thumbnails/#favicon
usage() {
>&2 echo "usage: $(basename "$0") input [output]"
}
set -eu
input="${1:-}"
output="${2:=favicon}"