Skip to content

Instantly share code, notes, and snippets.

View raidery's full-sized avatar
🎯
Focusing

Raider raidery

🎯
Focusing
  • IBM
  • China
View GitHub Profile
@raidery
raidery / gist:5d4e4667401834bd4468
Created November 7, 2014 05:31
Scala and sbt installation on ubuntu 12.04
#!/bin/sh
# one way (older scala version will be installed)
# sudo apt-get install scala
#2nd way
sudo apt-get remove scala-library scala
wget http://www.scala-lang.org/files/archive/scala-2.11.2.deb
sudo dpkg -i scala-2.11.2.deb
sudo apt-get update
#!coding:utf-8
#!coding:/usr/bin/python
"""
dependency:
you have to install beautifulsoup4 modulex
sudo pip install beautifulsoup4
description:
ximalaya downloading program made by Meyou(Wuhan) --2015.4.27
import requests
from bs4 import BeautifulSoup
from multiprocessing.dummy import Pool
import os
os.chdir(r'E:\python\2017_4_20')
mp3_url = 'http://www.ximalaya.com/2452186/album/4015467'
headers = {
#!/bin/bash
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
set -e
if [[ ! -z "${JUPYTERHUB_API_TOKEN}" ]]; then
# launched by JupyterHub, use single-user entrypoint
exec /usr/local/bin/start-singleuser.sh $*
else
// see https://gist.github.com/2382341
// scalaz for only solution3
import scalaz._
import Scalaz._
object SolutionForMultiNestedMatchforMyStudy {
def f(num: Int): Option[Int] = {
num match {
@raidery
raidery / AnytoDouble.scala
Created April 24, 2019 01:56
AnytoDouble.scala
// this flavour is pure magic...
def toDouble: (Any) => Double = { case i: Int => i case f: Float => f case d: Double => d }
// whilst this flavour is longer but you are in full control...
object any2Double extends Function[Any,Double] {
def apply(any: Any): Double =
any match { case i: Int => i case f: Float => f case d: Double => d }
}
// like when you can invoke any2Double from another similar conversion...
@raidery
raidery / averageTime.scala
Created April 24, 2019 06:42
averageTime block with Scala
def averageTime[R](block: => R, numIter: Int = 10): Unit = {
val t0 = System.nanoTime()
(1 to numIter).foreach( _ => block)
val t1 = System.nanoTime()
val averageTimeTaken = (t1 - t0) / numIter
val timeTakenMs = averageTimeTaken / 1000000
println("Elapsed time: " + timeTakenMs + "ms")
}
val testDf = spark.range(10000000).toDF.cache
@raidery
raidery / UpperTransformer.scala
Last active May 8, 2019 03:14
Custom UnaryTransformer
import org.apache.spark.ml._
import org.apache.spark.ml.util.Identifiable
import org.apache.spark.sql.types._
val df = Seq(
(0, "a"), (1, "b"),
(2, "c"), (3, "a"),
(4, "a"), (5, "c"))
.toDF("label", "category")
@raidery
raidery / gist:e74946d8433b4f1e89d35169eb0fcb71
Created December 19, 2019 09:19
Extract column values of Dataframe as List in Apache Spark.scala
df.collect().foreach(row => row.toSeq.foreach(col => {
col match {
case n: Number => println(col)
case _ => None
}
}))
@raidery
raidery / extract_column.scala
Created December 19, 2019 09:20
Extract column values of Dataframe as List in Apache Spark
df.collect().foreach(row => row.toSeq.foreach(col => {
col match {
case n: Number => println(col)
case _ => None
}
}))