Skip to content

Instantly share code, notes, and snippets.

@willonboy
willonboy / absim.sh
Created February 11, 2014 02:14 — forked from 0xced/absim.sh
#!/bin/bash
cd ~/Library/Application\ Support/MobileSync/Backup
backup=`ls -t1 | sed -n '1p'` # most recent backup
for f in "$backup"/*.mdinfo; do
grep -q "Library/AddressBook/AddressBook.sqlitedb" $f
if [ $? -eq 0 ]; then
addressbook=`basename $f .mdinfo`
cp -v "`pwd`/$backup/$addressbook.mddata" ~/Library/Application\ Support/iPhone\ Simulator/User/Library/AddressBook/AddressBook.sqlitedb
exit $?
@willonboy
willonboy / EncodingDetect.java
Last active August 19, 2019 14:05
Java版自动获取文本文件使用的编码
package com.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
# -*- Encoding: utf-8 -*-
from M2Crypto.EVP import Cipher
key = 'a' * 16
text = 'Hello, there!'
cipher = Cipher(alg='des_ede_ecb', key=key, op=1, iv='\0'*16)
@willonboy
willonboy / NSArray_NSDictionary _containsObject_test
Created January 11, 2013 01:59
test NSArray/ NSDictionary containsObject: function
- (void)test
{
NSMutableDictionary *testDic = [NSMutableDictionary dictionary];
[testDic setValue:@"dic value" forKey:@"1"];
NSMutableArray *testArr = [NSMutableArray array];
[testArr addObject:[NSNumber numberWithInt:10]];
if ([testDic.allKeys containsObject:@"1"])
@willonboy
willonboy / Bridge.def
Created January 6, 2013 07:47
Bridge.def
C YES true
C NO false
C nil null
C NULL null
: applicationDidFinishLaunching: v12@0:4@8
T id @
T short s
@willonboy
willonboy / toggle_Internet_Sharing.scpt
Created July 6, 2012 09:52
toggle Internet Sharing
property bOff : true
tell application "System Preferences"
activate
end tell
tell application "System Events"
tell process "System Preferences"
click menu item "Sharing" of menu "View" of menu bar 1
tell window "Sharing"
@willonboy
willonboy / Turn_on_off_FileSharing.scpt
Created July 6, 2012 09:51
Turn on/off FileSharing
tell application "System Preferences"
activate
reveal (pane id "com.apple.preferences.sharing")
end tell
tell application "System Events" to tell table 1 of scroll area of group 1 of window 1 of process "System Preferences"
tell (1st row whose value of static text 1 is "File Sharing")
set sharingStatus to value of checkbox 1 as boolean
@willonboy
willonboy / toggle_web_proxy.scpt
Created July 6, 2012 09:50
toggle network setting web proxy
set eleDesString to ""
tell application "System Preferences"
activate
end tell
tell application "System Events"
tell process "System Preferences"
click menu item "Network" of menu "View" of menu bar 1
click button "Advanced…" of window "Network"
// Reads in a set of raw data files, and outputs smoothed files. (lots of libdispatch magic)
#define SIGMA (50)
- (IBAction)smoothDataSets:(id)sender {
[openPanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger ret){
if(ret == NSOKButton){
// Apply to each file and then output appropriately.
dispatch_group_t smooth_group = dispatch_group_create();
dispatch_queue_t global_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
for(NSURL *url in [openPanel URLs]){
const char *in_path = [[url path] UTF8String];