Skip to content

Instantly share code, notes, and snippets.

View ihainan's full-sized avatar
😉
Hey

Jigao Fu ihainan

😉
Hey
View GitHub Profile
@ihainan
ihainan / gist:f1626ca2e43b8318c862
Created March 19, 2016 00:03
multipart/form-data Request
POST http://xxxx:8080/api/v2/multipart/att HTTP/1.1
Content-Type: multipart/form-data; boundary=apiclient-1458318856973
User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 5 - 5.1.0 - API 22 - 1080x1920 Build/LMY47D)
Host: xxxx:8080
Connection: Keep-Alive
Accept-Encoding: gzip
Content-Length: 7980
--apiclient-1458318856973
Content-Disposition: form-data; name="json"
@ihainan
ihainan / PartitionerTest.scala
Created August 27, 2015 02:45
A simple program used to test Partitioner in Apache Spark 1.4.1
package org.apache.spark.test
import org.apache.spark.{HashPartitioner, RangePartitioner, SparkContext, SparkConf}
import org.apache.spark.SparkContext._
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
/**
* Partitioner Test
*/
object PartitionerTest {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ihainan
ihainan / Iterable Operations.ipynb
Last active August 21, 2017 05:59
Iterable Operations
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
object Solution498 {
def findDiagonalOrder(matrix: Array[Array[Int]]): Array[Int] = {
if (matrix.length == 0 || matrix(0).length == 0) Array.empty[Int]
else {
val (row, column) = (matrix.length - 1, matrix(0).length - 1)
var flag = true
(0 to row + column).flatMap { sum =>
val (low, high) = (0 max (sum - column), row min sum)
val range = if (flag) (high to low by -1) else (low to high)
flag = !flag
object Solution {
def powMod(x: Int, y: Int, mod: Int): Int = {
if (y == 0) 1
else {
val half = powMod(x, y / 2, mod)
if (y % 2 == 0) half * half % mod
else (half * half % mod) * (x % mod) % mod
}
}