Skip to content

Instantly share code, notes, and snippets.

(eval-after-load 'dired
'(progn
(define-key dired-mode-map (kbd "c") 'my-dired-create-file)
(defun create-new-file (file-list)
(defun exsitp-untitled-x (file-list cnt)
(while (and (car file-list) (not (string= (car file-list) (concat "untitled" (number-to-string cnt) ".txt"))))
(setq file-list (cdr file-list)))
(car file-list))
(defun exsitp-untitled (file-list)
[js]
//Be careful. It seems completely emulate key press.
//You need Execel app to run this code.
var shellApp = new ActiveXObject("Wscript.Shell");
var ex = WScript.CreateObject("Excel.Application");
shellApp.appActivate("C:\\Windows\\system32\\cmd.exe")
ex.ExecuteExcel4Macro("CALL(\"user32\",\"keybd_event\",\"JJJJJ\",164,56,1,0)");
ex.ExecuteExcel4Macro("CALL(\"user32\",\"keybd_event\",\"JJJJJ\",32,57,1,0)");
ex.ExecuteExcel4Macro("CALL(\"user32\",\"keybd_event\",\"JJJJJ\",32,57,3,0)");
ex.ExecuteExcel4Macro("CALL(\"user32\",\"keybd_event\",\"JJJJJ\",164,56,3,0)");
from PIL import Image
import os
filelist = ['foo.jpg', 'bar.bmp', 'zot.png']
for infile in filelist:
outfile = os.path.splitext(infile)[0] + ".jpg"
if infile != outfile:
try:
Image.open(infile).save(outfile)
except IOError:
#read image and convert grayscal
from PIL import Image
pil_im = Image.open('./data/empire.jpg').convert('L')
pil_im.show()
#change image to thumbnail
#but not change width and height aspect ratio
#read image and convert grayscal
from PIL import Image
pil_im = Image.open('./data/empire.jpg').convert('L')
pil_im.thumbnail((200,200))
pil_im.show()
#crop and paste image
from PIL import Image
pil_im = Image.open('./data/empire.jpg').convert('L')
#cropping
box = (100,100,400,400)#cropping region
region = pil_im.crop(box)
#pasting
from PIL import Image
pil_im = Image.open('./data/empire.jpg').convert('L')
#be careful it may change aspect ratio
out = pil_im.resize((128,128))
#show
out.show()
from PIL import Image
pil_im = Image.open('./data/empire.jpg').convert('L')
#rotate clockwise
out = pil_im.rotate(45)
#show
out.show()
# convert image to numpy array
im = array(Image.open('./data/empire.jpg')) #return numpy array
# show
imshow(im, interpolation='nearest')#or interpolation='None'
# star point
x = [100,100,400,400]
y = [200,500,200,500]
import os
from glob import glob
import cv2
import numpy as np
from numpy import arange
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backend_bases import key_press_handler