Skip to content

Instantly share code, notes, and snippets.

@lsfalimis
lsfalimis / append-attachment-en.scpt
Last active March 11, 2024 03:05
Append timestamp and theFile with line break to TARGETNOTE working with Hazel
tell application "Evernote"
set _selectedNote to false
set _notes to get every note of every notebook where its title contains "TARGETNOTE"
repeat with _note in _notes
if length of _note is not 0 then
set _selectedNote to _note
end if
end repeat
tell item 1 of _selectedNote to append text return & return & date string of (current date) & time string of (current date) & return
tell item 1 of _selectedNote to append attachment theFile
@lsfalimis
lsfalimis / sortChinese.py
Created July 20, 2014 11:35
sort Chinese. Use thru Keyboard Maestro, see http://i.imgur.com/yAFq01d.png
# coding: utf-8
import sys
from pypinyin import pinyin
import pypinyin
def getPinyin (x):
y = pinyin(unicode(x,'utf-8'), style=pypinyin.TONE2)
lst = []
for e in y:
lst = lst + e
@lsfalimis
lsfalimis / disable-OS-X-animation
Created May 4, 2014 01:32
disable OS X animation (10.9.2)
#Finder
#disable snap to grid animation
defaults write com.apple.finder AnimateSnapToGrid -bool false
#disable some animations
defaults write com.apple.finder DisableAllAnimations -bool true
#disable opening files zoom animation
defaults write com.apple.finder ZoomRects -bool false
@lsfalimis
lsfalimis / removeOrReplace.scpt
Last active March 15, 2017 12:21
Remove or replace texts in AppleScript
(*
I changed some parts of http://foolsworkshop.com/applescript/2008/05/an-applescript-replace-text-method/
*)
on removeText(unwanted, theText)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to unwanted
set theText to text items of theText
@lsfalimis
lsfalimis / yFinder.scpt
Last active March 12, 2017 14:46
Copy the paths of Finder files and folders
(*
if select multiple items, copy paths of them with one in each line;
if select an item, copy its path;
if none is selected, copy the current folder path.
*)
tell application "Finder"
set sel to the selection
if (count of sel) is greater than 1 then
set theList to ""
@lsfalimis
lsfalimis / AutoHotKey.ahk
Created August 9, 2014 08:34
AutoHotKey.ahk
;-Caption
LWIN & LButton::
WinSet, Style, -0xC00000, A
return
;+Caption
LWIN & RButton::
WinSet, Style, +0xC00000, A
return
@lsfalimis
lsfalimis / rtab.sql
Created September 3, 2014 15:46
relational table, mysql
create table one_mul_map (
id_a int unsigned not null default '0',
id_b int unsigned not null default '0',
primary key (id_a,id_b),
key mfk (id_b),
constraint ofk foreign key (id_a) references one (id),
constraint mfk foreign key (id_b) references mul (id)
) engine = innodb;
@lsfalimis
lsfalimis / weibo.r
Last active August 29, 2015 14:05
怎么对微博做聚类?求教...
# MySQL
# 先安装 RMySQL,相当折腾 http://lsfalimis.github.io/link--install-rmysql-on-mavericks/
library(RMySQL)
con = dbConnect(MySQL(), user="USERNAME", password="PASSWORD", dbname="DATABASENAME", host="HOST")
# 为了使中文不再显示为问号
dbSendQuery(con, 'set names utf8')
# COLUMN 是微博文字
rs = dbSendQuery(con, "select COLUMN from TABLE limit 100")
data = fetch(rs, n=-1)
@lsfalimis
lsfalimis / stata.do
Last active August 29, 2015 14:04
Stata (whole and regional) panel data analysis
/*
author: lsfalimis
blog: http://lsfalimis.github.io/
Stata setup: Stata 13 on Win
output path: C:\data
0. -search- to search for packages, -help COMMAND- to look up the manual of COMMAND where you can also find abbreviation.
1. Prepare data in excel which has id, year, y, x1, x2, x3 and region.
2. Take (natural) logarithm of y, x1, x2, x3.
3. Produce LaTeX tables of descriptive statistics with paranoiac syntax, before and after taking logarithm; using outreg2.
4. Produce plain text tables of correlation using mkcorr which doesn't support conditionals,
@lsfalimis
lsfalimis / rotateDatavisualizationTickLabel.tex
Last active August 29, 2015 14:04
#LaTeX rotate datavisualization tick label
\begin{figure}[ht]
\caption{Caption}\label{fig1}
\floatfoot{Data source: Yearbook (\cite{NBS:2000})}
\centering
\begin{tikzpicture}
\datavisualization
[scientific axes=clean,
x axis={
attribute=year,
length=4cm,