Skip to content

Instantly share code, notes, and snippets.

View redraiment's full-sized avatar
🏠
Working from home

Zhang, Zepeng (redraiment) redraiment

🏠
Working from home
View GitHub Profile
@redraiment
redraiment / r.el
Created October 10, 2013 16:20
Emacs Lisp 正则表达式简化
(defun conj (v &rest c)
(append v c))
(defun r (exp)
(do ((e (cons nil (string-to-list exp))
(let ((s (car e)) (x (cdr e))
(a (cadr e)) (d (caddr e)))
(cond
((= a ?%)
(cons (apply (apply-partially #'conj s)
@redraiment
redraiment / startup.py
Created October 11, 2013 12:40
Python启动文件,为REPL添加自动补全以及历史功能
import rlcompleter
import readline
import atexit
import os
# http://stackoverflow.com/questions/7116038/python-tab-completion-mac-osx-10-7-lion
if 'libedit' in readline.__doc__:
readline.parse_and_bind('bind ^I rl_complete')
else:
readline.parse_and_bind('tab: complete')
@redraiment
redraiment / sphere.js
Last active November 14, 2021 15:04
将n个点均匀地分布在球面上。算法利用正多面体(此处选用正八面体)剖分球面。
// 球面坐标系统
var Spherical = function(radial, polar, azimuthal) {
var self = this;
self.radial = radial || 1
self.polar = polar || 0
self.azimuthal = azimuthal || 0
};
// 转换成直角坐标系统
@redraiment
redraiment / 2000.cpp
Created November 16, 2013 11:26
杭电ACM 2000到2099题
#include <algorithm>
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void) {
char s[4];
while (cin >> s) {
sort(s, s + 3);
@redraiment
redraiment / html2md.rb
Created December 3, 2013 15:15
iKnowledge 1.0 HTML格式自动转换成2.0 Markdown格式
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'cgi'
module Html
def self.tag(content)
n, a = content.split /\s+/, 2
{:tag => n}.update(attr: Hash[(a or '').scan(/(\w+)="([^"]*)"/)])
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => ":memory:"
)
@redraiment
redraiment / css_reset.rb
Created March 19, 2014 06:05
CSS Reset for all Web Browser
# minimize reset tag level, so that user can override them
styles = {}
Object.class_eval do
define_method :style do |tag, properties|
styles[tag] ||= {}
styles[tag].merge!(properties)
end
end
@redraiment
redraiment / erm.rb
Last active August 29, 2015 13:57
ERM: Embedded Ruby Macro, code to write code
#!/usr/bin/ruby
require "fileutils"
require "erubis"
require "yaml"
def erm(source)
content, data = "", {}
loop do
properties, fragment = File.read(source).split("---\n", 2)
@redraiment
redraiment / ejs.js
Last active August 29, 2015 14:01
Embedded JavaScript
var File = function(name) {
this.file = new java.io.File(name);
};
File.prototype.map = function(fn) {
var fin = new java.util.Scanner(this.file);
var content = [];
while (fin.hasNextLine()) {
content.push(fn(fin.nextLine()));
}
(defun current-sentence ()
(interactive)
(replace-regexp-in-string "\n" ";"
(substring-no-properties
(or (sentence-at-point)
(save-excursion
(backward-sentence)
(sentence-at-point))))))
(defun commit-last-js ()