Skip to content

Instantly share code, notes, and snippets.

View Ripley6811's full-sized avatar

Jay W Johnson Ripley6811

View GitHub Profile
@Ripley6811
Ripley6811 / gist:3735758
Created September 17, 2012 05:50
PIL image to CV2 image
# PIL RGB 'im' to CV2 BGR 'imcv'
imcv = np.asarray(im)[:,:,::-1].copy()
# Or
imcv = cv2.cvtColor(np.asarray(im), cv2.COLOR_RGB2BGR)
# To gray image
imcv = np.asarray(im.convert('L'))
# Or
imcv = cv2.cvtColor(np.asarray(im), cv2.COLOR_RGB2GRAY)
@Ripley6811
Ripley6811 / python_cv2_feature_detection.py
Created October 11, 2012 08:17
Python+OpenCV feature detection
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tests the various feature detector algorithms in OpenCV 2.4 on one image
@SINCE: Thu Sep 13 23:01:23 2012
@VERSION: 0.1
@REQUIRES: OpenCV 2.4 (I used 2.4.0), matplotlib
@Ripley6811
Ripley6811 / EXIF after PIL.py
Created April 1, 2013 08:13
ccess EXIF data of images. Preserve EXIF data after PIL manipulation of an image. Requires exiftool.exe. Download from http://www.sno.phy.queensu.ca/~phil/exiftool/
'''
Preserve EXIF data after PIL manipulation of an image.
Requires exiftool.exe. Download from http://www.sno.phy.queensu.ca/~phil/exiftool/
Basically, do not save the manipulated image over the old image. Exiftool can
copy the data from old to new.
'''
from PIL import Image
import subprocess
@Ripley6811
Ripley6811 / IDL_crop_ASCAT_location
Created July 18, 2013 03:52
IDL code for reducing ASCAT data to a bounded area
function crop_ASCAT_location, data, lon_bounds=lon_bounds, lat_bounds=lat_bounds
n = N_ELEMENTS(data.lon)
c = 0 ; count
for i=0l, n-1 do begin
print, data.lon[i]
if data.lon[i] ge lon_bounds[0] and data.lon[i] le lon_bounds[1] $
and data.lat[i] ge lat_bounds[0] and data.lat[i] le lat_bounds[1] $
@Ripley6811
Ripley6811 / index.html
Created August 6, 2013 07:04
A CodePen by Jay W Johnson. Boy in the rain - CreateJS and Box2DWeb example. Raindrops are small circular dynamic bodies. Umbrella is a kinematic body (ignores gravity).
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript" src="https://dl.dropboxusercontent.com/u/49722688/packages/Box2dWeb-2.1.a.3.min.js"></script>
</body>
</html>
@Ripley6811
Ripley6811 / Grue.js
Last active December 20, 2015 16:59
Basic HTML5/Canvas setup with CreateJS. Full page canvas for games, demos, or other effects.
"use strict";
// Create a `Player` class that inherits from `createjs.Shape`.
function Grue() {
// This example object will display a circle with a transparency gradient
// The center is transparent and becomes solid blue at edges.
this.graphics.beginStroke("#F0F") // Purple edge.
.beginRadialGradientFill(
["rgba(0,0,0,0.2)","rgba(0,0,255,1)"], // colors: [center, edge]
[0,1], // gradient: [begin, end]
@Ripley6811
Ripley6811 / BurningPlain.js
Last active December 23, 2015 23:19
Demo of using a animated canvas element as a texture on a webgl (Three.js) object surface.
"use strict";
// Create a class that draws to a canvas.
function BurningPlain(canvas) {
this.w = canvas.width;
this.h = canvas.height;
this.ctx = canvas.getContext("2d");
// Draw buffer
var buffer = this.buffer = document.createElement('canvas');

This is a personalized reference for functions I have used. Any excluded parameters or simplifications are intentional.


##Function Summary

function param1 param2 response
.find PK or {} NA [{}]
.findOrCreate PK or {} {} {}
.destroy PK or {} NA [{}]
@Ripley6811
Ripley6811 / ko_extend_numeric.js
Last active August 29, 2015 14:14
KnockoutJS numeric validation function modified to allow a single period.
// Modified version of code at http://knockoutjs.com/documentation/extenders.html
// Allow a single period to pass when using "textInput" data-binding.
ko.extenders.numeric = function(target, precision) {
//create a writable computed observable to intercept writes to our observable
var result = ko.pureComputed({
read: target, //always return the original observables value
write: function(newValue) {
console.log(typeof newValue, newValue);
var current = target(),
@Ripley6811
Ripley6811 / nonASCIItext.js
Last active August 9, 2022 08:27
Add non-ASCII text as images to jsPDF. Use for Chinese characters and more. If canvas can draw it, then it can be added to jsPDF.
/**
* Prints a line of non-ASCII text as a series of images.
* All doc.text methods can be replaced with this method.
* Works like doc.text but requires a fontsize (default is 10).
*
* Add function to jsPDF instance (do not overwrite doc.text):
* var doc = new jsPDF();
* doc.alttext = nonASCIItext;
*
* @param {Number} x Horizontal placement