Skip to content

Instantly share code, notes, and snippets.

'''A-1'''
alpha2num = lambda s: (ord(char) - ord('A') + 1 for char in s)
'''0-0'''
num2num = lambda s: (ord(num) - ord('0') for num in s)
import itertools
import re
LOOKUP = ('A', 'Z', 'Y', 'X', 'U', 'T', 'S', 'R', 'P', 'M', 'L', 'K', 'J', 'H', 'G', 'E', 'D', 'C', 'B')
@rctay
rctay / README.md
Last active January 2, 2016 15:19
[python] aggregate m,...,n to m-n

The program reads a sequence of integers (sorted), and outputs x-y ranges for consecutive integers, outputting it verbatim otherwise.

cat | python ranges.py
1
2
3
7
8
9

^D

@rctay
rctay / README.md
Last active December 29, 2015 17:29
tmux: disqualify from oom-killer (I really should look into tmux conf files)

After running the command, you'll now be in your tmux session, in copy mode, with the contents

echo \-17 | sudo tee /proc/1234/oom_adj

You can then copy this, exit copy mode, paste and execute.

Note: in Ubuntu Raring tmux 1.7-3, copying the line caused a crash.

@rctay
rctay / eval_stable.ml
Last active December 26, 2015 08:39
fixed-point (pseudo) evaluation
let eval_stable n one_step x : lambda * int =
let ctr = new Gen.counter 0 in
let tick () = ctr # inc in
let step = one_step tick in
let rec aux x prev =
let curr = ctr # get in
if prev = curr then
x
else if ctr#get > n then (
print_endline ("exceeded "^(string_of_int n)^" reductions");
@rctay
rctay / lab5-library.ml
Last active December 26, 2015 03:09
lambda calculus library
module EvalLibrary = struct
(* Our familiar friend, the pipe operator *)
let ( |> ) (x:'a) (f:'a->'b) : 'b = f x
(* Takes/returns functions that take a expression to be wrapped *)
let bind name expr (fn:string -> string) =
(* (head^"let "^name^" = "^expr^" in ", " end"^tail) *)
fun body ->
fn ((Printf.sprintf "let %s = %s in %s end") name expr body)
@rctay
rctay / main.ml
Last active December 24, 2015 11:39
[ocaml] CS2104 Lab3 test helper
(*
Instructions:
- copy test_parse_eval.ml into the same directory as lab3.ml (Right-click the
<> to the right of the filename, Save as)
- include the let expression below; feel free to replace the body with your
own tests
*)
let module T = Test_parse_eval.Tester (Calc) (struct let reader = Parser.reader expr2 end) in
let test = T.test in
print_endline "\n= examples =";
@rctay
rctay / index.html
Last active December 21, 2015 05:58
simple vote counting/tallying with angular http://plnkr.co/edit/gist:6260428
<!doctype html>
<html ng-app>
<head>
<meta charset='utf-8'>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-controller="Controller">
@rctay
rctay / app.js
Last active December 21, 2015 05:49
math for physics/physical quantities (viz. values with units), in "worksheets" http://plnkr.co/edit/CHccBbCGltDI2e3U1kVY?p=preview
// Code goes here
angular.module('aModule', [])
.service('quant_alg', function() {
return quant_alg;
})
.controller('ControllerA', function($scope, quant_alg) {
var qa = quant_alg;
angular.extend($scope, qa);
})
<?php
/*
Plugin Name: Login, Relaxed
Description: Logins to the admin dashboard are always redirected to `siteurl` by default. This plugin relaxes this to allow logins from URLs apart from `siteurl`. This is useful if you are logging in to WordPress from localhost.
Plugin URI: https://gist.github.com/rctay/6219624
Version: 0.1
Author: Tay Ray Chuan
*/
function wp_login_loginform_action_blank($url, $path, $orig_scheme=null)
@rctay
rctay / 0.sh
Last active September 22, 2019 15:58
tmux: update current shell's environment's ssh agent forwarding info (ie. value of $SSH_AUTH_SOCK) when reconnecting, eg via PuTTY
# next try: `test` before `export`
val=`tmux show-environment | grep '^SSH_AUTH_SOCK='`;\
test -n "$val" && export "$val"
# with the $_ bash-ism:
test -n `tmux show-environment | grep '^SSH_AUTH_SOCK='`\
&& export "$_";