Somewhere I Belong

All about geek's life


  • 首頁

  • 歸檔

  • 關於

  • 標籤

  • 開源專案

刪除 Twitter 所有 Tweets (Python)

發表於 7月 26 2014 | 0 Comments

之前就一直很想整理那個亂亂的 Twitter 帳號,苦無方法一次可以把全部以往訊息刪除的工具!
因為以前都亂連動一些有的沒的社群網路,整個舊有點髒髒,上網搜尋到幾個輔助網站也沒啥鳥用!剛好看到這位 Dave Jeffery 寫的小巧 Python Script 來達成任務

# -*- coding: utf-8 -*-
"""
This script will delete all of the tweets in the specified account.
You may need to hit the "more" button on the bottom of your twitter profile
page every now and then as the script runs, this is due to a bug in twitter.
You will need to get a consumer key and consumer secret token to use this
script, you can do so by registering a twitter application at https://dev.twitter.com/apps
@requirements: Python 2.5+, Tweepy (http://pypi.python.org/pypi/tweepy/1.7.1)
@author: Dave Jeffery
"""
import tweepy
CONSUMER_KEY = 'XXX'
CONSUMER_SECRET = 'XXX'
def oauth_login(consumer_key, consumer_secret):
"""Authenticate with twitter using OAuth"""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth_url = auth.get_authorization_url()
verify_code = raw_input("Authenticate at %s and then enter you verification code here > " % auth_url)
auth.get_access_token(verify_code)
return tweepy.API(auth)
def batch_delete(api):
print "You are about to Delete all tweets from the account @%s." % api.verify_credentials().screen_name
print "Does this sound ok? There is no undo! Type yes to carry out this action."
do_delete = raw_input("> ")
if do_delete.lower() == 'yes':
for status in tweepy.Cursor(api.user_timeline).items():
try:
api.destroy_status(status.id)
print "Deleted:", status.id
except:
print "Failed to delete:", status.id
if __name__ == "__main__":
api = oauth_login(CONSUMER_KEY, CONSUMER_SECRET)
print "Authenticated as: %s" % api.me().screen_name
batch_delete(api)
view raw delete_all_tweets.py hosted with ❤ by GitHub

事前準備

  1. Twitter App 你可以到這邊申請
  2. Python 2.5+
  3. Tweepy sudo pip install tweepy
  4. Oauthlib sudo pip oauthlib
  5. 上面那段 Script git clone https://gist.github.com/113241.git

動手開幹

接下來把 Script 中的 CONSUMER_KEY 與 CONSUMER_SECRET 換成你剛剛申請 Twitter APP 的。然後執行 python delete_all_tweets.py

他就會出現提示Authenticate at XXX(你的帳號) and then enter you verification code here > 後面會接 oauth 的網址,點下去按授權會拿到一組 verify code,貼上來按 Enter

接著他會確認你是否真的要刪除,輸入 yes (大小寫沒差)。之後就會跳出

Deleted: XXX
Deleted: XXX
Deleted: XXX
Deleted: XXX
Deleted: XXX

等待他執行完畢後,你的帳號就乾乾淨淨囉!

華碩 N16 無線網路連不上 (IGMP、中華MOD)

發表於 7月 23 2014 | 1 Comment

今天早上因為颱風的關係跳電兩次,家裡面的 RT-N16 忽然失億了…於是我就被我媽叫起床修理,因為他們起床發現沒有網路快要抓狂了。囧rz…

把 AP 重開後確認他的確是失億了,原本的設定都消失了。大概是 Nand flash 不正常斷電損毀後他自動復原吧?(瞎猜),總之我就把 Hinet 小卡片帳號密碼打上,常用設定設好後…發現 WIFI 怎麼看的到吃不到,一直連不上!

由於我家網路架構比較特殊,為了要有 Gbps LAN 以及 MOD 正常使用並且不干擾其他裝置

線路圖如下:


