Skip to content

Instantly share code, notes, and snippets.

View Arthraim's full-sized avatar
💡
Padawan

Arthur Wang Arthraim

💡
Padawan
View GitHub Profile
@Arthraim
Arthraim / JSONParser.swift
Created November 24, 2020 08:38
Incomplete JSON parser in Swift
let JSON_COMMA = ","
let JSON_COLON = ":"
let JSON_LEFTBRACKET = "["
let JSON_RIGHTBRACKET = "]"
let JSON_LEFTBRACE = "{"
let JSON_RIGHTBRACE = "}"
let JSON_QUOTE = "\""
let JSON_WHITESPACES: [String] = [" ", "\t", "\n", "\r"]
let JSON_SYNTAX: [String] = [JSON_COMMA, JSON_COLON,
@Arthraim
Arthraim / new_tab_dribbble.css
Created June 15, 2018 02:40
User style of dribbble to make eyes easier
.attribution.hover-card-parent {
display: none;
}
.tools.group {
display: none;
}
.extras {
display: none;
}
.dribbbles {
@Arthraim
Arthraim / redux.swift
Last active January 23, 2018 03:09
An extremely easy implementation of redux in Swift 4
//: An extremely easy implementation of redux in Swift 4
// !!!!
// THIS IMPLEMENTATION HAS BEEN MOVED TO https://github.com/Arthraim/redux.swift
// !!!!
typealias Reducer<S, A> = (_ state: S, _ action: A) -> S
typealias Listener = () -> Void
class Store<S, A> {

Keybase proof

I hereby claim:

  • I am arthraim on github.
  • I am arthurwxy (https://keybase.io/arthurwxy) on keybase.
  • I have a public key ASDzdcG3WrWCSwZw_MKETFLenwyM6AGcVXEiPErXfo7Zygo

To claim this, I am signing this object:

@Arthraim
Arthraim / hairline.m
Last active October 29, 2018 07:40
Hairline of iOS
/**
* Width of hairline (1px on real device screen)
* The dppx of screens can be found here http://dpi.lv/
*
* @return CGFloat number to be set for "1px"
*/
+ (CGFloat)hairLineWidth {
if ([UIScreen mainScreen].bounds.size.width == 414.f) { // Plus
return 1.f / 2.46f; // 2.46 is the dppx of plus screens
} else {
@Arthraim
Arthraim / tryable_dictionary.md
Last active August 29, 2015 14:23
Tryable NSDictionary

Can I do something like this?

@implementation NSObject (Tryable)

- (id)tryWithKey:(id)key {
    if (!self) return [NSNull null];
    if (![self isKindOfClass:NSDictionary.class]) return [NSNull null];
    if (![(NSDictionary *)self objectForKey:key]
        || [(NSDictionary *)self objectForKey:key] == [NSNull null]) {
 return [NSNull null];
@Arthraim
Arthraim / resample_image.m
Last active August 29, 2015 14:10
Resampling Image with GUIImage
+ (UIImage *)compressForUpload:(UIImage *)original
{
// Calculate new size given scale factor.
CGSize originalSize = original.size;
CGFloat longerBorder = MAX(originalSize.width, originalSize.height);
CGFloat scale = longerBorder > MAX_DISTANCE_OF_LONGER_EDGE ? longerBorder / MAX_DISTANCE_OF_LONGER_EDGE : 1;
CGSize newSize = CGSizeMake(originalSize.width / scale, originalSize.height / scale);
GPUImageLanczosResamplingFilter *resampleFilter = [[GPUImageLanczosResamplingFilter alloc] init];
[resampleFilter forceProcessingAtSize:newSize];
@Arthraim
Arthraim / pnd.coffee
Created August 6, 2014 03:34
puzzle and dragon hubot script
# Description:
# Get pnd monsters information by number
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
@Arthraim
Arthraim / unicom.py
Created January 21, 2014 07:03
我只是想看看用哪个联通套餐最便宜
# coding:utf-8
def calc(p_count, p_price, m_count, m_price, w_count, w_price, t_p_count, t_m_count, t_w_count, t_price):
"""计算各套餐价格
p_count -- 通话时间(分钟)
p_price -- 通话价格
m_count -- 短信(条)
m_price -- 短信价格
w_count -- 流量(mb)
w_price -- 流量价格
t_p_count -- 套餐内通话时间
@Arthraim
Arthraim / black_n_red.py
Created July 29, 2013 08:54
第一次做出广搜好吗!
#coding: utf-8
# http://acm.hdu.edu.cn/showproblem.php?pid=1312
while True:
queue = []
#input W and H
WnH = raw_input()
width = int(WnH.split(' ')[0])
height = int(WnH.split(' ')[1])