Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash -e
# Make a balanced file tree with files full of random bytes for testing purposes.
# Script takes three parameters depth, width, and filesize.
DEPTH=2
WIDTH=10
FSIZE=10000
DORANDOM=1
#WRITEPROBABILITY=5
function rec_make_tree() {
#!/bin/bash
fail() {
echo "$@"
exit 1
}
[[ -z "$1" ]] && fail "Usage: $0 <path to file to check>"
FILE=`readlink -f "$1"`
[[ -f "$FILE" ]] || fail "File must exist. $FILE does not."
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <QDebug>
#include <QAudioDeviceInfo>
#include <qendian.h>
#include "audiolevelmeter.h"
AudioLevelMeter::AudioLevelMeter(QObject *parent)
: QObject(parent)
@sgpinkus
sgpinkus / index.html
Last active March 11, 2017 06:12
utility-function-editor-mock
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Spline Curve Editor</title>
<style>
* { border: 0; padding: 0; margin: 0; }
html, body { height: 100%; }
body {
font: 13px sans-serif;
/**
* Presents a bar graph with mutatable bars. The use can click on one bar and drag to change its
* height and corresponding value. The user can click and drag to select >1 and simultaneously
* change thier values.
*/
class EditableBarChart
{
/**
* Init. We need to explicitly deal with margins ~because axes.
*/
''' Override certain function from built-in json module to allow formatting of JSON two container types
, arrays and objects, to be optionally specified separately by allowing `indent` to be a 2-tuple.
I copied this from Python 3.5.3 but looks about the same in 3.4-3.6. Probably wont work in >=3.7.
'''
def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
_key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot,
## HACK: hand-optimized bytecode; turn globals into locals
ValueError=ValueError,
dict=dict,
@sgpinkus
sgpinkus / mongoose-map.js
Created February 18, 2020 03:29
mongoose-map.js
var mongoose = require('mongoose');
var getTestConnection = require('./getTestConnection.js');
var UserSchema = new mongoose.Schema({
name: { type: String, required: true },
notes: {
type: Map,
of: String,
default: {},
}
import Foundation
enum Gender : String, Codable {
case M, F
}
struct User : Codable {
let name: String
let email: String
let gender: Gender
let verified: Bool
# git clone git@github.com:sgpinkus/mime-db.git && cd mime-db && git checkout origin/add-mime-support
const db = require('./db');
const fs = require('fs');
const lodash = require('lodash');
let mimeSupport = lodash.pickBy(db, x => x.source === 'mime-support');
mimeSupport = Object.entries(mimeSupport).map(([k, v]) => { return { mime: k, ...v }; });
fs.writeFileSync('mime-support-additional.json', JSON.stringify(mimeSupport, null, 2));
@sgpinkus
sgpinkus / both-dirs-try.html
Last active August 14, 2020 12:11
Example of how "infinite scroll" works out of the box.
<!DOCTYPE html>
<html>
<head>
<title>Simplified Infinite Scroll</title>
<meta charset="utf-8" />
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<style type='text/css'>
* { border: 0; padding: 0; margin: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { display: flex; flex-flow: column wrap; }