Skip to content

Instantly share code, notes, and snippets.

View fever324's full-sized avatar

Hongfei Li fever324

View GitHub Profile
@fever324
fever324 / playpause.applescript
Last active July 4, 2019 01:39
AppleScript for play pausing for alfred workflow
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
if is_running("Spotify") then
tell application "Spotify"to playpause
else if is_running("iTunes") then
tell application "iTunes" to playpause
end if
@fever324
fever324 / roundToPlace.swift
Created November 16, 2016 19:12
Roudn to Place Double Swift
extension Double {
/// Rounds the double to decimal places value
func roundTo(places:Int) -> Double {
let divisor = pow(10.0, Double(places))
return (self * divisor).rounded() / divisor
}
}
@fever324
fever324 / addBorderToUIView.swift
Last active November 8, 2016 17:21
Add border to UIView
extension UIView {
func addBorder(edges: UIRectEdge, colour: UIColor = UIColor.white, thickness: CGFloat = 1) -> [UIView] {
var borders = [UIView]()
func border() -> UIView {
let border = UIView(frame: CGRect.zero)
border.backgroundColor = colour
border.translatesAutoresizingMaskIntoConstraints = false
return border
@fever324
fever324 / gist:70d77624a0761579a76a4956849514e3
Created October 5, 2016 02:32
Start server with forever through babel
forever start -c node_modules/.bin/babel-node server.js
@fever324
fever324 / Server
Created October 2, 2016 04:10
Forward port on server
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443
@fever324
fever324 / ProductofArrayExceptSelf .java
Created August 31, 2015 23:44
Product of Array Except Self
/*
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].
Solve it without division and in O(n).
For example, given [1,2,3,4], return [24,12,8,6].
Follow up:
Could you solve it with constant space complexity? (Note: The output array does not count as extra space for the purpose of space complexity analysis.)
*/
@fever324
fever324 / nthUglyNumber.java
Created August 25, 2015 01:59
Nth Ugly Number
/*
Write a program to find the n-th ugly number.
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.
Note that 1 is typically treated as an ugly number.
*/
public class Solution {
public int nthUglyNumber(int n) {
PriorityQueue<Long> q = new PriorityQueue<Long>();
@fever324
fever324 / uglyNumber.java
Created August 25, 2015 01:05
Ugly Number
/*
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.
Note that 1 is typically treated as an ugly number.
*/
public class Solution {
public boolean isUgly(int num) {
if (num == 0) {
@fever324
fever324 / BSTIterator.java
Created August 12, 2015 12:33
BST Iterator
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
@fever324
fever324 / BSTIterator.java
Created August 12, 2015 12:33
BST Iterator
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/