Skip to content

Instantly share code, notes, and snippets.

@joshkunz
joshkunz / gist:6260694
Created August 18, 2013 09:17
So I guess this is happening...
[1] 03:14:47 Joshkunz:~
$ ping google.com
PING google.com (74.125.225.200): 56 data bytes
64 bytes from 74.125.225.200: icmp_seq=0 ttl=57 time=37.938 ms
64 bytes from 74.125.225.200: icmp_seq=1 ttl=57 time=601.127 ms
64 bytes from 74.125.225.200: icmp_seq=2 ttl=57 time=338.328 ms
64 bytes from 74.125.225.200: icmp_seq=3 ttl=57 time=947.589 ms
64 bytes from 74.125.225.200: icmp_seq=4 ttl=57 time=323.217 ms
Request timeout for icmp_seq 5
Request timeout for icmp_seq 6
@joshkunz
joshkunz / if.rb
Created August 20, 2013 15:02
The many faces of if in ruby.
# Basic ruby conditional
if true
puts "true 1"
end
# But you can also use the python syntax
if true:
puts "true 2"
end
@joshkunz
joshkunz / fizzbuzz_doc.hs
Created August 23, 2013 23:04
The last 4 lines are what really got me.
-- Language: Haskell
-- To Run: $ ghc fizzbuzz_doc.hs && ./fizzbuzz
-- The syntax a -> a -> b is just 'function composition'
-- a -> b is a function that take a parameter of type a
-- and returns something of type b.
-- a -> a -> b is a function of type (a -> (a -> b))
-- which means that it takes an 'a' and returns
-- a function that takes an 'a' and returns a 'b'
-- All functions in haskell are specified this way.
@joshkunz
joshkunz / vlcwrap.c
Last active December 22, 2015 03:29
Wrapper that will close VLC on OSX with a SIGKILL when it receives a SIGINT (useful if you want to terminate it from the command-line with Control-C).
/* Build, (with your favorite compiler) run:
* cc -o vlcwrap vlcwrap.c */
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define VLC_BIN "/Applications/VLC.app/Contents/MacOS/VLC"
@joshkunz
joshkunz / _readme.md
Last active December 22, 2015 17:28
DFA generating utilities

Simple classes for building compatible DFAs in a more intuitive way. (source is below the documentation)

Build a DFA manually

Using it manually is pretty simple, basically you create a new DFA object, and add states to it. States are created automatically when you try and use them, so you don't have to worry about creating them explicitly. Here's an example of creating the DFA shown here.

@joshkunz
joshkunz / 273.c
Last active December 23, 2015 03:39
Answer to 273 following bitwise restrictions.
#include <limits.h>
#include <stdio.h>
/* magic constant */
#define SIGN_MASK INT_MIN
/* negative shift for arbitrary size int */
#define NS ((sizeof(int)<<3) - 1)
/* Positive shift for arbitrary size int */
#define PS (NS - 1)
@joshkunz
joshkunz / mpd_fileaccess.patch
Created October 12, 2013 06:28
Patch for mpd (tag: release-0.17.4) that fixes queuing files outside of MPD's library.
diff --git a/src/client_file.c b/src/client_file.c
index 2ee4333..8174c3b 100644
--- a/src/client_file.c
+++ b/src/client_file.c
@@ -44,12 +44,18 @@ client_allow_file(const struct client *client, const char *path_fs,
instance */
return true;
+ /* Pretty sure this check will never work.
if (uid <= 0) {
@joshkunz
joshkunz / total_lines.c
Created November 5, 2013 22:11
Read a list of null separated files on STDIN and output the number lines (specifically the number of newline characters) found in the files.
#include <stdio.h>
#include <stdlib.h>
FILE* next_file(char delim) {
if (feof(stdin) || ferror(stdin)) { return NULL; }
char * file_name = NULL;
size_t buffer_size = 0;
FILE * out = NULL;
getdelim(&file_name, &buffer_size, delim, stdin);
if (file_name) {
@joshkunz
joshkunz / armage17
Last active January 3, 2016 07:29
Most recent test results.
Testing: ./armage17/triangle
~~~ Failed test. ~~~
[(1, 2147483647), (0, 2147483647), (0, 0)]
[Expected] 'scalene right\n'
[Got] 'isosceles acute\n'
~~~ Failed test. ~~~
[(0, 0), (1073741822, 1073741824), (2147483645, 2147483647)]
[Expected] 'scalene obtuse\n'
[Got] 'isosceles obtuse\n'
~~~ Failed test. ~~~
@joshkunz
joshkunz / _readme.md
Last active August 29, 2015 13:55
Canvas subscription script.

Here's the script I wrote that automatically subscribes you to all forum threads. It's built to be run as a cron job.

You'll need to generate an API token for it which can be done at the bottom of the [profile settings page][profile]. It uses canvas's REST API to do the actual subscribing, the documentation for the api [is here][capi].

I also hate Canvas's WYSIWYG editor, so I wrote some scripts to render markdown, and then inline the styles. Typically I'll write my posts in a text file, and then run:

$ fpost name_of_file.md | pbcopy    # pbcopy is an OSX thing, xclip -in works for xwindows.

and then just post the raw HTML into the WYSIWYG's 'html entry' portion.