Skip to content

Instantly share code, notes, and snippets.

@flaneur2020
flaneur2020 / ubuntu.md
Created October 24, 2012 13:19
install ubuntu on a mbp
hdiutil convert -format UDRW -o ~/path/to/target.img ~/path/to/ubuntu.iso
diskutil unmountDisk /dev/diskN
sudo dd if=/path/to/downloaded.img of=/dev/rdiskN bs=1m
diskutil eject /dev/diskN

http://is.gd/sRwjbN

@flaneur2020
flaneur2020 / vruntime.rb
Created October 23, 2012 07:57
统计几个进程的vruntime
def pick_pids(tasks)
pids = tasks.map do |t|
pids = `pgrep #{t}`.scan(/\d+/).map(&:to_i)
pids.sample
end
pids
end
def vruntimes(pids)
results = []
@flaneur2020
flaneur2020 / traps201209.md
Created September 18, 2012 08:31
traps: 2012-09
  • python的方法参数不可初始为{},多次调用会引用到同一个dict对象上。
@flaneur2020
flaneur2020 / query.py
Created September 18, 2012 04:01
a query class for quixote the god damned.
# -*- encoding:utf-8 -*-
#
# 2012 by fleuria
# Inspired by vino from lepture
#
import logging
import collections
import MySQLdb as mysql
@flaneur2020
flaneur2020 / auto_clear_bl.vim
Created August 24, 2012 07:25
vim auto clear blank lines
fun! DelBlank()
let _s=@/
let l = line(".")
let c = col(".")
:%s/\s\+$//e
let @/=_s
call cursor(l, c)
endfun
au BufWritePre *.* :call DelBlank()
@flaneur2020
flaneur2020 / quixote.md
Created August 24, 2012 06:30
quixote routing

quixote是一个很落后的框架,使用它只有一个理由,便是我们亲爱的历史原因。

Routing

quixote使用python的类来模拟php的目录结构。

  • _q_exports: 列出这一"目录"下的所有"文件"
  • _q_index(request): 相当于index.php
  • _q_lookup(request, param): 相当于method_missing
@flaneur2020
flaneur2020 / mysql-notes.md
Last active October 9, 2015 00:28
Mysql notes

Pick up the right row in group by.

group by中选出的行并不会按照order by的顺序排列,要让它按照顺序选择出正确的,可以套一个嵌套select,让它在里面排好序再交给group by。

select * from (select problem_id, author_id, time from oj_submission order by time desc) submission 
where problem_id in (1,2) 
group by problem_id;
@flaneur2020
flaneur2020 / fs.h
Created August 15, 2012 14:16
fs.h in ffs
/*
* Copyright (c) 1982, 1986, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@flaneur2020
flaneur2020 / py-stack.md
Created July 27, 2012 04:15
notes on django

python的环境与ruby还是有很大不同的,而且框架多如牛毛,将遇到的坑记在这里。

ps: django跟屎一样。

virtualenv

直觉上很容易当作virtualenv当作rvm的存在,但实际上python的版本往往并非大问题,更多需要对付的还是三方库。virtualenv其实更多扮演的是Bundler的角色,但在操作上有所不同。

Bundler通过Gemfile列出当前项目需要的gem并将它们安装到系统,在代码中通过Bundler.require(:all)引入gem,并在bundle exec中设置环境变量之类,以选择正确版本的gem。

// 写了一天的哈希表到最后觉得不如用红黑树...
// 造轮子的下场果然是跪呢...
// by fleuria 2012
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "str.h"
#include "pool.h"
#include "hash.h"