Skip to content

Instantly share code, notes, and snippets.

View ErikPeterson's full-sized avatar

Ricky Tomatoes ErikPeterson

View GitHub Profile
@ErikPeterson
ErikPeterson / smiley_face.rb
Created February 18, 2014 02:52
Smiley Face Pixel Array
smiley_face = [
[249, 249, 217, 128],
[249, 249, 217, 128],
[249, 249, 217, 128],
[249, 249, 217, 128],
[249, 249, 217, 128],
[249, 249, 217, 128],
[249, 249, 217, 128],
[249, 249, 217, 128],
[249, 249, 217, 128],
@ErikPeterson
ErikPeterson / gist:9064042
Last active August 29, 2015 13:56
PNGarray

PNGarray is a project I've been working on over the past few days. It's a "gem in the rough" that allows one to create and manipulate arrays of RGBA color values, and encode/save them as 8-bit PNG images with full alpha transparency. Right now the functionality is basic, but it can produce some interesting results.

After programming the basic shell of PNGarray, which uses the "png" gem to encode and save images, I wanted to quickly generate images with it to test its functionality. I first used an array of only 4 x 4 pixels. This allowed me to enter the image by hand, and do a fast check on the program. However, the small grid was limiting in terms of seeing what the program could do, so I wanted to create some other data sets to probe the ability of the tools

Considering that even a 16 x 16 pixel image (the size of a favicon) has 1024 pixels, hand entry was not an option. I realized I would have to find a way to programatically assess the color values of an image file and output those values as a nested ar

@ErikPeterson
ErikPeterson / url_reg.rb
Last active August 29, 2015 13:56
Regex for URLs
#/^(\w+\:\/\/)?([\w+|\-\.\w+?\b]*)(:\d{1,5})?(\S*)?/
#When used with the .match method in Ruby on a URL string, this regex produces a Match object
#with the following array of matches: [whole url, protocol, domain, port, relative path]
#Examples (try these out in IRB or Pry):
url_reg = /^(\w+\:\/\/)?([\w+|\-\.\w+?\b]*)(:\d{4})?(\S*)?/
"http://www.google.com/index.html".match(url_reg).to_a.each_with_index do |el, index|
function randElem(){
var els = $('*');
return $( els[Math.floor(Math.random() * els.length)] )
}
function deleteRandElem(){
var el = randElem(),
num = Math.floor(Math.random() * 3000);
el.remove();
function randElem(){
var els = $('*');
return $( els[Math.floor(Math.random() * els.length)] )
}
function deleteRandElem(){
var el = randElem(),
num = Math.floor(Math.random() * 3000);
el.remove();
function randElem(){
var els = $('*');
return $( els[Math.floor(Math.random() * els.length)] )
}
function deleteRandElem(){
var el = randElem(),
num = Math.floor(Math.random() * 3000);
el.remove();
//The body of the html
<body>
<ul id="my-items">
</ul>
<form id="myform">
<input name="myvalue" type="text"></input>
<input type="submit" id="thebutton"></input>
</form>
....
@ErikPeterson
ErikPeterson / gist:cfdbec9ebdbcea1f0f5c
Last active August 29, 2015 14:07
Simple ajax form submit
//right inside of your window.onload function
var formButton = document.querySelector('the_id_of_your_forms_button_here');
formButton.addEventListener('click', function(e){
//stop form from submitting through the browser the default way
e.preventDefault();
var name = document.querySelector('id_of_the_name_field').value;
var address = document.querySelector('id_of_the_address_field').value;

Keybase proof

I hereby claim:

  • I am erikpeterson on github.
  • I am erikpeterson (https://keybase.io/erikpeterson) on keybase.
  • I have a public key whose fingerprint is 3F44 7C80 DBC7 9FAF 8D97 2CDC DAFF 1F4D EA34 C8ED

To claim this, I am signing this object:

@ErikPeterson
ErikPeterson / threevideodemo.js
Last active October 5, 2022 06:53
THREEJS Video Texture Demo
//Set up scene, camera, and renderer
var scene = new THREE.Scene;
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
var renderer = new THREE.CanvasRenderer();
renderer.setClearColor( 0xf0f0f0 );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var video = document.createElement('video');