Skip to content

Instantly share code, notes, and snippets.

@r4vi
r4vi / chkadm.py
Created April 12, 2011 11:10
checks if the current logged in user is removed from the local administrators group and re-adds. (windows)
import ctypes
import win32net, win32api
import time
current_user = win32api.GetUserNameEx(2)
data = [{"domainandname": current_user}]
def get_members(group_name):
members = win32net.NetLocalGroupGetMembers(None, group_name, 3)[0]
print members
@r4vi
r4vi / gist:1977971
Created March 5, 2012 11:45
eval in lisp
(defun eval. (e a)
(cond
((atom e) (assoc. e a))
((atom (car e))
(cond
((eq (car e) 'quote) (cadr e))
((eq (car e) 'atom) (atom (eval. (cadr e) a)))
((eq (car e) 'eq) (eq (eval. (cadr e) a)
(eval. (caddr e) a)))
((eq (car e) 'car) (car (eval. (cadr e) a)))
@r4vi
r4vi / richhicky.clj
Created April 29, 2012 17:21
Norvig spellchecker in clojure by rich hickey
(defn words [text] (re-seq #"[a-z]+" (.toLowerCase text)))
(defn train [features]
(reduce (fn [model f] (assoc model f (inc (get model f 1)))) {} features))
(def *nwords* (train (words (slurp "big.txt"))))
(defn edits1 [word]
(let [alphabet "abcdefghijklmnopqrstuvwxyz", n (count word)]
(distinct (concat
@r4vi
r4vi / pub.py
Created June 15, 2012 08:20
redis-pubsub
import redis
import datetime
import time
def main():
r = redis.client.StrictRedis()
while True:
now = datetime.datetime.now()
print 'Sending {0}'.format(now)
r.publish('clock', now)
/* ShowOff JS Logic */
var ShowOff = {};
var preso_started = false
var slidenum = 0
var slideTotal = 0
var slides
var currentSlide
var totalslides = 0
@r4vi
r4vi / bubbles.clj
Created July 22, 2012 01:02
Quill Examples
(ns quil-ravi.core
(:use quil.core))
(defn setup []
(smooth) ;;Turn on anti-aliasing
(frame-rate 65) ;;Set framerate to 1 FPS
(background 200)) ;;Set the background colour to
;; a nice shade of grey.
(defn savef []
@r4vi
r4vi / copy.html
Created August 15, 2012 15:51
html5 copy
<html>
<head>
<script>
function copy(event) {
event.clipboardData.setData('text/plain', 'Hello World!');
}
</script>
<body oncopy="copy(event)">
</body>
</html>
@r4vi
r4vi / index.html
Created December 1, 2012 22:55 — forked from mbostock/.block
World Countries
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.country {
fill: #b8b8b8;
stroke: #fff;
stroke-width: .5px;
stroke-linejoin: round;
}
@r4vi
r4vi / optimize.sh
Last active December 15, 2015 02:29 — forked from ryansully/optimize.sh
handles files with spaces in the name and keeps EXIF in jpeg
#!/bin/sh
# script for optimizing images in a directory (recursive)
# pngcrush & jpegtran settings from:
# http://developer.yahoo.com/performance/rules.html#opt_images
# pngcrush
find $1 -iname "*.png" | while read png
do
echo "crushing $png ..."
@r4vi
r4vi / gist:8008148
Created December 17, 2013 16:48
python threading
#!/usr/bin/python
import threading
import time
class Sleepy(threading.Thread):
def run(self):
time.sleep(5)