Skip to content

Instantly share code, notes, and snippets.

@avidal
avidal / simple-asyncio.py
Created June 3, 2024 14:56
Simple example of using pexpect+asyncio from non async code
# Use it with: python3 simple-asyncio.py <timeout>
# timeout defaults to 5 seconds which means it'll never timeout
# change the string to expect (or the string printed after the sleep) to demonstrate the EOF example (did not timeout but did not match)
import sys
import asyncio
import pexpect
async def work(timeout):
package main
import (
"fmt"
"time"
"github.com/bytecodealliance/wasmtime-go"
)
func prepare(wasmfile string) (*wasmtime.Store, *wasmtime.WasiInstance, *wasmtime.Module) {
#![deny(warnings)]
use hyper::service::{make_service_fn, service_fn};
use hyper::{Client, Server, Body, Request, Result, Response, StatusCode};
async fn handle(req: Request<Body>) -> Result<Response<Body>> {
match req.uri().path() {
"/ping" => {
Ok(handle_ping())
@avidal
avidal / remove-facebook-photos.js
Last active February 7, 2017 15:47
public snippets
/* Remove facebook photos
Just run the below snippet on the console after browsing to Your Photos (click Photos, then Your Photos)
It kind of works on videos with a couple of caveats: need to change data-action-type to delete_video,
and change contains('button') to select 'Confirm' instead of 'Delete'
However, FB reloads the page after removing each video so it can't be run in a loop
*/
function contains(selector, text) {
@avidal
avidal / 1.png
Last active August 29, 2015 14:04
flexbox footer avatar thing
1.png
@avidal
avidal / gist:b5e2af4e2f618254a0ab
Created July 28, 2014 16:11
amazon url regex
(?:https?://)?(?:[a-zA-Z0-9\-]+\.)?(?:amazon|amzn){1}\.(?P<tld>[a-zA-Z\.]{2,})\/(gp/(?:product|offer-listing|customer-media/product-gallery)/|exec/obidos/tg/detail/-/|o/ASIN/|dp/|(?:[A-Za-z0-9\-]+)/dp/)?(?P<ASIN>[0-9A-Za-z]{10})
I created this a number of years ago for an irc bot (https://github.com/rmmh/skybot) to recognize amazon urls. Keep forgetting to hang onto it.
### Keybase proof
I hereby claim:
* I am avidal on github.
* I am avidal (https://keybase.io/avidal) on keybase.
* I have a public key whose fingerprint is 33DC 0060 F0E3 A0AE FD9F 6DB8 4980 1044 EFC3 E5F6
To claim this, I am signing this object:
@avidal
avidal / gist:4216238
Created December 5, 2012 15:07
Clear up the backlog in the selected channel in irccloud
var msgs = cb().messages;
var lim = 200 /* max of 200 entries in the backlog */;
var arr = msgs.toArray().slice(0, msgs.size() - lim);
_.each(arr, function(m) {
$('div[data-eid='+m.get('eid')+']').remove();
msgs.remove(m);
})
#!/usr/bin/env python
import os
j = lambda *p: os.path.join(*p)
# Permanent directory paths are $goodroot/$album
GOOD_ROOT = u"/media/raid/music"
import subprocess
from StringIO import StringIO
class XmpFile(object):
def __init__(self, path, flags, *mode):
# Store the path as an instance property for later
self.path = "." + path
self.file = os.fdopen(open(self.path, flags, *mode),
flag2mode(flags))