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 / main.cpp
Created July 4, 2012 19:13
Crypto++ DES encryption/decryption
#include <QtCore/QCoreApplication>
#include <crypto++/des.h>
#include <stdio.h>
// keyString 是一个密钥,必须保证长度要超过 16
// block 是要处理的数据,处理后的数据也同时存放在 block 里,必须保证它的长度为 8 的整倍数
// length 是 block 的长度,必须保证它为 8 的整倍数
// direction 是表示是否是加密还是解密,若是加密,则用 CryptoPP::ENCRYPTION, 解密用 CryptoPP::DECRYPTION
@Moligaloo
Moligaloo / client.rb
Created July 10, 2012 16:41
Simple Ruby Server & Client
require 'socket' # Sockets are in standard library
hostname = 'www.3-kingdoms.com'
port = 2000
s = TCPSocket.open(hostname, port)
while line = s.gets # Read lines from the socket
puts line.chop # And print with platform line terminator
end
@Moligaloo
Moligaloo / disableReturnKey.m
Created July 26, 2012 05:43
Disable the return key of keyboard
-(void)disableReturnKey{
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
@Moligaloo
Moligaloo / DefaultFontFallbacks.plist
Created July 26, 2012 05:57
The plist to replace default font of Mac OS X
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- default ordered fallback list - fallback entity has to be PostScript name -->
<key>default</key>
<array>
<string>LucidaGrande</string> <!-- MAKE sure this matches the kCTFontSystemFontType in CTFontDescriptorCreateForUIType() & TDescriptorSourceImp::CreateDefaultDescriptor()! -->
<string>AppleSymbolsFB</string>
<string>GeezaPro</string>
@Moligaloo
Moligaloo / fmod_play_memfile.c
Created July 30, 2012 14:17
Using fmod play files in the memory
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fmod.h>
int main(void)
{
FILE *fp = fopen("win-cc.ogg", "rb");
fseek(fp, 0, SEEK_END);
int length = ftell(fp);
@Moligaloo
Moligaloo / gist:3234222
Created August 2, 2012 05:59
Append new path to environment PATH in Fish interactive shell
# put the following code to ~/.config/fish/config.fish
set --export PATH $PATH "The path you want to append"
@Moligaloo
Moligaloo / gist:3689649
Created September 10, 2012 08:26
Get global IP in Objective-C
NSError *error;
NSURL *ipURL = [NSURL URLWithString:@"http://automation.whatismyip.com/n09230945.asp"];
NSString *ip = [NSString stringWithContentsOfURL:ipURL encoding:NSUTF8StringEncoding error:&error];
NSLog(@"IP:%@",ip);
@Moligaloo
Moligaloo / gist:3792531
Created September 27, 2012 06:36
Suppress warnings for part of source code
#pragma GCC push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
static ABAddressBookRef CreateAddressBook(){
if (ABAddressBookCreateWithOptions != NULL) {
return ABAddressBookCreateWithOptions(NULL, NULL);
}else{
return ABAddressBookCreate();
}
}
@Moligaloo
Moligaloo / gist:3850710
Created October 8, 2012 04:22
Send mail with attachment and signature via AppleScript in OS X
tell application "Mail"
set theSubject to "Subject" -- the subject
set theContent to "Content" -- the content
set theAddress to "xxx@163.com" -- the receiver
set theSignatureName to "signature_name"-- the signature name
set theAttachmentFile to "Macintosh HD:Users:moligaloo:Downloads:attachment.pdf" -- the attachment path
set msg to make new outgoing message with properties {subject: theSubject, content: theContent, visible:true}
@Moligaloo
Moligaloo / HookDemo.plist
Created October 10, 2012 09:35
Make a hook demo
Filter = {
Bundles = (com.apple.MobileSMS);
};