Skip to content

Instantly share code, notes, and snippets.

@yc0
yc0 / credentials
Last active April 17, 2017 06:40
the sample code for sendMessage with topic:notification in AWS SNS
[default]
aws_access_key_id=<access_key>
aws_secret_access_key=<secret_key>
@yc0
yc0 / backlogs_issue_patch.rb
Created April 21, 2017 09:20
[redmine]allow you modify your parent later without changing the tracker id
# plugins/redmine_backlogs/lib/backlogs_issue_patch.rb
def backlogs_after_save
# ..
# omitted
# ..
if self.story?
# omitted
tasklist = RbTask.find(:all, :conditions => ["root_id=? and lft>? and rgt<? and
(
# This is the Twisted Get Poetry Now! client, version 2.1.
# NOTE: This should not be used as the basis for production code.
import optparse,sys
from twisted.internet.protocol import Protocol, ClientFactory
from twisted.internet import reactor
from twisted.python.failure import Failure
@yc0
yc0 / exercise.tour.go
Created December 19, 2017 06:11
tour.golang exercise solutions
/******************************************************************************************************/
/* Exercise: Errors #57 */
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
@yc0
yc0 / tour.golang.org.go
Last active December 22, 2017 16:57
tour.golang.org exercise solutions
/******************************************************************************************************/
/* Exercise: concurrency/8 Equivalent Binary Trees */
package main
import (
"fmt"
"math/rand"
)
@yc0
yc0 / go-leetcode-587.go
Last active January 13, 2018 07:03
587. Erect the Fence implement in Golang
/*
The problem is shown below.
There are some trees, where each tree is represented by (x,y) coordinate in a two-dimensional garden.
Your job is to fence the entire garden using the minimum length of rope as it is expensive.
The garden is well fenced only if all the trees are enclosed.
Your task is to help find the coordinates of trees which are exactly located on the fence perimeter.
******************************************************************************************
@yc0
yc0 / go-leetcode-621.go
Created February 7, 2018 16:47
leetcode 621. Task Scheduler
/*
621. Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.
However, there is a non-negative cooling interval n that means between two same tasks, there must be at least n intervals that CPU are doing different tasks or just be idle.
You need to return the least number of intervals the CPU will take to finish all the given tasks.
Example 1:
@yc0
yc0 / go-leetcode-662.go
Created February 8, 2018 16:52
662. Maximum Width of Binary Tree
/*
662. Maximum Width of Binary Tree
Given a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum width among all levels. The binary tree has the same structure as a full binary tree, but some nodes are null.
The width of one level is defined as the length between the end-nodes (the leftmost and right most non-null nodes in the level, where the null nodes between the end-nodes are also counted into the length calculation.
Example 1:
Input:
@yc0
yc0 / codility-email.py
Created February 14, 2018 08:07
Codility - Email compostion
"""
Email字串處理
輸入email(S)和網域名(C)
Function(S,C)
S=["aa bb cc; xx yy z-z; aa bb; aa bx cc"]
C=["test"]
@yc0
yc0 / go-leetcode-517.go
Created April 7, 2018 11:26
517. Super Washing Machines
func findMinMoves(machines []int) int {
if machines == nil {
return -1
}
sum, size := sum(machines...), len(machines)
fmt.Println(sum,size)
if sum % size == 0 {
target := sum / size
cnt, res := 0, 0