Skip to content

Instantly share code, notes, and snippets.

View kosso's full-sized avatar

Kosso kosso

View GitHub Profile
// Creates our main root window. Fullscreen all the way!
var win = require('/ui/common/window_home').createWindow();
if(Ti.Platform.osname==='android'){
// This Theme makes sure the windows are full screen and buttons aren't always in caps.
// mytheme.xml lives in /platform/android/res/values - see below.
win.open({theme: "MyAmazingTheme"});
} else {
var rootNavWin = Titanium.UI.iOS.createNavigationWindow({
@kosso
kosso / svgfixer.js
Created March 28, 2017 15:20 — forked from leonderijke/svgfixer.js
Fixes references to inline SVG elements when the <base> tag is in use.
/**
* SVG Fixer
*
* Fixes references to inline SVG elements when the <base> tag is in use.
* Firefox won't display SVG icons referenced with
* `<svg><use xlink:href="#id-of-icon-def"></use></svg>` when the <base> tag is on the page.
*
* More info:
* - http://stackoverflow.com/a/18265336/796152
* - http://www.w3.org/TR/SVG/linking.html
@kosso
kosso / gist:614ff574b14389b2426c6c6b5792487f
Last active March 24, 2017 12:43
Titanium iOS SDK hack to allow picking animated GIFs from Camera Roll
// Add before the sendPickerSuccess in MediaModule.m
// ~ line 2104
// Provides event.gifmedia with the success event if a GIF is picked as a TiBlob.
// If so, the event.media is the first frame as a PNG.
// Kosso
// See if it's a GIF. Use the referenceURL
NSURL *referenceURL = [editingInfo objectForKey:UIImagePickerControllerReferenceURL];
NSString *_mime = [Mimetypes mimeTypeForExtension:[referenceURL path]];
@kosso
kosso / gist:513b9f94c6a1f39c163d8d45ee0e3f21
Created March 21, 2017 21:54
LetsEncrypt autorenewal
LetsEncrypt Autorenewal
-----------------------
Let's say you created and installed an Apache certificate with:
./certbot-auto -n --apache --agree-tos -m your@email.com -d yourdomain.com -d www.yourdomain.com
Create a file called 'letsencrypt-autorenew' (or anything really)
@kosso
kosso / custom-types-and-fields.php
Last active April 29, 2024 05:33
An example Wordpress (4.7+) plugin to create custom post types with custom taxonomies and custom meta fields, including exposing these to the REST API and adding custom columns in admin.
<?php
/**
* Plugin Name: Custom Post Types Example
* Description: An example plugin to create custom post types with custom taxonomies and custom meta fields, including exposing to the REST API.
* Plugin URI: http://kosso.co.uk
* Version: 1.0.0
* Author: Kosso
* Author URI: http://kosso.co.uk
* License: GPLv2
* Network: true
@kosso
kosso / gist:8be491cb03d6b49d256a1a1d3d590918
Last active January 16, 2017 17:26
Example Custom Post Type with REST API support
<?php
/**
* Plugin Name: Custom Post Types
* Description: Custom post types plugin.
* Plugin URI: http://kosso.co.uk
* Version: 1.0.0
* Author: Kosso
* Author URI: http://kosso.co.uk
* License: Free
* Network: true
// Fisheye to spherical conversion
// Assumes the fisheye image is square, centered, and the circle fills the image.
// Output (spherical) image should have 2:1 aspect.
// Strange (but helpful) that atan() == atan2(), normally they are different.
kernel vec4 fish2sphere(sampler src)
{
vec2 pfish;
float theta,phi,r;
vec3 psph;
function __image main(__image src) {
return fish2sphere.apply(src.definition, null, src);
}
////////
kernel vec4 fish2sphere(sampler src)
{
vec2 pfish;
#!/usr/bin/env python
import SimpleHTTPServer
# Simple web server with caching disabled (useful for development)
class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
@kosso
kosso / random_colours.html
Created November 19, 2016 12:42
Generate a random HEX background colour with the appropriate black/white text colour by determining the luminance of the generated colour.
<html>
<head>
<title>Random background colours with appropriate text colour.</title>
<script type="text/javascript">
function randomColor(){
return '#'+(function lol(m,s,c){return s[m.floor(m.random() * s.length)] + (c && lol(m,s,c-1));})(Math,'0123456789ABCDEF',4);
}