Skip to content

Instantly share code, notes, and snippets.

View nibrahim's full-sized avatar

Noufal Ibrahim nibrahim

View GitHub Profile
@nibrahim
nibrahim / pygments-pygame.py
Created January 9, 2011 20:40
Using pygments to highlight code for use in pygame
#!/usr/bin/env python
import pygame
from pygame.locals import *
from pygame.color import Color
from pygments.lexers import PythonLexer
from pygments.styles.emacs import EmacsStyle
@nibrahim
nibrahim / line-length-sort.el
Created October 22, 2010 10:34
Sort lines by length
(defun sort-lines-by-length (b e)
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region b e)
(let ((items (sort
(split-string
(buffer-substring (point-min) (point-max)) "[\n]")
(lambda(x y) (< (length x) (length y)))))
)
@nibrahim
nibrahim / pycon-plugin-presentation.tex
Created October 22, 2010 09:19
Code samples in beamer
\documentclass {beamer}
\usepackage{graphics}
\usepackage{listings}
\usetheme{Berkeley}
\title {Plugin frameworks}
\subtitle {3 approaches to designing plugin APIs}
@nibrahim
nibrahim / nkv-session.el
Created August 3, 2010 18:18
Poor mans session management for Emacs
; Cheap and dirty session management for Emacs.
; Add the location of this file to your load-path,
; Do a (require 'nkv-session) in your .emacs
; Then hit f9 to load up your session files.
; While you work, if you want to remember a file, hit f9 in the buffer.
; If you want to remember all the current open buffers, you can simply call nkv/session-save-current-buffers
; Whenever you want to save, call nkv/save-session.
; Or you can add nkv/save-session to kill-emacs-hook to save the session upon quit automatically.
; Next time, hit f9 to reload your files.
;
@nibrahim
nibrahim / gist:466899
Created July 7, 2010 16:19
Pomodoro timer as similar to the online focus booster as a shell script
function alarm() {
# First argument is the number of minutes spent on work (one pomodoro)
# Second argument is the rest time.
# I usually invoke this as alarm 30 5 (work for 30 minutes, rest for 5)
work_time=$(echo "$1*60" | bc)
rest_time=$(echo "$2*60" | bc)
( mpg123 --loop -1 ~/scratch/clock-ticking-4.mp3 > /dev/null 2>&1 &
mpg123pid=$!
(sleep ${work_time} &&
kill $mpg123pid &&
@nibrahim
nibrahim / edit.el
Created April 13, 2010 06:49
Emacs/Zsh snippet to open files an jump to a specific line
(require 'server)
(server-start)
(defun nkv-find-file-and-jump (spec)
(interactive "s")
(let ((f (car (split-string spec ":")))
(l (cadr (split-string spec ":"))))
(find-file f)
(if l (goto-line (string-to-int l)))))