Skip to content

Instantly share code, notes, and snippets.

<h1>Cats</h1>
<a id='meow' href='#'>its the cats</a><br>
<form id='cat-form'>
<input type='text' name='name' placeholder='name'><br>
<input type='text' name='product' placeholder='product'><br>
<input id='add-cat' type='submit'>
</form>
@data-doge
data-doge / gist:26f143fe6ce5ddb61077
Created April 1, 2015 06:15
ajax-example javascript
$(document).ready(function() {
$('#meow').click(function(e) {
e.preventDefault();
console.log("WE ARE NOT BEING REDIRECTED, yes");
$.ajax({
type : 'GET',
url : '/cats',
{
cats: [
{
id: 1,
name: "Pierre O'Reilly V",
product: "Small Cotton Car"
},
{
id: 2,
name: "Gabriel Prohaska I",
@data-doge
data-doge / gist:99045260238f76e63954
Created April 2, 2015 00:31
ajax-example-html refactored
<h1>Cats</h1>
<p id='notification'></p>
<a id='get-cats-button' href='#'>its the cats</a><br>
<form id='new-cat-form'>
<input type='text' name='name' placeholder='name'><br>
<input type='text' name='product' placeholder='product'><br>
<input type='submit'>
@data-doge
data-doge / gist:5018a4ad0487cfe07849
Created April 2, 2015 00:32
ajax-example-javascript refactored
$(document).ready(function() {
$('#get-cats-button').click(function(e) {
e.preventDefault();
$.ajax({
type : 'GET',
url : '/cats',
success : function(res) {
var cats = JSON.parse(res);
$('#cat-container').empty();
@data-doge
data-doge / gist:015a4a9fe96ae1b0f649
Created April 6, 2015 06:47
ajax example geordi
$(document).ready(function() {
$('#new-item-form').on('submit', function (e) {
e.preventDefault();
var data = $(e.target).serialize();
$.ajax({
type: 'POST',
url: '/api/items',
data: data,
@data-doge
data-doge / gist:c3bef91283aaec409f57
Last active August 29, 2015 14:19
controller testing sinatra example
#### CONTROLLER ####
get '/cats' do
@cats = Cat.all
erb :index
end
post '/cats' do
cat = Cat.new(name: params[:name], product: params[:product])
cat.save ? (redirect '/cats') : (status 400)
function Cell () {
this.alive = Math.random() > 0.7;
this.neighbors = 0;
}
function Conway (size) {
this.size = size;
this.grid = this.generateGrid(size);
this.directions = [ [-1,-1], [-1, 0], [-1, 1], [ 0,-1], [ 0, 1], [ 1,-1], [ 1, 0], [ 1, 1] ];
}
@data-doge
data-doge / index.html
Last active August 29, 2015 14:19
ajax-example
<h1>cats</h1>
<a id='get-cats' href='#'>get cats</a>
<ul id='cats-container'></ul>
<form id='new-cat-form'>
<input type='text' name='name' placeholder='name'>
<input type='text' name='bitcoin' placeholder='bitcoin'>
<input type='submit'>
@data-doge
data-doge / gist:dcee50f18cd28aca61fd
Created May 5, 2015 03:13
enumerables and roman numerals examples
array = ["9","8","7","6","5","4","3","2"]
array.length.times { |i| p array[i] }
array.each { |char| p char }
array.each_with_index { |char,i| p "#{char} || #{i}" }
matrix = Array.new(10) { Array.new(10) {"a"}}