Skip to content

Instantly share code, notes, and snippets.

View pmallol's full-sized avatar

Paula Mallol pmallol

View GitHub Profile
@redblobgames
redblobgames / remove-alpha-on-canvas.js
Created September 19, 2018 20:41
Remove alpha channel on a canvas, so it's always transparent or always opaque
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const pixels = imageData.data;
for (let i = 3, n = canvas.width * canvas.height * 4; i < n; i += 4) {
pixels[i] = pixels[i] < 127? 0 : 255
}
ctx.putImageData(imageData, 0, 0);
@timdown
timdown / trim_canvas.js
Created July 26, 2017 16:15
Returns a copy of a canvas element with surrounding transparent space removed
var trimCanvas = (function() {
function rowBlank(imageData, width, y) {
for (var x = 0; x < width; ++x) {
if (imageData.data[y * width * 4 + x * 4 + 3] !== 0) return false;
}
return true;
}
function columnBlank(imageData, width, x, top, bottom) {
for (var y = top; y < bottom; ++y) {
@fgilio
fgilio / axios-catch-error.js
Last active April 11, 2024 19:02
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@bcardiff
bcardiff / README.md
Last active November 17, 2015 01:06
p5e1

INTRODUCTION TO PROGRAMMING FOR THE VISUAL ARTS WITH P5.JS

Assignment 1: Port an Image to Code

//Now with less jquery
//1) go to your my-list page, and scroll to the bottom to make sure it's all loaded:
//http://www.netflix.com/browse/my-list
//2) Next, paste this in your developer tools console and hit enter:
[...document.querySelectorAll('.slider [aria-label]')].map(ele => ele.getAttribute('aria-label'))
//or use this to copy the list to your clipboard:
copy([...document.querySelectorAll('.slider [aria-label]')].map(ele => ele.getAttribute('aria-label')))
@clafferty-powa
clafferty-powa / AlphaToBlack
Created January 26, 2015 16:50
Make all pixels with transparency black, and remove their alpha channel on Android Bitmap
// For input image where information is only stored in alpha channel over black RGB.
// Make all pixels with transparency black, and remove alpha channel.
private Bitmap AlphaToBlack(Bitmap image) {
Bitmap rgbImage = image.copy(Bitmap.Config.ARGB_8888, true);
for (int y = 0; y < rgbImage.getHeight(); y++) {
for (int x = 0; x < rgbImage.getWidth(); x++) {
int aPixel = rgbImage.getPixel(x, y);
if (rgbImage.getPixel(x, y) < 0xFF000000)
@impressiver
impressiver / raven-config.html
Last active February 27, 2024 14:27
Raven.js configuration for logging JavaScript exceptions to Sentry (https://getsentry.com/). Without the added ignore options, you'll quickly find yourself swamped with unactionable exceptions due to shoddy browser plugins and 3rd party script errors.
<!-- Raven.js Config -->
<script src="{{ JS_PATH }}/lib/raven.js" type="text/javascript"></script>
<script type="text/javascript">
// Ignore list based off: https://gist.github.com/1878283
var ravenOptions = {
// Will cause a deprecation warning, but the demise of `ignoreErrors` is still under discussion.
// See: https://github.com/getsentry/raven-js/issues/73
ignoreErrors: [
// Random plugins/extensions
'top.GLOBALS',
@remy
remy / trim-canvas.js
Last active May 3, 2024 13:39
Trims the surrounding transparent pixels from a canvas
// MIT http://rem.mit-license.org
function trim(c) {
var ctx = c.getContext('2d'),
copy = document.createElement('canvas').getContext('2d'),
pixels = ctx.getImageData(0, 0, c.width, c.height),
l = pixels.data.length,
i,
bound = {
top: null,