Skip to content

Instantly share code, notes, and snippets.

View parambirs's full-sized avatar
👋

Parambir Singh parambirs

👋
View GitHub Profile
// 1. The signum of a number is 1 if the number is positive, -1 if it is negative, and
// 0 if it is zero. Write a function that computes this value.
def signum(n: Int) = {
if (n > 0) 1
else if (n < 0) -1
else 0
} //> signum: (n: Int)Int
signum(4) //> res0: Int = 1
@parambirs
parambirs / app.js
Created September 7, 2019 23:26
Basic Vue Application
const app = new Vue({
el: '#app',
data: {
product: 'Boots',
myproducts: [
'Boots',
'Jacket',
'Hiking Socks'
],
products: []
@parambirs
parambirs / JavaStreams.java
Created August 29, 2019 19:56
Creating different kinds of Stream sources in Java
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Sources {
public static void main(String[] args) throws IOException {
@parambirs
parambirs / Switch.java
Created August 29, 2019 19:55
Java 12 Switch
public class Main {
enum Event {
PLAY, STOP, PAUSE
}
public static void main(String[] args) {
var event = Event.PLAY;
switch (event) {
case PLAY:
@parambirs
parambirs / docker.sh
Created August 15, 2019 20:27
Docker Postgres
docker pull postgres:latest
docker run -d --name guitar-db -p 5432:5432 -e 'POSTGRES_PASSWORD=p@ssw0rd42' postgres
@parambirs
parambirs / s4di_ch01_exercises.sc
Last active August 14, 2019 23:11
Solutions for "Scala for the Impatient", chapter 1 exercises
package src.exercises
import scala.math._
import BigInt.probablePrime
import util.Random
object chap01 {
// 1. In the Scala REPL, type 3. followed by the Tab key. What methods can be
// applied?
// => Do it in REPL. There are many methods including %, &, *, +, toByte, toChar etc.
// 1. Write a code snippet that sets a to an array of n random integers between 0
// (inclusive) and n (exclusive).
val a = new Array[Int](10) //> a : Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
for(i <- 0 until a.length) a(i) = scala.util.Random.nextInt(10)
a //> res0: Array[Int] = Array(9, 0, 5, 8, 6, 6, 3, 9, 0, 3)
// 2. Write a loop that swaps adjacent elements of an array of integers. For example,
// Array(1, 2, 3, 4, 5) becomes Array(2, 1, 4, 3, 5).
val a = Array[Int](1,2,3,4,5)
a //> res1: Array[Int] = Array(1, 2, 3, 4, 5)
@parambirs
parambirs / ScalaJS.md
Last active December 4, 2018 23:20
Scala.js notes

sbt tasks

> run

> fastOptJS

Generates a single JS file.

> fullOptJS

@parambirs
parambirs / setup.sh
Created October 10, 2018 19:48
TypeScript Node Express Setup
npm init -y
npm install --save typescript
tsc --init
@parambirs
parambirs / singleton.js
Created June 26, 2018 20:01
Singleton in JavaScript
'use strict';
let lime = new function() {
this.type = 'Mexican lime';
this.color = 'green';
this.getInformation = function() {
return 'This ' + this.type + ' is ' + this.color + '.';
};
}