Skip to content

Instantly share code, notes, and snippets.

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

Mandar Chandorkar mandar2812

🏠
Working from home
View GitHub Profile
@moble
moble / README.md
Last active December 13, 2023 14:22
Speed up execution of `@everywhere` in julia

As described in detail here, julia can take really excessive amounts of time to execute the first @everywhere statement on many processes β€” around 1 hour for thousands of processes β€” even if the actual code being executed everywhere is trivial. Basically, the Distributed functions need to be precompiled to make this happen quickly.

This gist provides a simple way to do so β€” at least on Slurm clusters (though the same principles should apply elsewhere). Just submit precompile.jl as a batch job (adjusting the SBATCH directives as needed), and it should create a sysimage that you can use to run future batch jobs. Check end of the log of the Slurm job to see exactly how to use the sysimage.

Note that both the original julia process and all processes created with addprocs should use the --sysimage=/path/to/sys_everywhere.so argument. Doing so reduces the time taken to execute the first @everywhere sta

@simerplaha
simerplaha / C3js.scala
Last active May 16, 2018 13:40
A simple Scala-js C3.js Charts facade ... Something I wrote quickly to integrate C3.js charts. Hopefully it will be good enough for anyone to get started with C3.js charts in Scala.js. I will try to make the parameters more type safe objects soon and implement the APIs properly.
import scala.scalajs.js
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.annotation.JSName
trait C3ChartObject extends js.Object {
def load(data: C3JSChartDataset): js.Dynamic = js.native
def unload() = js.native
}
@mandar2812
mandar2812 / Hermite.scala
Created May 13, 2015 16:06
Tail Recursive function to calculate the Hermite polynomial of an arbitrary degree.
object Hermite {
def hermite(n: Int, x: Double): Double = {
def hermiteHelper(k: Int, x: Double, a: Double, b: Double): Double =
k match {
case 0 => a
case 1 => b
case _ => hermiteHelper(k-1, x, b, x*b - (k-1)*a)
}
hermiteHelper(n, x, 1, x)
}
@mandar2812
mandar2812 / MedianRecursive.scala
Last active August 15, 2019 02:34
A tail recursive function to calculate median of a List
import scala.util.Random
/**
* @author mandar2812
*/
object MedianRecursive {
def median(list: Stream[Double]): Double = {
val random: (Int) => Int = Random.nextInt
@jeffsteinmetz
jeffsteinmetz / gist:063bd3237033f3af2ed9
Last active October 20, 2023 22:20
Generate Unique, Hashed, Random Token in Scala for use in API calls or as an OAuth Token Bearer
import scala.util._
import java.security.SecureRandom
import java.security.MessageDigest
/*
* Generates a Bearer Token with a length of
* 32 characters (MD5) or 64 characters (SHA-256) according to the
* specification RFC6750 (http://tools.ietf.org/html/rfc6750)
*
* Uniqueness obtained by hashing system time combined with a
@cbosco
cbosco / all_my_facebook_photos.html
Last active November 9, 2023 23:34
Simple "get all of my facebook photos" facebook JS SDK + Graph API example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Photos with Friends!</title>
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script>
/**
* This is the getPhoto library
*/