Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
for key in "$@"
do
key="$1"
flipSubs=false
tenbit=false
case $key in
@sanmadjack
sanmadjack / fit_within.dart
Created July 19, 2017 19:39
Dart function to fit a rectangle represented by a point
/// Calculates the size of a rectangle that fits within the confines of another
/// rectangle the size of the dimensions described by [outer] with the same
/// aspect ratio as the rectangle described by [inner].
Point fitWithin(Point inner, Point outer) {
final double outerRatio = outer.x/outer.y;
final double innerRatio = inner.x/ inner.y;
if(outerRatio<innerRatio) {
final num x = outer.x;
final num y = inner.y * (outer.x/inner.x);
@sanmadjack
sanmadjack / filechooserdialogexample.cs
Created September 4, 2014 14:45
FileChooserDialog GTK# C# Example
FileChooserDialog fcd = new FileChooserDialog ("Choose files",this, FileChooserAction.Open,
"Select", ResponseType.Ok, "Cancel", ResponseType.Close);
fcd.SelectMultiple = true;
fcd.Run (); // This opens the window and waits for the response
fcd.Destroy (); // The dialog does not automatically close when clicking the buttons, so you have to manually close it with this
@sanmadjack
sanmadjack / ResizeListViewHeight.cs
Created August 11, 2014 15:04
Android C# function to resize ListView height to match contents
private void ResizeListViewHeight(ListView lv) {
IListAdapter la = lv.Adapter;
if (la == null) {
return;
}
int totalHeight = 0;
DisplayMetrics dm = new DisplayMetrics();
@sanmadjack
sanmadjack / Google.gpl
Created February 6, 2014 16:12
A GIMP and Inkscape Color Pallet for Google Colors
GIMP Palette
Name: Google Colors
Columns: 3
# Created by Matthew Barbour
# Based on Google colour guidelines from http://www.behance.net/gallery/Google-Visual-Assets-Guidelines-Part-1/9028077
66 133 244 Blue 1
118 167 250 Blue 2
160 195 255 Blue 3
219 68 55 Red 1
229 115 104 Red 2
@sanmadjack
sanmadjack / toDni.js
Last active August 29, 2015 13:56
A JavaScript function that takes a decimal-format number and outputs the D'Ni (base-25) equivalent digits. Returns an array containing integer representations of each D'Ni digit.
function convertToDni(number) {
var new_number = new Array();
// If the number is just 0, then we just save some time and output a zero
if(number==0) {
new_number.unshift(0);
return new_number;
}
// D'Ni is base-25, so we divide by 25 over and over again, depositing the remainders into the new number,
// until the number is finally less than 25 (meaning dividing it by 25 floors to 0
while(number>0) {
@sanmadjack
sanmadjack / sysinfo.motd.pl
Last active April 7, 2022 21:02
A MOTD script for displaying system information.
#!/usr/bin/perl
use Data::Dumper;
sub GetIpAddresses{
my $output = qx(ifconfig);
my $hash = {};
my $interface;
foreach my $line (split /[\r\n]+/, $output) {
if($line =~ m/^([^ ]+)/) {
@sanmadjack
sanmadjack / crossword.html
Created September 26, 2013 21:23
A crossword puzzle solving assistant
<html>
<head>
<script>
function process() {
var element = document.getElementById("input");
var input = element.value;
var data = new Array();
@sanmadjack
sanmadjack / zfs.php
Created September 23, 2013 21:17
PHP ZFS Info Display
<html>
<head>
<script type="text/javascript">
var filesystems=<?php
$filesystems = array();
$header_regex = "|^([A-Za-z0-9/]+)\s+([a-z]+)\s+([^\s]+)\s+([a-z-]+)$|";
$output = array();
@sanmadjack
sanmadjack / PrintDataSetToHTML.vb
Created May 2, 2013 16:16
A function to create a string containing the html table representation of a DataSet
Private Function PrintDataSetToHTML(ByRef ds As DataSet) As String
Dim output As New StringBuilder
For Each dt As DataTable In ds.Tables
output.AppendLine("<table>")
output.Append("<caption>")
output.Append(dt.TableName)
output.AppendLine("</caption>")
output.AppendLine("<tr>")
For Each dc As DataColumn In dt.Columns
output.Append("<th>")