This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Calculates the estimated brightness of an Android Bitmap. | |
pixelSpacing tells how many pixels to skip each pixel. Higher values result in better performance, but a more rough estimate. | |
When pixelSpacing = 1, the method actually calculates the real average brightness, not an estimate. | |
This is what the calculateBrightness() shorthand is for. | |
Do not use values for pixelSpacing that are smaller than 1. | |
*/ | |
public int calculateBrightnessEstimate(android.graphics.Bitmap bitmap, int pixelSpacing) { | |
int R = 0; int G = 0; int B = 0; | |
int height = bitmap.getHeight(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
pixelSpacing tells how many pixels to skip each pixel. | |
If pixelSpacing > 1: the average color is an estimate, but higher values mean better performance | |
If pixelSpacing == 1: the average color will be the real average | |
If pixelSpacing < 1: the method will most likely crash (don't use values below 1) | |
*/ | |
public int calculateAverageColor(android.graphics.Bitmap bitmap, int pixelSpacing) { | |
int R = 0; int G = 0; int B = 0; | |
int height = bitmap.getHeight(); | |
int width = bitmap.getWidth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var matches = function(string, q) { | |
q = q.toLowerCase().replace(/[^\w]/g, ''); | |
var inner = function(string, q) { | |
if (q.length) { | |
var i = string.indexOf(q[0]); | |
return i > -1 ? inner(string.substr(i), q.substr(1)) : false; | |
} | |
return true; | |
}; | |
return inner(string.toLowerCase(), q); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Waveform drawer</title> | |
</head> | |
<body> | |
<input type="file" /><br /> | |
<svg preserveAspectRatio="none" width="2000" height="100" style="width:900px;height:50px;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | |
<linearGradient id="Gradient" x1="0" x2="0" y1="0" y2="1"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Store { | |
constructor() { | |
reaction( | |
() => [this.filter, this.limit, this.order], | |
() => this.getItems() | |
); | |
this.getItems(); | |
} | |
@observable filter = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const slots = [50, 40, 200, 300, 400].sort((a, b) => a < b); | |
const slotSum = slots.reduce((sum, s) => sum + s, 0); | |
const random = () => { | |
const r = Math.random() * slotSum; | |
for (let i = 0, c = 0; i < slots.length; i++) { | |
c += slots[i]; | |
if (r < c) { | |
return i; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const updateReason = fn => | |
function(prevProps, prevState) { | |
const isEqual = (a, b) => { | |
if (a === null || b === null || a === undefined || b === undefined) { | |
return a === b; | |
} else if (a.constructor === Object && b.constructor === Object) { | |
const keysA = Object.keys(a).sort(); | |
const keysB = Object.keys(b).sort(); | |
if (keysA.join(',') === keysB.join(',')) { | |
return keysA.every(key => isEqual(a[key], b[key])); |