Skip to content

Instantly share code, notes, and snippets.

View vasnake's full-sized avatar
🏠
Working from home

Valentin vasnake

🏠
Working from home
View GitHub Profile
@vasnake
vasnake / spark.udf.fizzbuzz.scala
Last active August 25, 2023 15:28
Spark generic UDF, spark.sql.api.java
package org.apache.spark.sql.fizzbuzz.udf
import org.apache.spark.sql.api.java.UDF1
import scala.util.Try
import org.scalatest._
import flatspec._
class FizzBuzz extends UDF1[Any, String] {
def dbg(s: => String): Unit = println(s)

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

For starters, here is the sort of thing that SI-2712 affects:

def foo[F[_], A](fa: F[A]): String = fa.toString
@vasnake
vasnake / encoding-video.md
Created January 30, 2019 13:28 — forked from Vestride/encoding-video.md
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@vasnake
vasnake / seq.scala
Created January 10, 2017 06:46
Sequences processing, interview questions
/*
Есть события: (время начала, время конца, тег "в метро", айди территории, флаг "вход", флаг "выход"),
заполнены поля могут быть как угодно, очередность событий может быть любая
*/
case class TelEventRecord(bts: Int, ets: Int,
transport: String,
zid: Int = -1,
enter: Boolean = false, exit: Boolean = false)
/*
Надо обработать последовательность таких событий, чтобы получить последовательность "поездок"
@vasnake
vasnake / typeclassExample.scala
Created July 4, 2016 17:15
Scala Type Classes example
// type classes example
// based on material from SICP 1.3.1 high-order procedures
// inspired by
// The Neophyte's Guide to Scala Part 12: Type Classes
// http://danielwestheide.com/blog/2013/02/06/the-neophytes-guide-to-scala-part-12-type-classes.html
// scala.math.Numeric is a type class
// that define an interface
@vasnake
vasnake / deluge.rpcserver.py.patch
Created October 25, 2014 15:31
Deluge 1.3.7 core/rpcserver.py patch (http://dev.deluge-torrent.org/ticket/2555) resolving "client unable to connect" issue.
--- rpcserver.py.orig 2014-10-25 19:03:15.841366375 +0400
+++ rpcserver.py 2014-10-25 19:05:40.753392389 +0400
@@ -131,7 +131,8 @@
SSL transport.
"""
ssl_dir = deluge.configmanager.get_config_dir("ssl")
- ctx = SSL.Context(SSL.SSLv3_METHOD)
+ ctx = SSL.Context(SSL.SSLv23_METHOD)
+ ctx.set_options(SSL.OP_NO_SSLv2 & SSL.OP_NO_SSLv3)
ctx.use_certificate_file(os.path.join(ssl_dir, "daemon.cert"))
@vasnake
vasnake / webcamfixer.py
Created July 18, 2014 21:01
Webcam fixer
#!/usr/bin/env python
# -*- mode: python; coding: utf-8 -*-
# Copyright (c) Valentin Fedulov <vasnake@gmail.com>
''' This script intended to fix some webcam software problems.
It's job can be described in three points:
First step: find latest JPG file in SEARCH_IN folder and subfolders.
Next step: copy that file to WRITE_TO destination.
Last step: put a timestamp on lower right corner of the WRITE_TO image.
@vasnake
vasnake / disable_fw.sh
Created June 14, 2014 14:31
Reset (disable) firewall
#!/bin/bash
# disable_fw.sh - Reset (disable) firewall
# ---------------------------------------------------------------------------------------------------------------
# Initially Written by Vivek Gite <vivek@nixcraft.com>
# Rewrited by Valentin Fedulov <vasnake@gmail.com>
# Source: http://www.cyberciti.biz/faq/turn-on-turn-off-firewall-in-linux/
# ---------------------------------------------------------------------------------------------------------------
# You can copy / paste / redistribute this script under GPL version 2.0 or above
# =============================================================
#!/usr/bin/env python
"""
=====================================
PEP 20 (The Zen of Python) by example
=====================================
Usage: %prog
:Author: Hunter Blanks, hblanks@artifex.org / hblanks@monetate.com