Skip to content

Instantly share code, notes, and snippets.

View sonnyp's full-sized avatar
🛠️

Sonny sonnyp

🛠️
View GitHub Profile
#!/usr/bin/env gjs
const { GLib, GUPnP } = imports.gi;
const { MainLoop } = GLib;
const mainloop = new MainLoop(null, true);
function getExternalIpAddress() {
// does it work with interface: null or without
import {AppState} from 'react-native';
import xml from './xmpp/packages/xml';
// https://xmpp.org/extensions/xep-0352.html
// https://facebook.github.io/react-native/docs/appstate
module.exports = function csi({entity}) {
let supported = false;
let inactive = false;
@sonnyp
sonnyp / XHTML5.xhtml
Last active April 18, 2019 08:48
XHTML5 template
<?xml version="1.0" encoding="utf-8"?>
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8"/>
<title>TITLE</title>
<meta name="description" content="$DESCRIPTION"/>
<meta name="author" content="$AUTHOR"/>
function fixedEncodeURIComponent(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, (c) => {
return `%${c.charCodeAt(0).toString(16)}`;
});
}
function urlEncode(params) {
let data = '';
Object.keys(params).forEach((key, idx, { length }) => {
const k = fixedEncodeURIComponent(key.toString());
@sonnyp
sonnyp / bind.xml
Created June 6, 2016 14:41
prosody bind issue
<!-- OUT -->
<iq to="localhost" type="set" id="40924263533590377" xmlns="jabber:client">
<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>
</iq>
<!-- IN -->
<iq id="40924263533590377" type="error" xmlns="jabber:client" from="localhost">
<error type="cancel">
<service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
@sonnyp
sonnyp / HTML5.html
Last active April 17, 2016 16:14
HTML5 template
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>TITLE</title>
<meta name="description" content="$DESCRIPTION">
<meta name="author" content="$AUTHOR">
<meta name="keywords" content="$KEYWORDS">
@sonnyp
sonnyp / iife.js
Last active April 13, 2016 13:18
JavaScript IIFE for Node.js and browsers
// global will refer to global for Node.js and window for browsers
;(function (global) { // ; in case the file is concatenated with a non ; line ending
'use strict'
// your code
}(typeof global !== 'undefined' ? global : this)) // `this`doesn't refer to global in Node.js module
@sonnyp
sonnyp / .editorconfig
Created January 8, 2016 23:19
.editorconfig
# EditorConfig is awesome: http://EditorConfig.org
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
indent_style = space
/*
A simple new-line delimited JSON protocol with upgrades.
Receiving Usage:
protocol = require('./frame-protocol');
// parsing data
parser = protocol.Parser();
// This code co-ordinates tabs from the same domain to elect one of them as a
// "master", and allow them to broadcast messages to each other.
function WindowController () {
var now = Date.now(),
ping = 0;
try {
ping = +localStorage.getItem( 'ping' ) || 0;
} catch ( error ) {}
if ( now - ping > 45000 ) {
this.becomeMaster();