Skip to content

Instantly share code, notes, and snippets.

View antifuchs's full-sized avatar
🕴️

Andreas Fuchs antifuchs

🕴️
View GitHub Profile
# Runs a new "jofrli" session with two windows.
# This starts the jofrli service process in one window, and the emacs connecting to it via slime in the other
new -s jofrli -n emacs "sudo -u jfrli -i -- -c '/usr/bin/emacs -q -l /opt/lisp/jofrli/production/init.el'"
neww -d -t 0 -n lisp "sudo -u jfrli -i -- -c '/opt/lisp/ql/sbcl/bin/sbcl --core /opt/lisp/ql/sbcl/lib/sbcl/sbcl.core --load /opt/lisp/jofrli/production/init.lisp'"
@antifuchs
antifuchs / array_sorted.rb
Created April 16, 2013 16:59
Array#sorted? method for discovering whether an array is sorted in any order. Optionally takes a block and yields to it each element to discover the sort value for that element.
class Array
def sorted?(&block)
case length
when 0, 1 then true
else
init_signum = nil
if block
init_signum = block.call(self[0]) <=> (prev = block.call(self[1]))
else
init_signum = self[0] <=> (prev = self[1])
@antifuchs
antifuchs / hypothesis.ex
Last active December 16, 2015 11:29
Wonder if that'll work...
@doc """
Provides a convenient macro that allows a test to be
defined with a string. This macro automatically inserts
the atom :ok as the last line of the test. That said,
a passing test always returns :ok, but, more important,
it forces Elixir to not tail call optimize the test and
therefore avoiding hiding lines from the backtrace.
## Examples
@antifuchs
antifuchs / pkcs7_constant_time_unpad.go
Last active December 17, 2015 06:19
Even if this looks plausible to you, you are completely bonkers if you even think of using this. Seriously, what is wrong with you.
func unpadPKCS7(data []byte, toSize uint8) int {
// Non-costant time operations on length of the message (can
// be assumed to be public info):
if len(data) == 0 || len(data)%int(toSize) != 0 {
return 0
}
// Ostensibly(!) constant-time operations only from here on:
var lastByteVerbatim, lastByte uint8
var success int
@antifuchs
antifuchs / private.xml
Created May 13, 2013 01:24
Other people have hobbies, I tweak my keyboard config (-:
<?xml version="1.0"?>
<root>
<devicevendordef>
<vendorname>APPLE_INC</vendorname>
<vendorid>0x05ac</vendorid>
</devicevendordef>
<devicevendordef>
<vendorname>FILCO</vendorname>
<vendorid>0x04d9</vendorid>
;;; Patch inf-ruby to load more code by default:
(require 'inf-ruby)
(setq inf-ruby-console-patterns-alist
'(("*.gemspec" . asf-gem)
("scripts/bin/console" . pay-server)
("Gemfile" . default)))
(defun inf-ruby-console-asf-gem (dir)
# Chalk::Dev::Server::ProcessWatcher is an instance of EM::ProcessWatch,
# but this should work for all subclasses of EM::Connection.
before do
@env = proc {}
EM::Environment.register_block(@env)
@watcher = Chalk::Dev::Server::ProcessWatcher.new(@env)
end
# To use @watcher now, you don't need EM.run or any shenanigans.
fn sessionNumber(line: &str) -> Option<int> {
match(line.as_slice().split_iter(':').next()) {
Some(first) => int::from_str(first),
_ => None
}
}
fn occupiedSessions(output: ~str) -> @HashSet<int> {
let set = @HashSet::new();
for line in output.line_iter(){
#[fixed_stack_segment]
fn exec_program(program: &str, args: &[~str]) {
do program.to_c_str().with_ref() |c_program| {
// I don't much care about the ownership of the strings here
// at this point, so let's just fail if execvp isn't working.
unsafe {
let c_args = args.map(|arg| { arg.to_c_str().unwrap() });
// c_args needs a NULL attached to the end though. Here's what I tried:
// let c_args = args.map(|arg| { arg.to_c_str().unwrap() }) + [ptr::null()]; // this screams about unconstrained types.
execvp(c_program, vec::raw::to_ptr(c_args));
#!/usr/bin/env ruby
require 'optparse'
def exp_notation(n)
Math.log10(n).floor
end
def main
options = {}