Skip to content

Instantly share code, notes, and snippets.

@crowjdh
crowjdh / AppInfo.java
Last active August 29, 2015 14:13
Way to get app's version information
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
/**
* Created by Dongheyon Jeong on 15. 1. 20.
*
* AppInfo
* 앱의 일반적인 정보를 제공하는 클래스
*/
@crowjdh
crowjdh / Def.java
Last active August 29, 2015 14:14
Restrict integer parameter and return value.
private int mProperty;
@IntDef(value = { PROPERTY_A, PROPERTY_B })
@Retention(RetentionPolicy.SOURCE)
public @interface MyProperty {}
public void setProperty(@MyProperty int property) {
mProperty = Property;
}
public @MyProperty int getProperty() {
return mProperty;
@crowjdh
crowjdh / AppActiveStateObserver.java
Last active August 29, 2015 14:24
Observes and supplies information whether an Android app is in foreground or background.(API 14+)
package com.what.ever;
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import java.util.ArrayList;
/**
* Created by Dongheyon Jeong in ActivityLifecycleCallbacksTest on July 9th, 2015
@crowjdh
crowjdh / BuilderPatternExample.swift
Last active September 5, 2015 04:11
Simple builder pattern for Swift
import Foundation
// Usage:
//
// let car = Car(engine: "Awesome Engine", gas: 90, builder: {
// $0.hasCooler = true
// $0.hasSmartKey = true
// })
final class Car {
final class Singleton {
// MARK: - Singleton
private struct Instance {
static var dispatchToken: dispatch_once_t = 0
static var instance: Singleton?
}
public class MethodHierarchy {
// 0: dalvik.system.VMStack.getThreadStackTrace
// 1: java.lang.Thread.getStackTrace
// 2: Current method(ex. get)
// 3: Method calling current method
private static final int DEFAULT_FROM_DEPTH = 4;
public static String get() {
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
return get(DEFAULT_FROM_DEPTH, elements.length);
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
/**
* Created by Dongheyon Jeong in News Kit from Yooii Studios Co., LTD. on 15. 3. 11.
package com.yooiistudios.coreutils;
import android.util.Log;
import java.lang.reflect.Array;
/**
* Created by Dongheyon Jeong in Randombox_Android from Yooii Studios Co., LTD. on 15. 7. 5.
* <br/><br/>
* HashCodeUtils<br/>
@crowjdh
crowjdh / FFmpegWithHTTPHeader.m
Created February 22, 2016 09:47
Set HTTP header information to FFmpeg avformat_open_input function in iOS
- (AVDictionary*) createAVFormatContextOptions: (NSDictionary*)dict
{
AVDictionary *options = NULL;
for (NSString* keyString in dict) {
av_dict_set(&options, [keyString UTF8String], [[dict objectForKey:keyString] UTF8String], 0);
}
return options;
}
@crowjdh
crowjdh / Stop & remove all containers in current docker machine
Last active March 24, 2018 09:55
Method to stop and remove all containers in current docker machine.
Stop:
Ubuntu:~ Me$ docker ps -a | grep 'ago' | awk '{print $1}' | xargs docker stop
Remove:
Ubuntu:~ Me$ docker ps -a | grep 'ago' | awk '{print $1}' | xargs docker rm