Skip to content

Instantly share code, notes, and snippets.

View RaminHAL9001's full-sized avatar

Ramin Honary RaminHAL9001

View GitHub Profile
(defun rename-current-buffer (new-bufname)
"Prompts for a new buffer name in the minibuffer using the
current buffer name as an initial value, renames the current
buffer to the value entered."
(interactive
(let ((curbufname (buffer-name)))
(list (read-string "New buffer name: " curbufname 'buffer-name-history curbufname t))))
(rename-buffer new-bufname))
(global-set-key (kbd "C-c r b") 'rename-current-buffer)
<html><head>
<style type="text/css">
div.top-level {
width: 20cm;
left-margin: 0.5cm;
right-margin: 0.5cm;
}
p, ol, td, blockquote {
font-family: serif;
color: #000000;

Well I think you have made a wise decision to learn Haskell, but it is really unlike any programming language you have probably learned until now.

Lets first review what id and const do.

The id function is a function that doesn't change anything -- whatever you pass to it, the same value comes out unchanged. So id 5 equals 5, id False equals False id "hello" equals "hello", id () equals ().

The const function is a function that always returns the same value, no matter what you give to it. const 5 True equals 5, const 5 "hello" equals 5, const 5 () equals 5, no matter what, const 5 always returns 5.

Now, do you understand what the map and iterate do? The map function takes a list and a function and uses the function to modify each elements in the list with the function. For example:

@RaminHAL9001
RaminHAL9001 / timer.bash
Last active August 29, 2015 14:12
Command line oven timer program written in Bash script. Specify wait time in "hh:mm:ss" or "mm:ss" format.
#!/bin/bash
# An oven timer. This script uses the "notify-send" program to display a
# message after a certain amount of time specified as command line arguments.
# It optionally plays a sound using "mplayer" after calling "notify-send".
# Waiting time can be specified in a user friendly (hours : minutes : seconds)
# format, e.g. "hh:mm:ss" or "mm:ss".
#
# Copyright (C) Ramin Honary 2014, all rights reserved.
# Licensed under the GNU General Public License:
# http://www.gnu.org/licenses/gpl.html
public static int damLevDist(String A, String B) {
StringBuilder builder = new StringBuilder();
builder.append(" ");
A = A.toLowerCase(); B = B.toLowerCase();
int alen = A.length(), blen = B.length();
int maxdist = alen + blen;
int alphabet[] = new int[127];
for (int i = 0; i < alphabet.length; ++i) {
alphabet[i] = 0;
}
@RaminHAL9001
RaminHAL9001 / FoldPrec.hs
Created January 17, 2014 20:35
BOMDAS, PEMDAS, order of operations. Folding a list of elements where each element is paired with an operator. Providing the operators precedence and associativity, the foldPrec function will infix the elements of the list by the correct order of operations. This is the general case, so it works for anything, not just arithmetic operations.
-- "Data/Function/FoldPrec.hs" fold with precedence and associativity.
--
-- Copyright (C) 2014 Ramin Honary.
--
-- The source code is free software: you can redistribute it and/or
-- modify it under the terms of the GNU General Public License as
-- published by the Free Software Foundation, either version 3 of the
-- License, or (at your option) any later version.
--
-- This software is distributed in the hope that it will be useful,