Skip to content

Instantly share code, notes, and snippets.

View showsky's full-sized avatar
👋
Hello World~

Ting Cheng showsky

👋
Hello World~
View GitHub Profile
<?php
function fetch_image($url, $referer)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_REFERER, $referer);
$re = curl_exec($curl);
if (curl_errno($curl))
@showsky
showsky / README.md
Created October 12, 2015 09:02
Certificate pinning
@showsky
showsky / generic.java
Last active October 21, 2015 08:18
RxJava, RxAndroid
new Thread() {
@Override
public void run() {
super.run();
for (File folder : folders) {
File[] files = folder.listFiles();
for (File file : files) {
if (file.getName().endsWith(".png")) {
final Bitmap bitmap = getBitmapFromFile(file);
getActivity().runOnUiThread(new Runnable() {
@showsky
showsky / HZip.php
Created October 26, 2015 09:28
Backup file to google drive
<?php
class HZip {
/**
* Add files and sub-directories in a folder to zip file.
* @param string $folder
* @param ZipArchive $zipFile
* @param int $exclusiveLength Number of text to be exclusived from the file path.
*/
private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
@showsky
showsky / GeneralService.h
Last active February 3, 2016 12:42
多重 delegate,有別於一般的一對一 delegate,使用 weak 避免 reference cycle。大家都不熟悉所以採用 NSNotifications
@protocol ServiceDelegate <NSObject>
@optional
- (void)generalService:(GeneralService *)service didRetrieveEntries:(NSArray *)entries;
@end
@interface GeneralService : NSObject
- (void)registerDelegate:(id<ServiceDelegate>)delegate;
@showsky
showsky / example.java
Created January 7, 2017 17:17
Android FileProvider
....
String realFileUri = new File(AppHelper.getDirectoryPath(), AppHelper.getFileName() + ".jpeg");
mMediaUri = FileProvider.getUriForFile(
getContext(),
"com.nnnnnnn.provider",
realFileUri
);
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
@showsky
showsky / cookie.m
Created September 24, 2017 14:17
cookie.m
@showsky
showsky / CustomSwiperRefreshLayout.java
Created April 20, 2018 03:05
SwiperRefreshLayout 對於水平滾動衝突
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
/**
* Created by showsky on 2018/4/18.
@showsky
showsky / LCS.php
Created August 17, 2018 08:42
LCS
<?php
class LCS {
private $str1;
private $str2;
private $c = array();
/*返回串一和串二的最长公共子序列*/
function getLCS($str1, $str2, $len1 = 0, $len2 = 0) {
$this->str1 = $str1;