Skip to content

Instantly share code, notes, and snippets.

View lure's full-sized avatar

Alex Shubert lure

  • JetBrains, LLC
View GitHub Profile
@lure
lure / Eratosthene.java
Created August 27, 2012 07:29
Byte array sieve of Eratosthene
import java.util.Arrays;
public class Eratosthene{
public static int[] byteEratosthenes(int cap) {
int[] result = new int[(int) Math.ceil(1.25 * cap / Math.log(cap))];
int pos = 1;
result[0] = 2;
byte[] primes = new byte[(cap - 2 >> 4) + 1];
@lure
lure / organizer.rb
Last active December 17, 2015 06:49
ruby, files organizer
# Being executed in the dir with a list of files with names formed as
# 'AuthorName BookTitle.ext' or 'AuthorName,BookTitle.ext'
# creates dirs named by Author and moves author's books there
require 'fileutils'
PATH_D = File.expand_path(File.dirname(__FILE__)) + '/' #absolute path to current dir
FILE_BASE = File.basename(__FILE__) #script's filename
Dir.foreach("./") do |entry|
next if entry.start_with?('.') or entry == FILE_BASE
@lure
lure / SocialProviders.scala
Created November 21, 2015 21:57
Scala enumeratio
abstract class JEnum extends Enumeration {
case class JVal(name: String, url: Option[String]) extends Val(name) {
lazy val successUrl: String = {
// Should have protocol specification or YAHOO will fail
url.getOrElse(Props.get("public.domain").getOrElse("") + "/socialauth/rest/" + this.name + "/action")
}
}
protected final def JValue(name: String, url: String = null): Value = JVal(name, Option(url))
implicit def valueToJValue(v: Value): JVal = v.asInstanceOf[JVal]
@lure
lure / docker-log-gist.md
Created January 13, 2017 09:58 — forked from afolarin/docker-log-gist.md
docker-logs

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@lure
lure / google-download.sh
Created April 3, 2018 20:23
Download files from google disk.
#!/bin/bash
SOURCE="$1"
if [ "${SOURCE}" == "" ]; then
echo "Must specify a source url"
exit 1
fi
DEST="$2"
if [ "${DEST}" == "" ]; then
@lure
lure / postgresql_pg_stat_activity_with_tempfiles.sql
Created September 4, 2018 19:47 — forked from ng-pe/postgresql_pg_stat_activity_with_tempfiles.sql
postgresql "pg_stat_activity" with temporary files information
-- View pg_stat_activity with temporary files informations (file list and total file size)
-- version 0.3
SELECT
pg_stat_activity.pid AS pid,
CASE WHEN LENGTH(pg_stat_activity.datname) > 16
THEN SUBSTRING(pg_stat_activity.datname FROM 0 FOR 6)||'...'||SUBSTRING(pg_stat_activity.datname FROM '........$')
ELSE pg_stat_activity.datname
END
AS database,
import cats.implicits._
//https://stackoverflow.com/questions/48744146/stacking-m-either-and-writer
object SafeLogWriter {
type FutureErrorOr[A] = EitherT[Future, Error, A]
type ErrorOr[A] = Either[Error, A]
type MyWriter[A] = WriterT[Future, Vector[String], A]
type MyStack[A] = EitherT[MyWriter, Error, A]
@lure
lure / macros.scala
Created March 22, 2019 21:17
Macro string to symbol
import scala.reflect.macros.whitebox
import scala.language.experimental.macros
def symbolic_impl(c: whitebox.Context)(f: c.Expr[String]): c.Expr[scala.Symbol] = {
import c.universe._
c.Expr(q"""scala.Symbol(${c.eval[String](f)})""")
}
def symbolic(f: String): scala.Symbol = macro symbolic_impl