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 / 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 / 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 / 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 / HttpRequestDemo.cs
Created February 27, 2010 04:46
dotnet renjian api request example
using System;
using System.IO;
using System.Net;
namespace HttpRequest
{
class Program
{
static void Main(string[] args)
{
@Arthraim
Arthraim / renjian_widget.js
Created May 15, 2010 06:27
renjian web widget
/*
Author: Arthur Wang
Version: 0.5
Update: 2010/5/15
Author URI: http://arthraim.cn/
*/
function renjianCallback(statuss) {
var sData = [], sHtml = "", j = 1;
for (var i=0; i < statuss.length; i++){
if (statuss[i].in_reply_to_user_id != null) continue;
@Arthraim
Arthraim / csv_converter.py
Created September 25, 2010 15:51
transfer TianYu csv file to a nokia csv file
# 天宇csv -> nokia csv
# Arthur Wang
# REGEX: "(\w+|[^@#:\s,,,.。;;:;]+)" *
import re
p = re.compile('"(\\w+|[^@#:\\s,,,.。;;:;]+)" *')
p.sub(r"\1,", '"abc" "12312312"', 0);
# OUTPUT: 'abc,12312312,'
@Arthraim
Arthraim / getAvatars.py
Created December 17, 2010 02:36
get all avatars from renjian.com
import urllib
import simplejson
i = 0
breaki = 0
while i >= 0:
i = i + 1
print ''
rnjn_url = 'http://api.renjian.com/'
user_url = rnjn_url + 'users/show.json?id=' + unicode(i)
@Arthraim
Arthraim / ping_text.php
Created April 21, 2011 09:12
a PHP popen demo
<html>
<head>
<title>ping</title>
</head>
<body>
<?php
echo "<h1>ping</h1>";
$file_handle = popen("ping artori.us", "r");
while (!feof($file_handle)) {
$line = fgets($file_handle);
@Arthraim
Arthraim / ass2srt.awk
Created February 25, 2010 10:02
subtitle ass 2 srt
function remove_space(A,i)
{
# strip spaces on each side of A[i]
sub("^[ \t]*","",A[i])
sub("[ \t]*$","",A[i])
# remove '^M' '\n' character
gsub("[
\n]","",A[i])
}
@Arthraim
Arthraim / letterpress_king.rb
Created December 26, 2012 17:52
King of Letterpress
# find words in letters
words = ["abc", "def"] # you need a biiiiiiiiiiig word list here
letters = "pfwbsubarciesgqwjfornotyl"
results = []
words.each do |w|
dict = letters.split //
flag = true
(w.split //).each do |l|
#p dict
if (dict.include? l)