牆壁網路孔 <---> SWITCH <---> MOD, 小米盒子, Apple TV (都是 DHCP)
|
|
|
ASUS N16 <--WAN and LAN 各接一條--> 中華電信小烏龜
|
|
PC (DHCP), NAS (PPPoE 自己撥號取得固定 IP)
  1. 其中小烏龜停用 DHCP 功能,統一由 N16 配發。
  2. 小烏龜設定 PORT ISOLATION 功能,將與 N16 LAN/WAN 兩孔隔開
  3. N16 內部網路設定(LAN) - IPTV 中的 啟動群播路由、Enable efficient multicast fowarding 一定要一定要一定要打開,今天我就是忘記打開所以 WIFI 一直連不上。這個要是不開 MOD 的廣播封包會把你的網路炸爛…

    想不到遇到有人接法跟我一樣,然後遇到一樣問題

筆記一下,免得下次 N16 罷工我又忘了怎麼設定…

MySQL 匯出成 *.CSV

發表於 7月 14 2014 | 0 Comments

要把 MySQL 倒出來…以前只會傻傻用 phpmyadmin 來做這檔事…(也好久以前了啦!

稍微記錄一下這次的內容方便未來使用

SELECT *
FROM tag_value_tbl
WHERE `acquire_time` > '2014-03-01 00:00:00'
INTO OUTFILE '/tmp/meterdata.csv'
FIELDS TERMINATED BY '\t'
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

基本上就是設定 INTO OUTFILE FIELDS TERMINATED BY ENCLOSED BY LINES TERMINATED BY 這些變數,前面當然就是你要 select 那些東西塞進去檔案。

ionic 之第一次安裝就失誤 Unable to add plugins

發表於 7月 4 2014 | 0 Comments

今天忽然看到有人分享 ionic 相關訊息,一時手癢想說來玩一下,沒想到就碰壁了…

先聲明以下環境是 Windows 8.1 64-bit,我按照官方網站上面的指示

$ npm install -g cordova ionic

結果不知道為什麼,我直接在開始選單執行 Node.js command prompt系 統會說權限不足(Try Administrator),我自己開 cmd 就可以,也許這是種下之後安裝錯誤的種?

第二步要開新專案,有 blank, tabs, sidemenu 三種可以選,想說來個 tags 好了…

$ ionic start myApp tabs

結果…

H:\Dropbox\project\mobileapp>ionic start newapp tabs
Running start task...
Creating Ionic app in folder H:\Dropbox\project\mobileapp\newapp based on
tabs project

DOWNLOADING: https://github.com/driftyco/ionic-app-base/archive/master.zip

DOWNLOADING: https://github.com/driftyco/ionic-starter-tabs/archive/master.zip
Initializing cordova project.
Fetching plugin "org.apache.cordova.device" via plugin registry
Fetching plugin "org.apache.cordova.console" via plugin registry
Fetching plugin "https://github.com/driftyco/ionic-plugins-keyboard" via git clo
ne
Error: Command failed: fatal: could not create work tree dir 'C:\Users\YOURUSERNAME\AppD
ata\Local\Temp\plugman\git\1404399211161'.: No such file or directory

at ChildProcess.exithandler (child_process.js:647:15)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:753:16)
at Process.ChildProcess._handle.onexit (child_process.js:820:5)
ERROR: Unable to add plugins. Perhaps your version of Cordova is too old. Try up
dating (npm install -g cordova), removing this project folder, and trying again.

Exiting.

errr….我不是剛剛才裝了 Cordova 嗎?怎麼可能過期阿!於是上網找尋一下,發現有人情況跟我一樣,他的解法是:

以下為關鍵片段,沒有這個目錄或檔案…通常是在不存在的資料夾下產生檔案2k7
情況會出錯,所以他老兄就手動幫他建立了 C:\Users\YOURUSERNAME\AppData\Local\Temp\plugman\git\

'C:\Users\YOURUSERNAME\AppD
ata\Local\Temp\plugman\git\1404399211161'.: No such file or directory

然後再執行一次…

H:\Dropbox\project\mobileapp>ionic start newapp tabs
Running start task...
Creating Ionic app in folder H:\Dropbox\project\mobileapp\newapp based on
tabs project

DOWNLOADING: https://github.com/driftyco/ionic-app-base/archive/master.zip

DOWNLOADING: https://github.com/driftyco/ionic-starter-tabs/archive/master.zip
Initializing cordova project.
Fetching plugin "org.apache.cordova.device" via plugin registry
Fetching plugin "org.apache.cordova.console" via plugin registry
Fetching plugin "https://github.com/driftyco/ionic-plugins-keyboard" via git clo
ne

H:\Dropbox\project\mobileapp>

