Skip to content

Instantly share code, notes, and snippets.

View wichert's full-sized avatar

Wichert Akkerman wichert

View GitHub Profile
@wichert
wichert / iq_roster.go
Created December 19, 2019 09:26
go-xmpp roster
package stanza
import (
"encoding/xml"
"gosrc.io/xmpp/stanza"
)
const NSRoster = "jabber:iq:roster"
@wichert
wichert / xmppjs-rn.js
Last active December 4, 2019 08:29
React Native / xmppjs test
import React, { useEffect, useState } from "react";
import { AppState, StyleSheet, Text, View, Button } from "react-native";
import { client } from "@xmpp/client/react-native";
import xml from "@xmpp/xml";
const CREDENTIALS = [
{
name: "Arwen",
username: "4h9rd2yd3t58fbwxe257rvjd6",
password: "S7yZBsDIe7boi6ruVhhioGHzM6YW6vboMnmlguS5BUU="
import logging
import os
from pyramid.httpexceptions import WSGIHTTPException
from pyramid.tweens import EXCVIEW
from raven import Client
from raven import fetch_package_version
from raven.utils.wsgi import get_environ
try:
from raven.contrib.celery import register_signal, register_logger_signal
import celery # NOQA
@wichert
wichert / ably.js
Created November 21, 2017 10:39
Ably connection setup
// @flow
import * as Ably from 'ably'
import type Channel from 'ably/common/lib/client/channel'
import type ConnectionStateChange from 'ably/common/lib/client/connectionstatechange'
// import type ErrorInfo from 'ably/common/lib/types/errorinfo'
import winston from 'winston'
import EventEmitter from 'events'
type AuthHeaders = {[string]: string}
@wichert
wichert / celery.py
Last active March 23, 2018 12:51
Pyramid / celery integration example
import os
import sys
import venusian
import jzoo.tasks as jzoo_tasks
from celery import Celery
from celery import signals
from celery.bin import Option
from pyramid.paster import bootstrap, get_appsettings
from pyramid.scripting import prepare
import transaction
@wichert
wichert / README.md
Created March 3, 2017 17:01
python async subprocess test

To run the example:

python3 server.py &
python3 client.py

I would expect the output to look like this:

@wichert
wichert / cookie.py
Created May 19, 2016 12:07
Better cookie handling for Pyramid
@wichert
wichert / mac.py
Created January 25, 2016 12:44
Python example for http://macvendors.co/
>>> import pprint
>>> import requests
>>> MAC_URL = 'http://macvendors.co/api/%s'
>>> r = requests.get(MAC_URL % 'BC:92:6B:A0:00:01')
>>> pprint.pprint(r.json())
{'result': {'address': '1 Infinite Loop Cupertino CA US 95014 ',
'company': 'Apple, Inc.',
'mac_prefix': 'BC:92:6B'}}
@wichert
wichert / markdown.py
Created November 16, 2015 14:36
Markdown rendering in Chameleon
# This module allows you to use markdown in Chameleon templates from pyramid.
#
# Markdown rendering is only down for text that is translatable, and has its
# message context set to ``markdown``. This is a complete abuse of the translation
# system, but currently provides the simplest way to get markdown running in
# Chameleon.
import CommonMark
from chameleon.utils import Markup
from translationstring import ChameleonTranslate
from pyramid_chameleon.localization import translator
@wichert
wichert / crop.js
Created July 31, 2015 12:22
JavaScript function to dynamically crop text
// Look for all elements with a clip class, and remove words form them
// until the text fits in the available space. This requires the element
// to have a fixed (maximum) width and height.
function cropText(root) {
var victims = root.querySelectorAll(".clip"),
rest, html, victim, $victim, words, cropped;
for (var i=0; i<victims.length; ++i) {
$victim=$(victim=victims[i]);
// We can only measure when the item is visible, but make it transparent