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 / 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)))
@zwang
zwang / tracing.clj
Created September 27, 2014 06:19
clojure marco to enable code tracing
; From Clojure: the JFDI language by Michael O. Church
; https://docs.google.com/presentation/d/16ccLdZ6Epp6Nu-lMansEErwAjbN4sau4LztaARmdl_k/edit#slide=id.g1793dde48_1508
; Motivation: runtime tracing of functions is a powerful debug technique.
; It’d require a framework to do this in Java, but in Clojure, a macro suffices!
(defmacro tracing [code]
`(do
(println "The code was: " '~code)
@zwang
zwang / eval ex.clj
Created October 2, 2014 04:05
HackerRank evaluate e^x
(dotimes [n (read-string (read-line))]
(let [x (read-string (read-line)),
ex (fn [x]
(inc
(reduce +
(map #(/ (reduce * (repeat % x))
(reduce * (range 1 (inc %)))
)
(range 1 10)
)
@zwang
zwang / SystemLog.swift
Last active August 29, 2015 14:26 — forked from kristopherjohnson/SystemLog.swift
Demo of using the Apple System Log (ASL) API from Swift
// Note: This must be used in an Xcode project that contains a bridging header
// that includes <asl.h>
import Foundation
/// Provides high-level methods to access the raw data in
/// an ASL message.
struct SystemLogEntry {
/// Key-value pairs read from ASL message
let data: [String : String]
@zwang
zwang / simulator_populator
Last active August 29, 2015 14:26 — forked from cabeca/simulator_populator
This script removes and recreates all simulators in Xcode 6.
#!/usr/bin/env ruby
device_types_output = `xcrun simctl list devicetypes`
device_types = device_types_output.scan /(.*) \((.*)\)/
runtimes_output = `xcrun simctl list runtimes`
runtimes = runtimes_output.scan /(.*) \(.*\) \((com.apple[^)]+)\)$/
devices_output = `xcrun simctl list devices`
devices = devices_output.scan /\s\s\s\s(.*) \(([^)]+)\) (.*)/
@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