Skip to content

Instantly share code, notes, and snippets.

View ixqbar's full-sized avatar
💭
I may be slow to respond.

Well ixqbar

💭
I may be slow to respond.
View GitHub Profile
@ixqbar
ixqbar / gist:fbba7a6136b725b7eec8
Created October 21, 2015 09:23
redis optimize
echo 1 > /proc/sys/vm/overcommit_memory
echo never > /sys/kernel/mm/transparent_hugepage/enabled
@ixqbar
ixqbar / gist:2c62feaeae02c943eaee
Created October 28, 2015 02:13
扩容数组的长度都会变为2的整次幂
//java
static int tableSizeFor(int cap) {
int n = cap - 1;
n |= n >>> 1;
n |= n >>> 2;
n |= n >>> 4;
n |= n >>> 8;
n |= n >>> 16;
return (n < 0) ? 1 : n + 1;
}
static char * string_trim (char *s) {
char *p;
/* skip leading white spaces */
while (*s && isspace (*s))
++s;
/* trim trailing white spaces */
p = s + strlen (s) - 1;
while (isspace (*p))
NSString *string = @"我123";
const char *inStr = [string UTF8String];
unsigned char result[MD5_DIGEST_LENGTH];
NSMutableString *outStr = [NSMutableString string];
MD5((unsigned char *)inStr, strlen(inStr), result);
unsigned int i;
for (i = 0; i < MD5_DIGEST_LENGTH; i++){
[outStr appendFormat:@"%02x", result[i]];
}
NSLog(@"input string:%@" ,string);
@ixqbar
ixqbar / gist:d61ce405af4e73e631c2
Last active November 19, 2015 10:39
openssl aes
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/aes.h>
int main(int argc, char** argv) {
AES_KEY aes;
unsigned char key[AES_BLOCK_SIZE]; // AES_BLOCK_SIZE = 16
unsigned char iv[AES_BLOCK_SIZE]; // init vector
unsigned char* input_string;
@ixqbar
ixqbar / linux-uuid.md
Last active December 16, 2015 03:01
uuid
yum install libuuid-devel
/**
 *  gcc -o uuid uuid.c -luuid
 */
@ixqbar
ixqbar / objc-aes.md
Last active December 16, 2015 03:00
objc aes
//
//gcc -std=c99 crypto.m -framework Foundation
//
//

#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonCryptor.h>
@ixqbar
ixqbar / objc-zlib.md
Last active December 16, 2015 03:01
objc zlib for php gzcompress gzuncompress

NSData+Zlib.h

#import 

@interface NSData (Zlib)
- (id)deflate:(int)compressionLevel;
- (id)inflate;
@end
@ixqbar
ixqbar / objc-md5.md
Created December 16, 2015 03:12
objc-md5
#import <CommonCrypto/CommonDigest.h>

NSString *md5_str = @"1234567890";
const char *cStr = [md5_str UTF8String];
unsigned char digest[CC_MD5_DIGEST_LENGTH];
CC_MD5(cStr, (CC_LONG)strlen(cStr), digest);

NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
@ixqbar
ixqbar / get_mac.md
Last active December 24, 2015 08:07
获取linux系统macaddress
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
 
int main(int argc, char **argv) {