Skip to content

Instantly share code, notes, and snippets.

View Yoplitein's full-sized avatar
🔈
[screaming]

Steven Dwy Yoplitein

🔈
[screaming]
View GitHub Profile
AttrType[] find_attributes(AttrType, alias Thing)()
{
AttrType[] result;
foreach(attr; __traits(getAttributes, Thing))
static if(is(typeof(attr) == AttrType))
result ~= [attr];
return result;
}
@Yoplitein
Yoplitein / gist:c04237c74101f3395c98
Last active August 29, 2015 14:05
gl3n to gfm conversion functions
import gl3n.util: is_matrix, is_vector;
auto to_gfm(MatrixType)(MatrixType matrix)
if(is_matrix!MatrixType)
{
static import gfm.math;
enum matrixSize = matrix.cols * matrix.rows;
matrix.mt[matrixSize] data;
matrix.mt *ptr = matrix.value_ptr;
@Yoplitein
Yoplitein / gist:bd07e5a59a9bbd5e4d90
Created August 29, 2014 23:08
string prompt function for tkd, similar to javascript's prompt function
string string_prompt(Window parent, string prompt, string initialValue = null)
{
string result;
auto window = new Window(parent, "Prompt");
auto label = new Label(window, prompt);
auto input = new Entry(window);
auto okButton = new Button(window, "OK");
auto cancelButton = new Button(window, "Cancel");
void close(CommandArgs _ = CommandArgs.init)
@Yoplitein
Yoplitein / gist:98eddf7e9f1f74e61b29
Created September 13, 2014 10:43
Simple script to alert you, via email (through cron,) of packages with upgrades on Arch
#!/bin/bash
cacheFile=~/bin/updates.cache
cacheFileNew=~/bin/updates-new.cache
function getignores()
{
#list ignored packages here, like so:
#echo "packagename"
#TODO: actually parse pacman.conf
@Yoplitein
Yoplitein / gist:3b07090caadff0d20f36
Last active August 29, 2015 14:06
D unittesting helper to ensure certain exceptions are thrown
void ensure_throws(ExceptionType = Exception)(void delegate() callable, string message = "")
{
import core.exception: AssertError;
try
{
callable();
assert(false, message);
}
catch(ExceptionType err) {}
@Yoplitein
Yoplitein / gist:8bc30b082d5c45fceb2c
Created October 6, 2014 15:26
Simple noise function in D
//adapted from http://stackoverflow.com/a/7262117
private real noise(long x, long y)
{
long initial = x + y * 57;
initial = (initial << 13) ^ initial;
real intermediate = (
1.0L - (
(
result * (
result ^^ 2 + 15731 + 789221
@Yoplitein
Yoplitein / PKGBUILD.patch
Created April 1, 2015 15:05
AngelScript PKGBUILD Patch
--- PKGBUILD.old 2015-03-31 06:59:59.000000000 -0700
+++ PKGBUILD 2015-04-01 08:00:47.770024293 -0700
@@ -16,10 +16,12 @@
build() {
cd "$srcdir/sdk/$pkgname/projects/gnuc"
- sed -i -e "/^LOCAL/s:=.*:=${pkgdir}/usr:" makefile
+ sed -i -e "/^LOCAL/s:=.*:=${pkgdir}/usr:" Makefile
+ sed -i -e "s/)_s/)/g" Makefile
+ sed -i -e "s/^\t\$(MAKE) install_shared$//g" Makefile
@Yoplitein
Yoplitein / record.sh
Created April 24, 2015 23:28
Simple script to quickly record a screencast. Requires ffmpeg and https://github.com/lolilolicon/xrectsel
#!/bin/bash
if [ -z "$@" ]; then
echo "./record.sh <filename.webm>"
exit 1
fi
SELECTION=`xrectsel`
INRES=`echo $SELECTION | cut -d"+" -f1`
WIDTH=`echo $INRES | cut -d"x" -f1`
@Yoplitein
Yoplitein / list.py
Created August 12, 2015 02:54
Lists symbols in a Mystcraft age data file.
import gzip
import sys
import pynbt
def main():
if len(sys.argv) < 2:
print "list.py <agedata_x.dat>"
return
@Yoplitein
Yoplitein / diff.py
Last active August 29, 2015 14:27
Lists symbols that were added to a Mystcraft age by the grammar.
import difflib
import gzip
import sys
import pynbt
def main():
if len(sys.argv) < 2:
print "diff.py <agedata_x.dat>"