Skip to content

Instantly share code, notes, and snippets.

View Moligaloo's full-sized avatar

Moligaloo Moligaloo

  • ByteDance
  • Shanghai, China
View GitHub Profile
@Moligaloo
Moligaloo / launchscreen.rb
Created April 27, 2016 02:01
Generate iOS launch screen images
#!/usr/bin/env ruby
require 'rmagick'
if ARGV.length < 2
puts "Usage: #{$PROGRAM_NAME} <logo path> <background color>"
exit
end
logopath = ARGV[0]
@Moligaloo
Moligaloo / disgusting-ancient-style.rb
Created April 11, 2016 10:17
Disgusting ancient style poem generator, from http://www.jianshu.com/p/f893291674ca
#!/usr/bin/env ruby
@two_chars_words = %w"朱砂 天下 杀伐 人家 韶华 风华 繁华 血染 墨染 白衣 素衣 嫁衣 倾城 孤城 空城 旧城 旧人 伊人 心疼 春风 古琴 无情 迷离 奈何 断弦 焚尽 散乱 陌路 乱世 笑靥 浅笑 明眸 轻叹 烟火 一生 三生 浮生 桃花 梨花 落花 烟花 离殇 情殇 爱殇 剑殇 灼伤 仓皇 匆忙 陌上 清商 焚香 墨香 微凉 断肠 痴狂 凄凉 黄梁 未央 成双 无恙 虚妄 凝霜 洛阳 长安 江南 忘川 千年 纸伞 烟雨 回眸 公子 红尘 红颜 红衣 红豆 红线 青丝 青史 青冢 白发 白首 白骨 黄土 黄泉 碧落 紫陌"
@four_chars_words = %w"情深缘浅 情深不寿 莫失莫忘 阴阳相隔 如花美眷 似水流年 眉目如画 曲终人散 繁华落尽 不诉离殇 一世长安"
@sentence_model = %w"xx,xx,xx了xx。 xxxx,xxxx,不过是一场xxxx。 你说xxxx,我说xxxx,最后不过xxxx。 xx,xx,许我一场xxxx。 一x一x一xx,半x半x半xx。 你说xxxxxxxx,后来xxxxxxxx。 xxxx,xxxx,终不敌xxxx。"
def get_sentence
model = @sentence_model.sample(1)[0].clone
while model.include?'xxxx'
model.sub!(/xxxx/, @four_chars_words.sample(1)[0])
@Moligaloo
Moligaloo / c-chain-invocation.c
Last active January 31, 2016 05:51
Chain invocation in C programming language
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
// MyJIT homepage: http://myjit.sourceforge.net/index.htm
#include "myjit/jitlib.h"
struct string_builder{
GString *gstring;
@Moligaloo
Moligaloo / HelpfulBreakpoints.m
Created January 9, 2016 03:32
help iOS developer to breakpoint when NSDictionary construction failed because of nil object
#import <objc/runtime.h>
#import <objc/message.h>
// copied from http://stackoverflow.com/questions/17346046/advice-on-how-to-catch-attempt-to-insert-nil-object-from-a-device-needed
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
static id safe_initWithObjects(id self, SEL _cmd, const id objects[], const id <NSCopying> keys[], NSUInteger count) {
id orignialResult = nil;
@Moligaloo
Moligaloo / json2msgpack.rb
Created December 2, 2015 13:07
Convert JSON source file to MessagePack file
#!/usr/bin/env ruby
require 'json'
require 'msgpack'
if ARGV.length < 2
puts "#{$PROGRAM_NAME} <json file> <msgpack file>"
exit 1
end
@Moligaloo
Moligaloo / json_pretty.rb
Last active June 20, 2018 09:56
Pretty reformat of JSON file
#!/usr/bin/env ruby
json_file = ARGV[0]
if json_file == nil
puts "Usage: #{$PROGRAM_NAME} <json file> [out_file]"
exit
end
require 'json'
@Moligaloo
Moligaloo / plist2json.rb
Created November 27, 2015 08:08
Convert plist file to json file using Ruby
#!/usr/bin/env ruby
if ARGV.length < 2
puts "Usage: #{$PROGRAM_NAME} <plist_file> <json_file>"
exit 1
end
plist_file = ARGV[0]
json_file = ARGV[1]
@Moligaloo
Moligaloo / unicode2utf8.rb
Created August 22, 2015 08:47
Convert two byte Unicode to UTF-8
#!/usr/bin/env ruby
# https://en.wikipedia.org/wiki/UTF-8
def unicode2utf8(str)
num = str.to_i(16)
c1 = 0xE0 + ((num & 0xF000) >> 12)
c2 = 0b10000000 + ((num & 0x0FC0) >> 6)
c3 = 0b10000000 + (num & 0x003F)
@Moligaloo
Moligaloo / jQueryLoad.js
Created July 20, 2015 07:34
Load jQuery from Chrome Web Inspector
javascript:if(!window.jQuery||confirm('Overwrite\x20current\x20version?\x20v'+jQuery.fn.jquery))(function(d,s){s=d.createElement('script');s.src='https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.js';(d.head||d.documentElement).appendChild(s)})(document);
@Moligaloo
Moligaloo / func2hex.lua
Created July 19, 2015 14:01
Convert lua function to hexadecimal string format and back
function func2hex(func)
return (string.dump(func):gsub(".", function(c) return ("%02X"):format(c:byte()) end));
end
function hex2func(hex)
return loadstring(hex:gsub("..", function(x) return string.char(tonumber(x, 16)) end))
end