Skip to content

Instantly share code, notes, and snippets.

View leontabak's full-sized avatar
💭
I am currently learning React with Udacity.

Leon Tabak leontabak

💭
I am currently learning React with Udacity.
View GitHub Profile
@leontabak
leontabak / GameOfFifteen.java
Created July 7, 2021 14:54 — forked from ssaurel/GameOfFifteen.java
Game of Fifteen tutorial on the SSaurel's Channel
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
@leontabak
leontabak / try-logging.py
Last active August 11, 2021 17:43
Logging in Python
# try-logging.py
# Leon Tabak
# l.tabak@ieee.org
# 11 August 2021
'''
Copyright 2021 Leon Hannah Tabak
Permission is hereby granted, free of charge, to any person obtaining
@leontabak
leontabak / Main.kt
Created September 23, 2021 02:28
Cohen-Sutherland algorithm.
/*
I wrote this code to introduce my students
to some features of the Kotlin language.
Leon Tabak
22 September 2021
*/
enum class ClippingStatus {
@leontabak
leontabak / Main.kt
Created September 24, 2021 13:44
Show GUI with Swing in Kotlin
import java.awt.Color
import java.awt.Font
import java.awt.GridLayout
import java.awt.event.ActionListener
import java.awt.event.ActionEvent
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JMenu
import javax.swing.JMenuBar
import javax.swing.JMenuItem
@leontabak
leontabak / Main.kt
Created September 24, 2021 18:08
introducing lambda in Kotlin
fun main() {
println("Experiment with lambda functions.")
val doublePlusOne: (Int) -> Int = {x:Int-> 2 * x + 1}
println( doublePlusOne(3) )
val data = (0..3).map( doublePlusOne )
println( data::class.simpleName )
println( data )
@leontabak
leontabak / Main.kt
Created September 29, 2021 15:02
fill a list with numbers drawn from an exponential distribution
import kotlin.math.ln
fun main() {
// a specified mean for an exponential
// distribution of random numbers
val specifiedMean = 3.0
// create a random number generator
val rng = kotlin.random.Random(System.nanoTime())
@leontabak
leontabak / Main.kt
Created September 29, 2021 15:12
how to fill a list with objects whose properties have random values
data class Process( val x0:Double, val x1:Double )
fun main() {
// create random number generator
val rng = kotlin.random.Random(System.nanoTime())
val elementInitializer: (Int) -> Process =
{_:Int -> Process(rng.nextDouble(), rng.nextDouble())}
@leontabak
leontabak / Main.kt
Created September 30, 2021 13:52
Make list of simulated processes
import kotlin.random.Random
// Create a list of processes.
// Each process has 2 properties:
// * it knows how much time has elapsed
// between the time that the previous
// process entered the waiting line
// and the time it took its place
// at the end of the line
// * it knows the time at which it
@leontabak
leontabak / Higher.scala
Created October 5, 2021 18:45
examples of currying and a closure
import java.io.PrintWriter
import scala.io.Source
object Higher extends App {
println("Sputnik!")
// Here's an example of a closure.
// f is a function that returns a
// function to its caller
// the function g that it returns
@leontabak
leontabak / HelloGoodbye.scala
Created October 6, 2021 18:40
Another example of the use of a closure in Scala.
package com.eonsahead
object HelloGoodbye extends App {
def greetingMaker (): () => String = {
// This is a function that returns a function
// to its caller.
// This function ("greetingMaker") has one local
// variable (named "arriving").