Skip to content

Instantly share code, notes, and snippets.

View zarinfam's full-sized avatar

Saeed Zarinfam zarinfam

View GitHub Profile
pow2 :: Integer -> Integer
pow2 a = a * a
@zarinfam
zarinfam / gist.js
Created July 11, 2019 09:04
Created with Copy to Gist
$(document).ready(fixUrls);
@zarinfam
zarinfam / gist.js
Created July 11, 2019 09:02
Created with Copy to Gist
function fixUrls(){
$('a').each(function () {
//get the original URL
var theURL = $(this).attr('href');
if (theURL.includes('t.umblr.com/redirect?')) {
//split at the equals sign
var one = theURL.split('=');
//split again at the amperstand
var two = one[1].split('&')
//get rif of the URL encoding
@zarinfam
zarinfam / gist.java
Created July 4, 2019 09:43
Created with Copy to Gist
for (int i = 0; i <= 10; i = i + 2) {
System.out.println(i);
}
@zarinfam
zarinfam / gist.java
Created July 4, 2019 09:40
Created with Copy to Gist
Stream.iterate(0, i -> i <= 10, i -> i + 2)
.forEach(System.out::println);
@zarinfam
zarinfam / gist.java
Created July 4, 2019 09:35
Created with Copy to Gist
Stream.iterate(0, i -> i + 2)
.forEach(System.out::println);
@zarinfam
zarinfam / gist.java
Created July 4, 2019 08:11
Created with Copy to Gist
Set<Integer> numbers = Set.of(1, 3, 6, 2, 4);
numbers.stream()
.takeWhile(i -> i < 4)
.forEach(System.out::println)
;
@zarinfam
zarinfam / gist.java
Created July 3, 2019 14:33
Created with Copy to Gist
Stream.iterate("*", s -> s + "*")
.takeWhile(s -> s.length() < 7)
.forEach(System.out::println)
;
@zarinfam
zarinfam / gist.scala
Created July 2, 2019 11:20
Created with Copy to Gist
object DeathToStrategy extends App {
def add(a: Int, b: Int) = a + b
def subtract(a: Int, b: Int) = a - b
def multiply(a: Int, b: Int) = a * b
def execute(callback:(Int, Int) => Int, x: Int, y: Int) = callback(x, y)
println("Add: " + execute(add, 3, 4))
println("Subtract: " + execute(subtract, 3, 4))
@zarinfam
zarinfam / gist.java
Created July 2, 2019 11:17
Created with Copy to Gist
interface Strategy {
int execute(int a, int b);
};
/** Implements the algorithm using the strategy interface */
class Add implements Strategy {
public int execute(int a, int b) {
System.out.println("Called Add's execute()");
return a + b; // Do an addition with a and b
}