Skip to content

Instantly share code, notes, and snippets.

@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.
/*
Example that utilizes FileSystem API and Web Workers.
Creates a lib.js and worker.js in a temporary file system, then creates a web worker for worker.js that imports lib.js from the local filesystem.
The start of something beautiful?
*/
var fs, liburl, worker = null;
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 / get_permissions.py
Created January 14, 2011 21:26
This snippet will get all permission objects for a specific model.
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from myapp.models import MyModel
content_type = ContentType.objects.get_for_model(MyModel)
permissions = Permission.objects.filter(content_type=content_type)
@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 / 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))
/\b[\w.%+!]+@(?:[^\s`!()\[\]{};:'",<>?«»“”‘’]+[.])+(?:AC|AD|AE|AERO|AF|AG|AI|AL|AM|AN|AO|AQ|AR|ARPA|AS|ASIA|AT|AU|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BIZ|BJ|BM|BN|BO|BR|BS|BT|BV|BW|BY|BZ|CA|CAT|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|COM|COOP|CR|CU|CV|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EDU|EE|EG|ER|ES|ET|EU|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GOV|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|INFO|INT|IO|IQ|IR|IS|IT|JE|JM|JO|JOBS|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|ME|MG|MH|MIL|MK|ML|MM|MN|MO|MOBI|MP|MQ|MR|MS|MT|MU|MUSEUM|MV|MW|MX|MY|MZ|NA|NAME|NC|NE|NET|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|ORG|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PRO|PS|PT|PW|PY|QA|RE|RO|RS|RU|RW|SA|SB|SC|SD|SE|SG|SI|SJ|SK|SL|SM|SN|SO|SR|ST|SU|SV|SY|SZ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