Skip to content

Instantly share code, notes, and snippets.

View pixelhandler's full-sized avatar
🍊
Working remotely

Bill Heaton pixelhandler

🍊
Working remotely
View GitHub Profile
@pixelhandler
pixelhandler / pre-push.sh
Last active April 8, 2024 01:04
Git pre-push hook to prevent force pushing master branch
#!/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
# 1. Copy the file into your repo at `.git/hooks/pre-push`
# 2. Set executable permissions, run `chmod +x .git/hooks/pre-push`
var application_root = __dirname,
express = require("express"),
path = require("path"),
mongoose = require('mongoose');
var app = express.createServer();
// database
mongoose.connect('mongodb://localhost/ecomm_database');
@pixelhandler
pixelhandler / images_loaded.js
Created July 14, 2011 04:12
Images loaded or not? Check with JavaScript
// Check if images load properly
// returns false if image not loaded
function imgOK(img) {
if (!img.complete) {
return false;
}
if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
return false;
}
return true;
@pixelhandler
pixelhandler / gist:d773fb3cfcf1a345014d75e43da65b77
Created January 15, 2019 00:11
JavaScript Generators and Concurrency
# JavaScript Generators and Concurrency
1. Why generators are a nice fit for handling a coroutine (source/sink)
2. How we use generators in the Dashboard app
3. What generators can do to help wrangle async behavior
Generators are functions that can be paused and resumed (think cooperative multitasking or coroutines)
Pitch:
@pixelhandler
pixelhandler / ember-rails-scaffold.md
Last active August 20, 2021 23:06
Scaffold for a browser app build with Ember.js, Rails, Ember.Data

Scaffold for a browser app build with Ember.js, Rails, Ember.Data

Journal App

This is a scaffold for setting up: an API with Rails and the ember-rails gem, persistence with Ember.Data, and a browser app using Ember.js

See source code on GitHub: pixelhandler/journal.

import Ember from 'ember';
import layout from '../templates/components/toggle-pill';
const CHECKED = 'checked';
export default Ember.Component.extend({
layout,
inputId: 123,
// Component properties
@pixelhandler
pixelhandler / hijack_form_submit.js
Created July 14, 2011 04:10
Hijack form’s submit onclick, validate, and use enter key to post form
// using jQuery library and validation plugin in this code
// for checking keycodes
function getKeyCode(event) {
var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
return keycode;
}
// is there an anchor as Submit button?
var $submit = $('a[id$="_submit"]');
// is there any behavior already on submit, like -> onclick="__doPostBack(...)"
@pixelhandler
pixelhandler / application.controller.js
Last active December 28, 2020 09:40
Loading with Nested Routes
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
@pixelhandler
pixelhandler / controllers.index.js
Last active October 18, 2019 15:53
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
matcher(item, query) {
let rating = item.get('rating');
return rating.toLowerCase().indexOf(query.toLowerCase());
},
actions: {
@pixelhandler
pixelhandler / bootstrap.js
Created February 26, 2012 02:12
Product API example using Backbone.js Models, Views and Collections
// bootstrap
PX.app = new PX.App();
Backbone.history.start();