Skip to content

Instantly share code, notes, and snippets.

@richard1122
richard1122 / svgToPNG.sh
Last active August 29, 2015 14:05
Convert some svg into png by inkscape
for line in `find . -iname '*.svg';`
do
for dpi in 90 180 360 720
do
inkscape -z -f "${line}" --export-png="png/${line}_${dpi}.png" -d "${dpi}"
done
done
@richard1122
richard1122 / nsd.java
Last active April 5, 2023 08:00
A simple example for Android NSD(network service discovery) and server socket
package com.richard1993.android.inputhack;
import android.app.Service;
import android.content.Intent;
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
import android.os.IBinder;
import android.util.Log;
import java.io.BufferedInputStream;
@richard1122
richard1122 / gets_between.php
Created October 5, 2014 12:21
gets_between
/*
This function split a string into multi part, each part start with(exclude) $start and end with(exclude) $end.
$end is optional.
Thanks @zenozeng for backend code at QSC mobile. (function get_between)
*/
function gets_between($start, $end, $content) {
$r = explode($start, $content);
$arr = array();
@richard1122
richard1122 / openmp_pi.cpp
Created January 2, 2015 17:11
OpenMP for PI calculation test
#include <iostream>
#include <omp.h>
#include <ctime>
using namespace std;
#define N 3000000000L
int main() {
omp_set_num_threads(8);
@richard1122
richard1122 / TransprentHTTPGzipedStreamReader.java
Last active August 29, 2015 14:19
Android HTTPURLConnection auto read gzip inputStream
public static String networkInputstreamtoString(InputStream is) throws IOException {
byte []sig = new byte[2];
final PushbackInputStream pb = new PushbackInputStream(is, sig.length);
pb.read(sig);
pb.unread(sig);
if (sig[0] == (byte) 0x1f && sig[1] == (byte) 0x8b) {
is = new GZIPInputStream(pb);
} else {
is = new BufferedInputStream(pb);
}
@richard1122
richard1122 / DPToPX.java
Last active August 29, 2015 14:23
Android snippet
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, mContext.getResources().getDisplayMetrics());
@richard1122
richard1122 / TL.d.ts
Last active November 20, 2016 07:51
telegram typings
// A typings definition of some telegram data structure
// author: Richard He<richard9372@gmail.com>
// https://gist.github.com/richard1122/1eb54cd4e422aeb707718ab307decd34
// see more detail: https://core.telegram.org/bots/api
declare namespace TL {
export interface IResponse<T> {
ok:boolean
result:T
}
@richard1122
richard1122 / idea.xml
Created May 17, 2018 09:27
intellij code style
<code_scheme name="Default" version="173">
<HTMLCodeStyleSettings>
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
</HTMLCodeStyleSettings>
<JSCodeStyleSettings>
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
@richard1122
richard1122 / v2ex.css
Created November 19, 2018 05:14
stylish
#Main > .box tr > td:first-child {
width: 0;
}
@richard1122
richard1122 / assertj-kotlin.postfixTemplates
Created January 29, 2019 04:24
custom intellij postfix template
.assertJ : AssertJ
ANY → org.assertj.core.api.Assertions.assertThat($expr$)
.isEqualTo: AssertJ And isEqualTo
ANY → org.assertj.core.api.Assertions.assertThat($expr$).isEqualTo($END$)
.isZero: AssertJ And isZero
ANY → org.assertj.core.api.Assertions.assertThat($expr$).isZero()
.isCloseTo: AssertJ And isCloseTo
ANY → org.assertj.core.api.Assertions.assertThat($expr$).isCloseTo($value#1$, Percentage.withPercentage(.1))$END$
.isTrue: AssertJ And isTrue
ANY → org.assertj.core.api.Assertions.assertThat($expr$).isTrue()