Skip to content

Instantly share code, notes, and snippets.

View lelandbatey's full-sized avatar

Leland Batey lelandbatey

View GitHub Profile
@lelandbatey
lelandbatey / treePrint.py
Created August 1, 2014 01:07
Prints a perfect binary tree of given height, just for fun : )
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
IS_TERM=False
if sys.stdout.isatty():
IS_TERM = True
if IS_TERM:
@lelandbatey
lelandbatey / c_white_reducer.py
Last active August 29, 2015 14:05
Obfuscated Tree Printer
#!/usr/bin/env python
from __future__ import print_function
import sys
def strip_comments(instr):
outStr = ""
for line in instr.split('\n'):
outStr+= line.split('//')[0] + '\n'
return outStr
@lelandbatey
lelandbatey / tiny_tree.c
Last active August 29, 2015 14:06
Tiny binary tree printer.
typedef int j;j p(j t,j l){for(;l;--l)putchar(t);}
j main(j c,j**v){j i,h=5;c>1?h=atoi(v[1]):0;h=1<<h;j b=h;for(;b;){b/=2;
for(i=b?h/b:0;i;i--)p(32,b-1),p(!(i%2)*32+32,1);p(10,1);}}
//Prints the following:
//
// @
// @ @
// @ @ @ @
// @ @ @ @ @ @ @ @
<?php
echo('<pre>');
function p($i, $l){
for ($x=0;$x<$l; ++$x){
echo(chr($i));}
}
function mk_tree($h=5){
$i=0;$h=1<<$h;$b=$h;
while ($b>1){
@lelandbatey
lelandbatey / tux_say.php
Created September 18, 2014 18:38
Like cowsay, but Tux, and in PHP
<?php
function tuxsay($str,$M=40){
$W=strlen($str);
if($W>$M) $W=$M;
$tux_array=array(10,32,32,32,92,10,32,32,32,32,92,10,32,32,32,32,32,32,32,32,46,45,45,46,10,32,32,32,32,32,32,32,124,111,95,111,32,124,10,32,32,32,32,32,32,32,124,58,95,47,32,124,10,32,32,32,32,32,32,47,47,32,32,32,92,32,92,10,32,32,32,32,32,40,124,32,32,32,32,32,124,32,41,10,32,32,32,32,47,39,92,95,32,32,32,95,47,96,92,10,32,32,32,32,92,95,95,95,41,61,40,95,95,95,47,10);
$str=wordwrap($str,$W,"\n",1);
echo($str.implode(array_map(function($x){return chr($x);}, $tux_array)) );
}
tuxsay("This is a testing thing that may or may not work.");
ffmpeg -re -i "some_file.mkv" -c:v libx264 -crf 18 -preset veryfast -async 1 -maxrate 1500k -c:a aac -strict experimental -b:a 192k -ar 44100 -ac 2 -bsf:v h264_mp4toannexb -maxrate 1000k -bufsize 3000k -f mpegts udp://127.0.0.1:1234
@lelandbatey
lelandbatey / tiny_tree_print.rs
Created January 12, 2015 20:24
tiny_tree.rs -- A Rust port of my original tiny_tree.c: https://gist.github.com/lelandbatey/99f3c4b99c621c12631d
use std::os;
use std::num::Int;
// Helper function to print out single characters repeatedly.
fn repeat_char(ch: char, mut n: i32){
while n > 0 {
print!("{}", ch.to_string());
n = n-1;
}
}
@lelandbatey
lelandbatey / context.py
Last active August 29, 2015 14:13
A minimal example of a problem with the Python static analyzer.
# This is the pseudocode for the actual code where I found this error
def big_function_to_handle_many_different_cases(varA, varB):
temporary_buffer = ""
def do_the_boilerplate():
SOME_GLOBAL_ARRAY.append(temporary_buffer)
temporary_buffer = "" # Reset the temporary_buffer
for thing in varA:
@lelandbatey
lelandbatey / ping_speaker.sh
Created January 14, 2015 20:49
Have your computer speak when a ping works, like in this classic story: http://ftp.arl.mil/mike/ping.html
#!/bin/bash
# Ping-speaker oneliner
# This shell oneliner will ping a host once twice every second, then call my
# custom text-to-speech program to speak that output. This is meant to act
# similarly to the classic story of a use for ping found here:
# http://ftp.arl.mil/mike/ping.html
# Be aware, I wrote this to work on Cygwin on my system specifically. It also
@lelandbatey
lelandbatey / inplace_cd.sh
Last active October 15, 2021 23:59
In place cd; cd won't create a newline and prompt
# Original
# function cd { command cd $@ > /dev/null; echo -ne "\r\e[1A\e[J"; }
# Written by Kate Adams: https://github.com/KateAdams
function cd {
command cd $1 > /dev/null # pipe stdout, but not stderr
local ret=$?
if [[ $ret == 0 ]]; then