Skip to content

Instantly share code, notes, and snippets.

@kadirmalak
kadirmalak / rdp-disconnect.py
Last active August 31, 2017 12:17
Remotely logoff / disconnect / reset multiple RDP sessions
# USAGE: python rdp-disconnect.py -u kadir.malak -s 192.168.0.10 192.168.0.11 somehostname1 somehostname2
from subprocess import check_output, STDOUT
import argparse
def rdp_session_id(server, username):
output = check_output('qwinsta /server:%s %s' % (server, username), stderr=STDOUT).decode('latin1')
if 'No session exists' in output:
return -1
lines = [line.split() for line in output.split('\r\n')]
@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")
}
}
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 / 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>",
@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 / 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
# 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)
class Node():
def __init__(self, data):
self.data = data
self.children = []
def add(self, node):
self.children.append(node)
return self
def __str__(self):
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
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']