Skip to content

Instantly share code, notes, and snippets.

yoyama / Schema2CaseClass.scala
Created Jan 20, 2017
Generate case class from spark DataFrame/Dataset schema.
View Schema2CaseClass.scala
* Generate Case class from DataFrame.schema
* val df:DataFrame = ...
* val s2cc = new Schema2CaseClass
* import s2cc.implicit._
* println(s2cc.schemaToCaseClass(df.schema, "MyClass"))
View Spark high

Spark - High availability

Components in play

As a reminder, here are the components in play to run an application:

  • The cluster:
    • Spark Master: coordinates the resources
    • Spark Workers: offer resources to run the applications
  • The application:
jkpl / Main.scala
Last active Jun 17, 2021
Ways to pattern match generic types in Scala
View Main.scala
object Main extends App {
class Funky[A, B](val foo: A, val bar: B) {
override def toString: String = s"Funky($foo, $bar)"
odersky / A simpler way to returning the "current" type in Scala.
Last active Mar 6, 2021
A simpler way to returning the "current" type in Scala.
View A simpler way to returning the "current" type in Scala.
/** This is in reference to @tploecat's blog
* where he compares F-bounded polymorphism and type classes for implementing "MyType".
* Curiously, the in my mind obvious solution is missing: Use abstract types.
* A lot of this material, including an argument against F-bounded for the use-case
* is discussed in:
* Kim B. Bruce, Martin Odersky, Philip Wadler:
* A Statically Safe Alternative to Virtual Types. ECOOP 1998: 523-549
itskingori / application_controller.rb
Last active Jul 23, 2021 — forked from speed-of-light/application_controller.rb
How to handle exceptions like 401, 501, 404 in Rails
View application_controller.rb
# As used with CanCan and Devise
class ApplicationController < ActionController::Base
include ErrorResponseActions
rescue_from CanCan::AccessDenied, :with => :authorization_error
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
before_filter :authenticate!
eliotsykes / ngFocusAndBlur.js
Created Apr 16, 2013
AngularJS ngFocus and ngBlur directives - one way to get them before they get released. Before using, consider re-naming ngFocus and ngBlur to something that doesn't invade the ng namespace, e.g. replace all 'ngFocus' and 'ngBlur' strings with 'ngcFocus' and 'ngcBlur' (where c = cats/custom).
View ngFocusAndBlur.js
app.directive('ngFocus', ['$parse', function($parse) {
return function(scope, element, attr) {
var fn = $parse(attr['ngFocus']);
element.bind('focus', function(event) {
scope.$apply(function() {
fn(scope, {$event:event});
ProLoser / alerts.html
Last active Oct 9, 2019
AngularJS Bootstrap implemented without any additional code
View alerts.html
<p>Bootstrap JS</p>
<div class="alert fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Holy guacamole!</strong> Best check yo self, you're not looking too good.
<p></p><a ng-click="alert=true">Open Alert (AngularJS)</a></p>
<div class="alert fade" ng-class="{in:alert}">
<button type="button" class="close" ng-click="alert=false">×</button>
vojtajina / all-templates.html
Created Aug 15, 2012
AngularJS: load all templates in one file
View all-templates.html
<script type="text/ng-template" id="one.html">
<div>This is first template</div>
<script type="text/ng-template" id="two.html">
<div>This is second template</div>
hellerbarde / latency.markdown
Created May 31, 2012 — forked from jboner/latency.txt
Latency numbers every programmer should know
View latency.markdown

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns  = 250 µs

Google Speech To Text API

Base URL:
It accepts POST requests with voice file encoded in FLAC format, and query parameters for control.

Query Parameters

The client's name you're connecting from. For spoofing purposes, let's use chromium

Speech language, for example, ar-QA for Qatari Arabic, or en-US for U.S. English