Skip to content

Instantly share code, notes, and snippets.

var utterance = new SpeechSynthesisUtterance();
var voices = speechSynthesis.getVoices();
utterance.voice = voices[16];
utterance.rate = 1.2;
utterance.pitch = 1;
mo = new MutationObserver(mutations => {
mutations.forEach(mutation => {
const e = mutation.addedNodes[0];
if (e) {
utterance.text = e.querySelector('#author-name').innerText + ': ' + e.querySelector('#message').innerText;
@randomekek
randomekek / framework.js
Created January 18, 2018 10:36
My js library
/*
ProxyDom usage:
var div = ..., proxy = ProxyDom(div);
proxy.text('hey').class('bold', true).attr('data-id', 'identity');
*/
/*
template usage:
<div data-template='name'>
<div data-bind='title'></div>
@randomekek
randomekek / GLSL-Noise.md
Created March 2, 2016 12:29 — forked from patriciogonzalezvivo/GLSL-Noise.md
GLSL Noise Algorithms

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}
<?php
/**
* Asynchronously Post Http requests
* $request = AsyncHttpPost::create($url, array('key' => 'post data'));
* Need to call isDone to begin working.
* Use either wait() to wait for the request to finish (blocking)
* Or use isDone to check if the request has completed.
*/
class AsyncHttpPost {
#!/bin/bash
if [ -n "$(svn st | egrep '^A|M' | awk '{print$2}' | xargs cat | grep -i '@todo')" ]; then
echo 'There are TODOs:';
svn st | egrep '^A|M' | awk '{print$2}' | while read filename; do
if [ -n "$(cat $filename | head -c 100000 | grep -i '@todo')" ]; then
echo $filename
cat $filename | head -c 100000 | grep -i '@todo' | awk '{ sub(/^[ *]*/, "", $0); print " > " $0 }'
echo
fi
@randomekek
randomekek / xml_encode.php
Last active February 6, 2024 14:37
xml_encode
<?php
function xml_encode($root, $values) {
return xml_add_children(new SimpleXMLElement("<?xml version='1.0' encoding='utf-8'?><$root/>"), $values)->asXML();
}
function xml_add_children($root, $values) {
foreach ($values as $key => $value) {
if ($key[0] == '@') {
$root->addAttribute(substr($key, 1), $value);
@randomekek
randomekek / gist:3184091
Created July 26, 2012 19:45
Transaction 'monad' in PHP
<?
class Trxn {
public static function run($trxn) {
$result = $trxn();
return $result;
}
public static function then(Closure $now, Closure $next) {
return function() use($now, $next) {
@randomekek
randomekek / screensaver.py
Created November 23, 2011 05:28
Log gnome screen saver and also pause banshee
import dbus
import time
import gobject
import datetime
import dbus.mainloop.glib as glib
class Main():
def __init__(self):
dbus_loop = glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus(mainloop = dbus_loop)
import gevent
from gevent.pywsgi import WSGIServer, WSGIHandler
def f(env, start_response):
start_response('200 OK', [('Content-type', 'text/plain')])
gevent.sleep(4)
return 'hi'
class NoErrorHandler(WSGIHandler):
def process_result(self):