Skip to content

Instantly share code, notes, and snippets.

# A Natural Sort Algorithm in one line
ITEMS = %W(item1 item2 item11 item1 item20 item3 hello other_item other_item7 item)
TRAILING_NUM = /[0-9]*\Z/
natural_sorted = ITEMS.sort.chunk{ |y| y.gsub(TRAILING_NUM, '') }.to_a.map{ |k_v| k_v[1] }.each{ |x| x.sort_by!{ |z| z.scan(TRAILING_NUM).first.to_i }}.flatten
puts natural_sorted
# => ["hello", "item", "item1", "item1", "item2", "item3", "item11", "item20", "other_item", "other_item7"]

Keybase proof

I hereby claim:

  • I am at1as on github.
  • I am willems (https://keybase.io/willems) on keybase.
  • I have a public key ASBJanSm1SKbTunlyBBTt_3BFB8mjHGMiLPmvpjFRO9Zlwo

To claim this, I am signing this object:

@at1as
at1as / valid_ssn.sh
Created June 12, 2016 03:29
Generate a valid Social Security Number
#!/bin/bash
# Generate a valid Social Security Number
function generate() {
SSN=""
valid=0
for i in {1..9}; do
DIGIT=$[RANDOM%9+1]
@at1as
at1as / oxford_comma
Created July 4, 2016 03:26
Add oxford comma to script
jason$ echo "a, b, c and d. e, f, g, and h" | sed 's/\([^,]\)\(\ and\)/\1\,\2/g'
> a, b, c, and d. e, f, g, and h
@at1as
at1as / facetime_kill.sh
Created December 5, 2016 05:30
Kill FaceTime app after X seconds
#!/bin/bash
# Usage : ./facetime_kill.sh 10
# Accepts 1 argument : a number of seconds before stopping app
if [[ $1 ]]
then
echo "Killing Facetime in ${1} seconds"
i=$1
@at1as
at1as / bits.erl
Last active February 22, 2017 06:32
Assignment #1 Functional Programming in Erlang
-module(bits).
-export([bits/1, bitsNoTailRecursion/1, startTests/0]).
%% Functional Programming in Erlang
%% Kent University
%% 21 February 2017
%% Exercise 1 : Summing the Bits
%%