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 / gist:3877861
Created October 12, 2012 07:56
Extends full screen image from iPhone 3.5 inch to iPhone 4 inch by using head part as texture via Qt
#include <QApplication>
#include <QImage>
#include <QPainter>
void extend2iPhone5(const QString &filename){
QImage image(filename);
QImage out(640, 1136, QImage::Format_ARGB32);
// 640x1136 is iPhone 5 (4 inches)'s screen resolution
@Moligaloo
Moligaloo / getOnlineDeb.sh
Created November 8, 2012 06:01
Download latest online deb file of Baidu input method
#!/bin/sh
# This script is used to get the online version's deb in the current folder
host="mi.baidu.com"
filename=$(curl --silent "$host/Packages" | grep --only-matching 'debs/baidu_input.*deb')
echo "I'm going to download $host/$filename"
wget "$host/$filename"
@Moligaloo
Moligaloo / PrintStructureOfUIView.m
Last active October 13, 2015 15:07
Print the structure of a UIView
static inline const char *GetClassNameCString(id obj){
NSString *className = NSStringFromClass([obj class]);
return [className UTF8String];
}
static void PrintSubviewToFile(UIView *view, int level, FILE *fp){
for(int i=0; i<level; i++){
fputc('-', fp);
}
@Moligaloo
Moligaloo / PlaySoundFromMemory.c
Created December 10, 2012 17:11
Play sound from memory by FMOD
// assume buffer is the sound file content
FMOD_SOUND *sound;
FMOD_CREATESOUNDEXINFO info;
memset(&info, 0, sizeof(info));
info.cbsize = sizeof(info);
info.length = size;
@Moligaloo
Moligaloo / PlaySoundFromMemory.c
Created December 10, 2012 17:12
Play sound from memory by FMOD
// assume buffer is the sound file content
FMOD_SOUND *sound;
FMOD_CREATESOUNDEXINFO info;
memset(&info, 0, sizeof(info));
info.cbsize = sizeof(info);
info.length = size;
@Moligaloo
Moligaloo / qStableSortDemo.cpp
Last active December 11, 2015 11:28
Apply a functor to qStableSort (a Qt template function to do stable sort)
#include <QCoreApplication>
#include <QStringList>
#include <QtDebug>
class CompanyComparator{
public:
CompanyComparator(bool ascend){
ascend_ = ascend;
}
@Moligaloo
Moligaloo / RevertPngCrush.py
Created January 30, 2013 08:29
Revert png files that are compressed by Apple's pngcrush tool, the original code is from http://axelbrz.com.ar/?mod=iphone-png-images-normalizer
#---
# iPIN - iPhone PNG Images Normalizer v1.0
# Copyright (C) 2007
#
# Author:
# Axel E. Brzostowski
# http://www.axelbrz.com.ar/
# axelbrz@gmail.com
#
# References:
@Moligaloo
Moligaloo / plutil.pl
Created January 30, 2013 08:32
Convert Apple's property list file between binary format and XML format
# plutil.pl 1.6 - implementation of binary/UTF-8 (text) XML conversion of plist files
# does not (yet) support OS X plutil command line syntax
# 1.0 - first public release
# 1.1 - added support for date Type 3; fixed real Type 2
# 1.2 - fixed handling of empty arrays
# 1.3 - fixed handling of large strings and empty keys
# 1.4 - write utf8 in XML, convert as necessary on read
# 1.5 - read/write 8 byte integers and negative integers; handle special XML chars in dictionary keys
# - now requires Math::BigInt
@Moligaloo
Moligaloo / luajson.cpp
Last active December 14, 2015 18:59
Bind C++ library jsonbox to Lua
#include "JsonBox.h"
#include "lualib/lua.hpp"
#include <sstream>
static JsonBox::Value LuaValueToJsonValue(lua_State *L);
static JsonBox::Value LuaTableToJsonValue(lua_State *L){
luaL_checktype(L, -1, LUA_TTABLE);
const static int key_index = -2;
@Moligaloo
Moligaloo / rm2tiled.cpp
Last active December 18, 2015 10:49
Convert RPG Maker VX Ace's tilesets to Tiled compatible tilesets
void Converter::convert(const QString &input, const QString &output){
QList<int> list;
QString str="8 9 10 9 10 11 "
"12 13 14 13 14 15 "
"16 17 18 17 18 19 "
"12 13 14 13 14 15 "
"16 17 18 17 18 19 "
"20 21 22 21 22 23 "
"0 9 10 1 -1 -1 "