Skip to content

Instantly share code, notes, and snippets.

@chico
chico / localStorageSize.js
Created Apr 11, 2019
Get the size of localStorage, copied from https://stackoverflow.com/a/15720835, execute it in the JavaScript console
View localStorageSize.js
var _lsTotal=0,_xLen,_x;for(_x in localStorage){ if(!localStorage.hasOwnProperty(_x)){continue;} _xLen= ((localStorage[_x].length + _x.length)* 2);_lsTotal+=_xLen; console.log(_x.substr(0,50)+" = "+ (_xLen/1024).toFixed(2)+" KB")};console.log("Total = " + (_lsTotal / 1024).toFixed(2) + " KB");
@chico
chico / firefox_osx_alias_command.sh
Last active Jan 11, 2019
firefox osx alias command
View firefox_osx_alias_command.sh
alias firefox="open -a Firefox 'https://www.bbc.com' && open -a Firefox 'https://flipboard.com' && open -a Firefox 'https://twitter.com' && open -a Firefox 'http://producthunt.com' && open -a Firefox 'https://blog.codinghorror.com'"
@chico
chico / MainActivity.java
Created Mar 22, 2018
CIFAR_10 Android Fix for Mammoth Interactive's Mobile Learning course
View MainActivity.java
private float[] formatImageData() {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), imageResouceIds[imageArrayIndex]);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 32, 32, true);
int[] intArray = new int[1024];
scaledBitmap.getPixels(intArray, 0, 32, 0, 0, 32, 32);
float[] floatArray = new float[3072];
int n = 0;
for (int i = 0; i < 1024; i++) {
floatArray[n++] = ((intArray[i] >> 16) & 0xff) / 255.0f;
floatArray[n++] = ((intArray[i] >> 8) & 0xff) / 255.0f;
View logs.js
var result = {ok: true};
console.dir(result, {depth: null, colors: true});
View mailchimp.js
passport.use(new MailChimpStrategy({
clientID: config.auth.mailchimpAuth.clientID,
clientSecret: config.auth.mailchimpAuth.clientSecret,
callbackURL: config.auth.mailchimpAuth.callbackURL,
passReqToCallback : true
},
function(req, token, refreshToken, profile, done) {
token = token + '-' + profile.dc; // Append datacenter to token for API calls to work
// Save and use token for doing Mailchimp API calls
}
View switch.css
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 1px solid red; border-radius: 20px;
View gist:e186ca17b0536e31bef7302afe076c00
Verifying that +ccharlesworth is my blockchain ID. https://onename.com/ccharlesworth
View pid_test.ino
/********************************************************
* PID Basic Example
* Reading analog input 0 to control analog PWM output 3
********************************************************/
#include <PID_v1.h>
#define PIN_INPUT 0
#define PIN_OUTPUT 3
View robotarm.js
var five = require('johnny-five')
var board = new five.Board()
var moveBase = function(board, base, cb) {
base.to(10, 2000)
board.wait(2500, function () {
base.to(170, 3000)
board.wait(3500, function () {
@chico
chico / MainActivity
Created Oct 31, 2014
GPUImage.saveToPictures blocks UI with preview
View MainActivity
// in onCreate()
glSurfaceView = (GLSurfaceView) findViewById(R.id.surfaceView);
mGPUImage = new GPUImage(this);
mGPUImage.setGLSurfaceView(glSurfaceView);
// on user button click
mCamera.mCameraInstance.takePicture(null, null, new Camera.PictureCallback() {