Skip to content

Instantly share code, notes, and snippets.

@ptpt
ptpt / gist:258852
Created December 17, 2009 16:30
define keys on emacs
;;; define-key in a easy way -*- emacs-lisp -*-
;; Copyright (C) 2010 Tao Peng <ptpttt@gmail.com>
;; Author: Tao Peng <ptpttt@gmail.com>
;; Keywords: key
;; This file is NOT part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it under
;; Act on lines if mark is not active
(defmacro defadvice-act-line-as-region-if-no-mark (orig-function)
`(defadvice ,orig-function (before act-on-line-if-no-mark activate compile)
,(format "Like `%s', but acts on the current line if mark is not active." orig-function)
(interactive
(if mark-active
(list (region-beginning) (region-end))
(list (line-beginning-position) (line-beginning-position
(+ 1 (prefix-numeric-value current-prefix-arg))))))))
@ptpt
ptpt / qsort.vb
Created March 11, 2010 15:53
Quick sort in VB.NET
Module Module1
Function partition(ByRef a As Array, ByVal l As Integer, ByVal r As Integer)
Dim j As Integer = l
Dim p As Integer = a(r)
For i = l To r - 1
If a(i) < p Then
Dim tmp As Integer = a(i)
a(i) = a(j)
a(j) = tmp
#include <stdio.h>
#define MAX_CHAR 255
int main(void)
{
int cc[MAX_CHAR+1];
char c;
int max_cc = 0;
int i = 0;
#!/usr/bin/env python
def bits(n):
bstr = ""
while (n>0):
bstr = str(n%2) + bstr
n = n / 2
return bstr
if __name__ == '__main__':
@ptpt
ptpt / kxt.sh
Created November 5, 2010 14:59
download music from kxt.fm
#!/bin/bash
curl -s http://feed.feedsky.com/kxtfm|grep -o \"http://.*\\.mp3\"|xargs wget -N
@ptpt
ptpt / ido-recentf.el
Created November 28, 2010 15:53
Find recent files using ido-mode
(defvar ido-recentf-list nil
"internal use")
(defun pt-recentf-ido-find-file ()
"Find recently opened files using ido-mode."
(interactive)
(recentf-cleanup)
(setq ido-recentf-list nil)
(let (records suffix)
(dolist (file recentf-list)
@ptpt
ptpt / binary_search.c
Created December 17, 2010 00:21
Binary search in C
#include<stdio.h>
#include<assert.h>
int binary_search(int a[], int b, unsigned int length)
{
if (length==0) return -1;
unsigned int mean = length/2;
if (b==a[mean])
return b;
else if (b<a[mean])
@ptpt
ptpt / postfix.py
Created March 20, 2011 23:38
eval postfix
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division
class Stack(list):
@property
def top(self):
if len(self)==0:
return None
Sub assign_level()
Dim pFLayer As IFeatureLayer
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Set pFLayer = pMxDoc.FocusMap.Layer(0)
Dim pSel As IFeatureSelection
Set pSel = pFLayer
Dim pSelectionSet As ISelectionSet
Set pSelectionSet = pSel.SelectionSet
Dim OIDList(1024) As Long