Skip to content

Instantly share code, notes, and snippets.

Shuntaro Yada shuntaroy

View GitHub Profile
@shuntaroy
shuntaroy / rest.py
Last active Dec 2, 2018
Assume keys are stored into environment variables
View rest.py
import os
import tweepy
consumer_key = os.environ['TWITTER_CONSUMER_KEY']
consumer_secret = os.environ['TWITTER_CONSUMER_SECRET']
access_token = os.environ['TWITTER_ACCESS_TOKEN']
access_token_secret = os.environ['TWITTER_ACCESS_TOKEN_SECRET']
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
@shuntaroy
shuntaroy / agg_ifnull_cond.js
Last active Jul 8, 2018
an example of tweet json
View agg_ifnull_cond.js
db.collection.aggregate([
{$project: {
_id:0,
account: "$user.screen_name",
tid: "$id",
text: {$ifNull: ["$retweeted_status.text", "$text"]},
date: "$created_at",
RT: {$cond: [
{$not: ["$retweeted_status"]},
false,
View useful.sh
!cmd # = the latest exec starting with ``cmd``
!! # = !-1, previously used command
!$ # = !:-1, previouly used argument
!$:r # = real name
!$:e # = extension
!^:h # = parent dir
!^:t # = file name
!^ # = !:1
^ptn^rpl^ # = s/ptn/rpl/
:gs/ptn/rpl/
@shuntaroy
shuntaroy / cleveref_ja.sty
Created Dec 31, 2015
\cref{labelname}とすると自動で「第1章」などとしてくれる cleveref パッケージを日本語化するスタイルファイル見本です。
View cleveref_ja.sty
\usepackage[noabbrev]{cleveref}
\crefformat{chapter}{第#2#1#3章}
\crefformat{section}{#2#1#3節}
\crefformat{subsection}{#2#1#3項}
\crefname{figure}{図}{図}
\crefname{table}{表}{表}
\crefname{equation}{式}{式}
\crefname{appendix}{付録}{付録}
@shuntaroy
shuntaroy / Open in iTerm2-nightly
Last active Nov 1, 2017 — forked from eric-hu/Open iterm tab here
Apple script to open an iterm2 "nightly" window from right-clicking on a file or folder in Finder. To use:(1) Open Automator(2) Create a new service(3) Change "Service receives selected" drop downs to "Files or folders" in "Finder"(4) Select "Run applescript" from the sidebar, then paste this script in and save
View Open in iTerm2-nightly
-- Adapted from these sources:
-- http://peterdowns.com/posts/open-iterm-finder-service.html
-- https://gist.github.com/cowboy/905546
--
-- Modified to work with files as well, cd-ing to their container folder
on run {input, parameters}
tell application "Finder"
set my_file to first item of input
set filetype to (kind of (info for my_file))
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer:
View otf-up-yu-elcapitan.sty
% prefer to use with \usepackage[bold]{otf}
\AtBeginDvi{\special{pdf:mapline uphminr-h UniYuMin-UTF16-H :0:YuMincho.ttc}}
\AtBeginDvi{\special{pdf:mapline uphminr-v UniYuMin-UTF16-V :0:YuMincho.ttc}}
\AtBeginDvi{\special{pdf:mapline uphminb-h UniYuMin-UTF16-H :1:YuMincho.ttc}}
\AtBeginDvi{\special{pdf:mapline uphminb-v UniYuMin-UTF16-V :1:YuMincho.ttc}}
\AtBeginDvi{\special{pdf:mapline uphgothr-h UniJIS2004-UTF16-H YuGo-Medium.otf}}
\AtBeginDvi{\special{pdf:mapline uphgothr-v UniJIS2004-UTF16-V YuGo-Medium.otf}}
\AtBeginDvi{\special{pdf:mapline uphgothb-h UniJIS2004-UTF16-H YuGo-Bold.otf}}
\AtBeginDvi{\special{pdf:mapline uphgothb-v UniJIS2004-UTF16-V YuGo-Bold.otf}}
@shuntaroy
shuntaroy / Rakefile
Last active Aug 29, 2015
Make symlinks of .tex and .pdf in local folder into ~/Dropbox/LaTeX with the same directory tree as the local folder.
View Rakefile
# Rakefile of TeXdocuments symlink
require "rake/clean"
CURRENT = Dir.pwd + '/'
DROPBOX = Dir.home + '/Dropbox/LaTeX/'
TARGETS = FileList['**/*.pdf', '**/*.tex']
GENERATE_DIRS = TARGETS.map { |p| DROPBOX + File.dirname(p)}.uniq.sort
GENERATED = FileList[DROPBOX + '**/*.pdf', DROPBOX + '**/*.tex']
CLEAN.include(GENERATED)
@shuntaroy
shuntaroy / Private.xml
Last active Aug 29, 2015
Private.xml for Karabiner to toggle mozc_input on Sublime Text (Mac)
View Private.xml
<?xml version="1.0"?>
<root>
<appdef>
<appname>SUBLIMETEXT</appname>
<equal>com.sublimetext.3</equal>
<!-- If you use Sublime Text 2, you should change above '3' into '2' -->
</appdef>
<item>
<name>Command_LR to toggle_mozc on SublimeText3</name>
<identifier>test</identifier>
@shuntaroy
shuntaroy / Private.xml
Created Jul 27, 2014
HHKB Pro2 key modifying setting for Karabiner (https://pqrs.org/osx/karabiner/index.html.ja) App. Only applied when HHKB Pro2 connected.
View Private.xml
<?xml version="1.0"?>
<root>
<devicevendordef>
<vendorname>PFU</vendorname>
<vendorid>0x0853</vendorid>
</devicevendordef>
<deviceproductdef>
<productname>HHKB</productname>
<productid>0x0100</productid>
You can’t perform that action at this time.