結案,結果 APP 還沒開始寫…(暈

source: Unable to add plugins. Perhaps your version of Cordova is too old

Windows XP 登入後立刻被登出 (忽然要輸入登入密碼)

發表於 6月 24 2014 | 0 Comments

這一天老媽忽然把電腦搬到我面前告訴我,不能開機了 …

看了一下,奇怪原本不需要輸入密碼的電腦怎麼忽然要輸入使用者名稱與密碼?心想應該是他們不小心弄到什麼了!於是就開始輸入一些例如:Administrator試圖登入。

顯然事情沒有這麼簡單,所以我又找了一些關於忘記密碼的解法。當然這過程當中可以說是困難重重,因為我的電腦都是 sata 介面,連 光碟機、IDE 什麼的都沒有,也不能用 USB 來製作救援。因為電腦已經十歲了,還無法支援 USB 開機。原本想說拿一台外接光碟機來用,但是發現我的快接線壞掉了…真是一波三折。

總結一下,最後就是拿了 伽利略 旗艦版 SATA&IDE TO USB3.0 光速線 這個好物來接到我電腦上,並搭配 VirtualBox 來使用。

  1. ERD Commander 2005
  2. 快接線

就這樣,把使用者密碼給改了。原本以為故事到此結束!但是我發現根本無法登入!就算密碼對了,登入後也會立刻被登出

於是找到了這篇 Windows Log on and Log off immediately.

關鍵在於這個 HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon 新增這兩個鍵

Shell = explorer.exe
Userinit = X:\windows\system32\userinit.exe

ps. HKLM = HKEY_LOCAL_MACHINE

以上,終於達成修理電腦的任務。

想不到十年的電腦到現在還是一尾活龍阿…

在 Samba 分享資料夾上編輯檔案變成可執行權限

發表於 6月 12 2014 | 0 Comments

因為工作關係桌機使用 Windows 然後檔案透過 Samba 分享在 Linux 環境當中…

但是說也奇怪,每次我使用 Sublime Text 3 編輯完一個檔案存檔後都會變成可執行的權限 Permission 755

起初我一直懷疑是 Sublime Text 3 是不是給我動什麼手腳,後來才看到原來有人跟我有一樣的問題!!!

居然是不起眼的 Samba 在作祟

問題就在於 smb.conf 中的參數設定

map archive = false

要設定成 false 才行,預設是 true。來看看官方文件怎麼說…

This controls whether the DOS archive attribute should be mapped to the UNIX owner execute bit. The DOS archive bit is set when a file has been modified since its last backup. One motivation for this option is to keep Samba/your PC from making any file it touches from becoming executable under UNIX. This can be quite annoying for shared source code, documents, etc…

原來就是這個好意的設定讓我困擾這麼久…

將 Debian/Ubuntu 套件清單輸出備份與還原

發表於 6月 12 2014 | 0 Comments

要打包系統所以要把目前裝過的套件全部記錄起來

簡單的拜了一下 Google 大神

dpkg --get-selections | grep -v deinstall

輸出已安裝清單

tasksel                                         install
tasksel-data install
tcpd install
tcpdump install
tmux install
traceroute install
ttf-dejavu-core install
tzdata install
ubuntu-keyring install
ubuntu-minimal install
ucf install
udev install
unattended-upgrades install
........................skip...........................
vnstat install
vsftpd install
w3m install
webalizer install
wget install
whiptail install
whois install
wireless-regdb install
x11-common install
xauth install
xfonts-encodings install
xfonts-utils install
xkb-data install
xml-core install
xz-lzma install
xz-utils install
zlib1g install
zlib1g-dev install
zsh install

所以說你想要備份目前機器上所有 package 清單就可以輸入下列指令

備份已安裝清單

dpkg --get-selections > pkglist.txt

還原已安裝套件

dpkg --clear-selections
sudo dpkg --set-selections < list.txt

source: How to list all installed packages?

Node.js npm 安裝 node-sqlite3 套件在不同平台

發表於 6月 10 2014 | 0 Comments

今天在公司要跨平台編譯 node-sqlite3,結果編出來的東西一直有問題…
搞半天原來是因為少下了一個指令,囧

在 node 在 0.8 版本之後使用了 node-gyp,可以讓工程師比較輕鬆地將一些 native code 編譯到不同平台上。

node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js, which takes away the pain of dealing with the various differences in build platforms. It is the replacement to the node-waf program which is removed for node v0.8. If you have a native addon for node that still has a wscript file, then you should definitely add a binding.gyp file to support the latest versions of node.

由於小弟我知識淺薄,說到 cross-compile 大概只想到置換環境變數 $(CC) 或是改改 header 檔案,結果遇到 npm install 一時之間還真的不知道要怎麼指定 toolchain 囧!後來翻到了 node-sqlite3 說明中有教你怎麼樣編譯到別的平台上。

我自己的做法

首先要具備 node-gyp 並安裝到全域 npm install node-gyp -g

再來就是 npm install sqlite3 --build-from-source --target_arch=arm

注意
這個 --build-from-source 非常重要,如果你的 toolchain 是自備的一定要加上這個 flag 要不然他會很好心的幫你直接下載 arm 版本的 binary,而達不到你要的效果(cross-compile)

另外,node-sqlite3是有套件相依性的…apt-get install libsqlite3 可以輕鬆解決

如果想查看他有相依那些 lib 的話不妨來一下 ldd 唄!

npm install 錯誤在虛擬機共享資料夾

發表於 6月 7 2014 | 0 Comments

今天更新 Blog 產生器 HEXO 時發現我要安裝 NPM 套件時會發生很詭異的錯誤…

TL;DR

使用虛擬機分享資料夾,例如我是用 VirtualBox 分享 windows 資料夾給 Debian。系統在建立 Symlink 的時候會有問題。

以下是錯誤訊息

npm ERR! error rolling back Error: ETXTBSY, unlink '/media/sf_project/imZack.github.io/node_modul
es/hexo-renderer-marked/node_modules/lodash/lodash.js'
npm ERR! error rolling back [email protected] { [Error: ETXTBSY, unlink '/media/sf_proj
ect/imZack.github.io/node_modules/hexo-renderer-marked/node_modules/lodash/lodash.js']
npm ERR! error rolling back errno: 62,
npm ERR! error rolling back code: 'ETXTBSY',
npm ERR! error rolling back path: '/media/sf_project/imZack.github.io/node_modules/hexo-rendere
r-marked/node_modules/lodash/lodash.js' }
npm ERR! Error: EROFS, symlink '../marked/bin/marked'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! <http://github.com/npm/npm/issues>

npm ERR! System Linux 3.2.0-4-amd64
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! cwd /media/sf_project/imZack.github.io
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! path ../marked/bin/marked
npm ERR! code EROFS
npm ERR! errno 56

丟上去 google,嗯!我不是孤單的…簡單的抓了一個答案來看得到的結果是:npm install 後面加入參數 --no-bin-link

依據 npm 官方文件表示:

The –no-bin-links argument will prevent npm from creating symlinks for any binaries the package might contain.

也就是說避免 npm 去幫你產生 symlinks,這時我才忽然想起我的環境是 windows 資料夾透過 virtualbox 的 shared folder 分享到 debian 難怪不能用 symlinks…

這裡似乎有一篇解法,將 virtual box 跑在 administrator 下然後在 VM 內設定下面參數

VBoxManage setextradata YOURVMNAME VBoxInternal2/
SharedFoldersEnableSymlinksCreate/YOURSHAREFOLDERNAME 1

不過我後來還是將這部分回到 windows 上面完成…哈

參考資料

Nodejs + npm, installing modules on ntfs partition

“Error: ETXTBSY” when installing the package with npm (gruntjs, gulp) at VirtualBox

NPM, Vagrant and Symlinks on Windows

利用 sshpass 幫你輸入 ssh 密碼

發表於 5月 29 2014 | 0 Comments

最近公司在測產品的時候常常要使用 scp 傳檔案到機器(target)上

每次都要輸入密碼,實在是很惱人阿~ 好險有 sshpass 讓你沒煩惱

只要輸入

sshpass -p your_password scp file [email protected]:/home

就可以不用輸入密碼把檔案傳到遠端啦!

如何安裝?

Ubuntu & Debian

apt-get install sshpass

sshpass: http://www.cyberciti.biz/faq/noninteractive-shell-script-ssh-password-provider/
install: https://gist.github.com/arunoda/7790979

1…567

YuLun Shih

70 文章
6 分類
127 標籤
RSS
GitHub E-Mail Twitter
© 2017 YuLun Shih