Skip to content

Instantly share code, notes, and snippets.

@kadirmalak
kadirmalak / OMP_NUM_THREADS_24_test.txt
Created March 14, 2019 13:20
export OMP_NUM_THREADS=24; ./runtests --gtest_filter="PlaygroundTests.FastScalar"
Note: Google Test filter = PlaygroundTests.FastScalar
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from PlaygroundTests
[ RUN ] PlaygroundTests.FastScalar
Scalar Addition - x.add(3.14159265359)
TestName OpNum Warmup NumIter DataType Inplace Shape Strides Axis Orders avg (us) median (us) min (us) max (us) stdev (us)
sAdd 0 10 1000 FLOAT false [16] [1]/[1] N/A c/c 0 0 0 5 0.16
for item in ifor(['a', 'b', 'c'], [1, 2], ['asd']):
print(item)
# outputs
# ['a', 1, 'asd']
# ['a', 2, 'asd']
# ['b', 1, 'asd']
# ['b', 2, 'asd']
# ['c', 1, 'asd']
# ['c', 2, 'asd']
def ifor(*lists):
root = Node('ROOT')
for L in lists:
leaves = list(root.leaves())
for data in L:
# create once, use multiple times
# this way we end up with a graph, instead of a tree
new_node = Node(data)
for leaf in leaves:
# leaves() function may return same nodes multiple times
class Node():
def __init__(self, data):
self.data = data
self.children = []
def add(self, node):
self.children.append(node)
return self
def __str__(self):
# dummy implementation just to show the intent
def for1(list1, list2, list3):
for i in list1:
for j in list2:
for k in list3:
yield (i, j, k)
for i in for1(['a', 'b', 'c'], [1, 2], ['asd']):
print(i)
@kadirmalak
kadirmalak / draw-method.clj
Created March 4, 2018 17:36
.ellipse method call changed to .rect method on the last line
(defn -draw [this] ;; override draw() method
(if (.-mousePressed this)
(.fill this 0)
(.fill this 255))
(let [x (.-mouseX this)
y (.-mouseY this)
width 80
height 80]
(.rect this x y width height))) ;; changed .ellipse to .rect
@kadirmalak
kadirmalak / core.clj
Created March 4, 2018 16:43
Minimal Processing app with Clojure
(ns processing-with-clojure.core
(:gen-class
:extends processing.core.PApplet) ;; we need a class extending processing.core.PApplet
(:import (processing.core PConstants PApplet)))
(defn -main
[& args]
(PApplet/main "processing_with_clojure.core")) ;; generated class name has underscores(_)
;; instead of hyphens(-)
@kadirmalak
kadirmalak / quine.cpp
Last active September 13, 2017 19:11
Self Reproducing Program (Quine) in C++
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
auto source = vector<string>{
"#include <iostream>",
import unittest
import inspect
import re
def run_tests(clazz):
def is_test_method(name):
return re.search('^test_*', name) is not None
funcs = inspect.getmembers(clazz, predicate=inspect.isfunction)
@kadirmalak
kadirmalak / processing.scala
Created August 31, 2017 12:21
Using Processing with Scala
package processingscala
import processing.core.{PApplet, PConstants}
object Main extends PApplet {
def main(args:Array[String]) = {
PApplet.main("processingscala.Main")
}
}