Skip to content

Instantly share code, notes, and snippets.

@twocity
twocity / transcribe.kts
Created March 12, 2018 02:16
Convert an audio file to txt through Google Speech API.
#!/usr/bin/env kscript
@file:DependsOn("com.squareup.okhttp3:okhttp:3.10.0")
@file:DependsOn("com.google.code.gson:gson:2.8.2")
@file:DependsOn("commons-cli:commons-cli:1.4")
import com.google.gson.Gson
import com.google.gson.JsonParser
import okhttp3.Interceptor
import okhttp3.Interceptor.Chain
@twocity
twocity / youtube-dl-mp3.py
Created March 5, 2018 03:51
download youtube audio through youtube-dl
from subprocess import call
import sys
cmd = 'youtube-dl --extract-audio --audio-format mp3 --audio-quality 0'.split(' ')
url = sys.argv[1]
cmd.append(url)
print('running {}'.format(' '.join(cmd)))
call(cmd)
@twocity
twocity / youtube-dl-mp3.py
Created March 5, 2018 03:51
download youtube audio through youtube-dl
from subprocess import call
import sys
cmd = 'youtube-dl --extract-audio --audio-format mp3 --audio-quality 0'.split(' ')
url = sys.argv[1]
cmd.append(url)
print('running {}'.format(' '.join(cmd)))
call(cmd)
@twocity
twocity / AVIFormat.kt
Created February 6, 2018 15:35
AVI format parser
import Header.RIFF
import okio.Buffer
import okio.BufferedSource
import okio.Okio
import java.io.File
class AVIFormat private constructor(val riff: ChunkGroup) {
val chunks by lazy { riff.spread() }
@twocity
twocity / miao.gradle
Last active September 17, 2021 09:43
miao~
android.applicationVariants.all { variant ->
if (variant.install != null) {
variant.install.doLast {
exec {
commandLine "afplay", "your_sound.mp3"
}
}
}
}
@twocity
twocity / compress.py
Created September 4, 2017 14:09
compress video through ffmpeg
#!/usr/bin/env python
import sys
import subprocess
import os
from os.path import basename
file = sys.argv[1]
command = ['ffmpeg', '-y']
command.extend(['-i', file])
@twocity
twocity / ff.stable.txt
Created August 10, 2017 04:51 — forked from 2bits/ff.stable.txt
ffmpeg-0.10.2 configure options
Usage: configure [options]
Options: [defaults in brackets after descriptions]
Standard options:
--help print this message
--logfile=FILE log tests and output to FILE [config.log]
--disable-logging do not log configure debug information
--prefix=PREFIX install in PREFIX []
--bindir=DIR install binaries in DIR [PREFIX/bin]
--datadir=DIR install data files in DIR [PREFIX/share/ffmpeg]
@twocity
twocity / BaseEpoxyHolder.kt
Created June 28, 2017 03:35
EpoxyHolder' views init
abstract class BaseEpoxyHolder : EpoxyHolder() {
lateinit var itemView: View
final override fun bindView(view: View?) {
this.itemView = view!!
onBindView(itemView)
}
abstract fun onBindView(view: View)
}
@twocity
twocity / dagger2
Created December 21, 2015 10:58
dagger2
http://google.github.io/dagger/
http://fernandocejas.com/2015/04/11/tasting-dagger-2-on-android/
https://docs.google.com/document/d/1fwg-NsMKYtYxeEWe82rISIHjNrtdqonfiHgp8-PQ7m8/
https://www.youtube.com/watch?v=oK_XtfXPkqw
@twocity
twocity / RefreshTokenInterceptor.java
Last active December 18, 2015 06:52
Auto refresh token with Okhttp's interceptor
public class RefreshTokenInterceptor implements Interceptor {
@Override public Response intercept(Chain chain) throws IOException {
Request originRequest = chain.request();
Response response = chain.proceed(originRequest);
if (isTokenExpired(response)) {
Request newRequest = buildRefreshTokenRequest(originRequest);
Response refreshResponse = chain.proceed(newRequest);
if (refreshResponse.isSuccessful()) {
return chain.proceed(originRequest); // must with the new token