Skip to content

Instantly share code, notes, and snippets.

View pentiumao's full-sized avatar

Andrew Wang pentiumao

View GitHub Profile
@pentiumao
pentiumao / ZipUtils.kt
Last active December 18, 2019 15:54
Zip File System Provider
/**
* Kotlin version: 1.3.61
* JVM target: 1.8
* @param source the path to the file to copy
* @param target the path to the target file
* @param env a map of provider specific properties to configure the file system
* @see https://docs.oracle.com/javase/8/docs/technotes/guides/io/fsp/zipfilesystemprovider.html
*/
fun archive(
source: Path,
@pentiumao
pentiumao / build.gradle
Last active November 9, 2018 07:29 — forked from xian/build.gradle
Download Robolectric dependencies for hermetic build
def robolectricVersion = '4.0'
def androidSdkVersions = [
'4.1.2_r1-robolectric-0',
'4.2.2_r1.2-robolectric-0',
'4.3_r2-robolectric-0',
'4.4_r1-robolectric-1',
'5.0.0_r2-robolectric-1',
'5.1.1_r9-robolectric-1',
'6.0.1_r3-robolectric-r1',
{"sig":"e716c4b783db37d49a14456c4e7686e6d6378aa46d34be17edeeb19fc4e53911a8f89f54a59e05da2c7d2cf9e9e22c117bbb8ddd1aa396b76ca5f151de603fd40","msghash":"2be465930ccc853be00eeef5b63f0abab18bddc1c8e5e0a7cc70dbb7ceaed29a"}

Keybase proof

I hereby claim:

  • I am pentiumao on github.
  • I am pentiumao (https://keybase.io/pentiumao) on keybase.
  • I have a public key ASCJpT4iaHRadXN7NPQuOBtJI_elwjBUcyyCJa1WSFIPqQo

To claim this, I am signing this object:

@pentiumao
pentiumao / NSString+Addition.m
Last active August 29, 2015 14:22
iOS URL Encode: Unfortunately, stringByAddingPercentEscapesUsingEncoding doesn't always work 100%. It encodes non-URL characters but leaves the reserved characters (like slash / and ampersand &) alone.
- (NSString *)urlEncode {
NSMutableString *output = [NSMutableString string];
const unsigned char *source = (const unsigned char *)[self UTF8String];
int sourceLen = strlen((const char *)source);
for (int i = 0; i < sourceLen; ++i) {
const unsigned char thisChar = source[i];
if (thisChar == ' '){
[output appendString:@"+"];
} else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
(thisChar >= 'a' && thisChar <= 'z') ||
@pentiumao
pentiumao / gist:bca410767547741839d2
Created June 3, 2014 11:10
HSV to RGB conversion function
/* HSV to RGB conversion function with only integer
* math */
void
hsvtorgb(unsigned char *r, unsigned char *g, unsigned char *b, unsigned char h, unsigned char s, unsigned char v)
{
unsigned char region, fpart, p, q, t;
if(s == 0) {
/* color is grayscale */
*r = *g = *b = v;
@pentiumao
pentiumao / UILabel+Image.m
Created January 3, 2014 03:55
UIlabel with icon around it
- (void)addImage:(UIImage *)image atPoint:(CGPoint)p;
{
float width = image.size.width;
float height = image.size.height;
UIImageView *icon = [[UIImageView alloc] initWithImage:image];
icon.frame = CGRectMake(p.x, p.y, width, height);
[self addSubview:icon];
self.layer.masksToBounds = NO;
}