Skip to content

Instantly share code, notes, and snippets.

View BramYeh's full-sized avatar

Bram Yeh BramYeh

View GitHub Profile
@BramYeh
BramYeh / icon-gen.sh
Created August 4, 2016 22:58 — forked from amulyakhare/icon-gen.sh
Bash script to update the application icon of our internal release builds to include a visual marker and version number on the icon for convenience of the testers.
#!/bin/bash
# $> bash icon-gen.sh <version label> <project dir> <script sub-dir>
#
#
# process_icon version_num res_sub_dir current_work_dir target_dir
process_icon(){
image_width=`identify -format %[fx:w] $3/app/src/main/res/drawable-$2/com_garena_shopee_logo_shopee_launcher.png` && let "image_width-=4"
image_height=`identify -format %[fx:h] $3/app/src/main/res/drawable-$2/com_garena_shopee_logo_shopee_launcher.png` && let "image_height-=4"
convert $3$4/marker.png -background '#0000' -fill white -gravity south -size 137x16 caption:$1 -composite -resize $image_widthx$image_height $3$4/intermediate.png
convert -composite -gravity center $3/app/src/main/res/drawable-$2/com_garena_shopee_logo_shopee_launcher.png $3$4/intermediate.png $3$4/com_garena_shopee_logo_shopee_launcher.png
@BramYeh
BramYeh / LowercaseEnumTypeAdapterFactory
Created March 28, 2017 13:11
LowercaseEnumTypeAdapterFactory
public class LowercaseEnumTypeAdapterFactory implements TypeAdapterFactory {
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<T> rawType = (Class<T>) type.getRawType();
if (!rawType.isEnum()) {
return null;
}
final Map<String, T> lowercaseToConstant = new HashMap<String, T>();
for (T constant : rawType.getEnumConstants()) {
lowercaseToConstant.put(toLowercase(constant), constant);
@BramYeh
BramYeh / WKWebView_Add_UserScript
Last active March 29, 2017 12:03
Use a user script that injects cookies
WKUserScript *userScript = [[WKUserScript alloc] initWithSource:@"document.cookie = 'CookieKey=CookieValue';"
injectionTime:WKUserScriptInjectionTimeAtDocumentStart
forMainFrameOnly:NO];
WKUserContentController *userContentController = [[WKUserContentController alloc] init];
[userContentController addUserScript:userScript];
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.userContentController = userContentController;
@BramYeh
BramYeh / WKNavigationDelegate_Add_JavaScript
Last active March 29, 2017 12:06
Use JavaScript that injects cookies
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
[webView evaluateJavaScript:@"document.cookie ='CookieKey=CookieValue'" completionHandler:nil];
}
@BramYeh
BramYeh / WKWebview_Update_Request
Created March 29, 2017 12:23
Add cookies into request that webview loads requests
// assume request is original request you want wkwebview to load
NSMutableURLRequest *mutableRequest = [request mutableCopy];
[mutableRequest setValue:"CookieKey = CookieValue" forHTTPHeaderField:@"Cookie"];
// navigates to a requested URL
[self.webView loadRequest:mutableRequest];
@BramYeh
BramYeh / swipe-operation-handler
Created April 29, 2017 19:35
sample: make existed cells support swipe-operation
- (void)containerViewPanGestureRecognized:(UIPanGestureRecognizer *)gestureRecognizer
{
switch (gestureRecognizer.state) {
case UIGestureRecognizerStateBegan: {
self.originalLocation = [gestureRecognizer locationInView:self.contentView];
break;
}
case UIGestureRecognizerStateChanged: {
CGFloat newX = [gestureRecognizer locationInView:self].x - self.originalLocation.x;
@BramYeh
BramYeh / Bclass.java
Last active July 6, 2017 14:38
Sample for Bclass
Class Bclass {
static class Cclass {
}
public void methodCalledOnce() {
Cclass cclass = new Cclass();
new AsyncTask<Cclass, Void, Void>() {
@Override
protected Void doInBackground(Cclass... params) {
@BramYeh
BramYeh / Aclass.java
Last active July 6, 2017 14:45
Sample of Aclass
Class Aclass {
private void methodToOptimize() {
Bclass bclass = new Bclass();
bclass.methodCalledOnce();
}
}
@BramYeh
BramYeh / AclassOptimized.java
Last active July 7, 2017 03:53
Sample of Optimized Aclass
Class Aclass {
private void methodToOptimize() {
Cclass cclass = new Cclass();
new AsyncTask<Cclass, Void, Void>() {
@Override
protected Void doInBackground(Cclass... params) {
return null;
}
}.execute(new Cclass[]{cclass});
@BramYeh
BramYeh / CycleViewPager.java
Created August 15, 2017 05:07
CycleViewPager Example
public class CycleViewPager extends ViewPager {
public CycleViewPager(Context context) {
super(context);
}
public CycleViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}