Skip to content

Instantly share code, notes, and snippets.

View zwang's full-sized avatar
😀
Plato App

Zhao Wang zwang

😀
Plato App
View GitHub Profile
@zwang
zwang / remove .svn
Created July 8, 2012 19:57
Quickly Remove all the .svn folders recursively in a Mac OS X System
find ./ -name ".svn" | xargs rm -Rf
@zwang
zwang / MonoError.xml
Created July 24, 2012 04:58
When exit Mono Develop, this error pop up. It only pops up if I did copy and paste text inside Mono Develop
System.NullReferenceException: Object reference not set to an instance of an object
at Mono.TextEditor.Utils.RtfWriter.GenerateRtf (Mono.TextEditor.TextDocument doc, ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options) [0x00061] in /Users/builder/data/lanes/monodevelop-mac-monodevelop-3.0.3-branch/57eb8135/source/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor.Utils/RtfWriter.cs:71
at Mono.TextEditor.ClipboardActions+CopyOperation.SetData (Gtk.SelectionData selection_data, UInt32 info) [0x00067] in /Users/builder/data/lanes/monodevelop-mac-monodevelop-3.0.3-branch/57eb8135/source/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEditor/Actions/ClipboardActions.cs:97
at Mono.TextEditor.ClipboardActions+CopyOperation.ClipboardGetFunc (Gtk.Clipboard clipboard, Gtk.SelectionData selection_data, UInt32 info) [0x00000] in /Users/builder/data/lanes/monodevelop-mac-monodevelop-3.0.3-branch/57eb8135/source/monodevelop/main/src/core/Mono.Texteditor/Mono.TextEd
@zwang
zwang / SetupAmazonSES.cs
Created August 3, 2012 14:37
Sending email using Amazon Simple Email service
/// <summary>
/// Sending email using Amazon SES
/// </summary>
public class AmazonSES
{
private static string accessKey = your access key in string;
private static string secretKey = your access secret key;
private static string _fromEmail = "yourname@example.com";
private static int _maximumDeliveryAttempts = 3;
@zwang
zwang / SendGrid.cs
Created August 3, 2012 14:59
Some functions using Send Grid to send emails
/// <summary>
/// Functions for sending emails using SendGrid
/// </summary>
public class SendGrid
{
#region Dependency and Initialization
private static SendingEmailSetting setting;
/// <summary>
/// This need to be set up when application starts
@zwang
zwang / KeychainItemWrapper in ARC
Created August 27, 2012 04:23
Use Apple's KeychainItemWrapper in ARC project from @ErikEvenson
Thanks to ErikEvenson https://github.com/ErikEvenson
I did three things to use Apple's current sample code in my ARC projects:
1) Set -fno-objc-arc as a compiler flag on KeychainItemWrapper.m under Build Phases, Compile Sources.
2) Use __bridge_transfer in the call to the wrapper: NSString *password = [wrapper objectForKey:(__bridge_transfer id)kSecValueData];
3) Add an autorelease to line 196 of Apple's code to plug Apple's memory leak: self.keychainItemData = [[[NSMutableDictionary alloc] init] autorelease];
Another solution which rewrites the code in ARC can be found here
https://gist.github.com/1170641
@zwang
zwang / gist:5667392
Created May 29, 2013 01:36
Load a class dynamically in Java
private Class<?> clazz = null;
public MonitorResinThread(Timer timer) {
super(timer, 1);
//Make sure the class is only load once
try {
String homePath = "/Home/folder/to/jar";
File file = new File(homePath + "/lib/resin.jar");
URL url = new URL("jar", "", "file:" + file.getAbsolutePath() + "!/");
URL[] urls = new URL[] { url };
@zwang
zwang / center div.css
Last active December 19, 2015 22:09
Make the inner Div center horizontally and vertically in the outer div
<style>
#outer
{
background:red;
display:table;
width: 100%;
height:600px;
}
#inner
{
@zwang
zwang / removeTrailingSpace
Last active December 23, 2015 11:09
Remove trailing white space in Eclipse
You can easily remove all the trailing whitespace within a single file by using
a regular expression with the Find/Replace dialog. Enter [ \t]+$ in the "Find:" box
and leave the "Replace with:" box empty. Check the "Regular expressions" option
then click "Replace All"
@zwang
zwang / getLargestFactor.clj
Last active August 29, 2015 14:06
To calculate the largest prime factor of a number
(ns scratch.core)
(defn dividable? [number]
#(zero? (mod number %))
)
(defn dividableByAny? [number divList]
(> (count (filter (dividable? number) divList)) 0)
)
@zwang
zwang / write-file.clj
Created September 7, 2014 15:01
convert a file with word on each line to a json array. (pick only the first 2000 words)
(defn convert [](with-open [rdr (reader "/Users/zhaowang/workspace/clojure/labrepl/data/words")]
(doseq [line (take 2000 (line-seq rdr))]
(writeToFile (str "\"" line "\"" ",")))))
(defn writeToFile [line]
(with-open [wrtr (writer "test.json" :append true)]
(.write wrtr line)))