Skip to content

Instantly share code, notes, and snippets.

@rohitn
rohitn / formatJSON.m
Created October 25, 2021 01:19 — forked from szhorvat/formatJSON.m
Format imported JSON for readability in Mathematica
formatJSON[json_] := formatRawJSON@rulesToAssociations[json]
rulesToAssociations[rules_] :=
Replace[rules, r : {__Rule} :> Association[r], {0, Infinity}]
basicTypeQ[_String | True | False | Null | (_?NumericQ)] = True;
basicTypeQ[_] = False;
formatRawJSON[json_] :=
@rohitn
rohitn / gridCaptive
Created September 16, 2021 16:57 — forked from rebcabin/gridCaptive
Mathematica functions for displaying captive expressions in Grid form.
dpyNullary[ex_] :=
Grid[{{ex, ""}},
Frame -> {All,False},
Alignment -> Left,
Background -> {{LightOrange,{LightYellow}}}];
dpyMultiary[key_, vals_] :=
With[{c = Length @ vals},
Module[{
spans = Table["", {c}],
@rohitn
rohitn / keychain2certfile.rb
Last active August 29, 2015 14:27 — forked from docwhat/keychain2certfile.rb
Creates an SSL_CERT_FILE on OSX (when using Homebrew) that won't break JRuby. Make sure you run this with normal ruby, not JRuby! See https://github.com/jruby/jruby-openssl/issues/56
#!/usr/bin/env ruby
# Parts stolen with no regret from Homebrew's OpenSSL formula.
require 'fileutils'
require 'openssl'
require 'digest/md5'
require 'digest/sha1'
CERT_FILE = ENV.fetch('SSL_CERT_FILE', '/usr/local/etc/openssl/cert.pem')
@rohitn
rohitn / fun.rb
Created October 1, 2013 23:41 — forked from judofyr/fun.rb
class Symbol
def | other
-> arg { other.to_proc[arg.send(self)] }
end
def call(*args)
-> arg { arg.send(self, *args) }
end
end
@rohitn
rohitn / whitespace-a-like.rb
Created November 27, 2012 13:54 — forked from Dan-Q/whitespace-a-like.rb
Encode a Ruby program into a version composed almost entirely of unicode whitespace characters. Decodes itself on the fly.
#!/usr/bin/env ruby
# encoding: utf-8
CHARS = %w{                       ​ ‌ ‍    }
def encode(string)
string.chars.map{|c|"#{CHARS[c[0]/16]}#{CHARS[c[0]%16]}"}.join
end
program = <<-EOF