Skip to content

Instantly share code, notes, and snippets.

View FlyingRadish's full-sized avatar
🏠
Working from home

will FlyingRadish

🏠
Working from home
  • Guangxi, China
View GitHub Profile
@FlyingRadish
FlyingRadish / WrapCollectionView.m
Created January 11, 2018 13:53
A UICollectionView which would wrap its content
@interface WrapCollectionView : UICollectionView
@end
@implementation WrapCollectionView
- (void) layoutSubviews
{
[super layoutSubviews];
if (!CGSizeEqualToSize(self.bounds.size, [self intrinsicContentSize]))
public class VersionComparator implements Comparator<String> {
@Override
public int compare(String lhs, String rhs) {
lhs = lhs.replaceAll("[^0-9.]", "");
rhs = rhs.replaceAll("[^0-9.]", "");
Scanner leftVersionScanner = new Scanner(lhs);
Scanner rightVersionScanner = new Scanner(rhs);
leftVersionScanner.useDelimiter("\\.");
public static int dp2px(Context ctx, float dp) {
final float scale = ctx.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
public static int px2dp(Context ctx, float px) {
final float scale = ctx.getResources().getDisplayMetrics().density;
return (int) (px / scale + 0.5f);
}
@FlyingRadish
FlyingRadish / Replacer.java
Created November 9, 2016 17:34
Find all specified segment from a string, then pass the key to a method and replace with the output.
public static String replace(String content, String tagExp, String targetExp, Replacer replacer) {
Pattern tagPattern = Pattern.compile(tagExp);
Pattern targetPattern = Pattern.compile(targetExp);
Matcher tagMather = tagPattern.matcher(content);
StringBuilder contentBuilder = new StringBuilder(content);
int offset = 0;
while (tagMather.find()) {
String tag = tagMather.group();
Matcher targetMatcher = targetPattern.matcher(tag);
if (!targetMatcher.find()) {