Skip to content

Instantly share code, notes, and snippets.

View crobinson42's full-sized avatar
🏠
Working from home

Cory Robinson crobinson42

🏠
Working from home
  • American Software
  • Northwest USA
View GitHub Profile
@crobinson42
crobinson42 / in-place-edit
Last active August 29, 2015 14:03
(jQuery) Edit Element in-place
// ****Copy and paste in script tags in an empty HTML page****
//
// - When you click on a button it turns into an input field,
// - you can edit the text and press "enter" to switch back
// - to a button
//
$(document).on('ready', function() {
// Make buttons and append it to the DOM
$('body').prepend('<button class="button">This is a Button!</button>');
@crobinson42
crobinson42 / custom-event-counter
Created June 28, 2014 16:24
Custom Event Counter
//
// Custom event - counter
// Emits data: startTime, startCount & count
//
var emitCounter= function(){
var currentCount = 0,
date = new Date(),
startTime = date.getTime();
var store = new JSData.DS();
store.registerAdapter('http', new DSHttpAdapter(), { default: true });
var User = store.defineResource({
name : 'user',
bypassCache : true,
relations: {
Warning: React can't find the root component node for data-reactid value `.5.1`. If you're seeing this message, it probably means that you've loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.warning @ bundle.js:60215ReactMount.findComponentRoot @ bundle.js:52740ReactMount.findReactNodeByID @ bundle.js:52707getNode @ bundle.js:52190executeDispatch @ bundle.js:44197executeDispatchesInOrder @ bundle.js:44221executeDispatchesAndRelease @ bundle.js:43664executeDispatchesAndReleaseTopLevel @ bundle.js:43675forEachAccumulated @ bundle.js:57576EventPluginHub.processEventQueue @ bundle.js:43880runEventQueueInBatch @ bundle.js:51159ReactEventEmitterMixin.handleTopLevel @ bundle.js:51175handleTopLevelWithoutPath @ bundle.js:51273handleTopLevelImpl @ bundle.js:51253Mixin.perform @ bundle.js:57058ReactDefaultBatchingStrategy.batchedUpdates @ bundle.js:49890batchedUpdates @ bundle.js:55134ReactEventListener.dispatchEvent @ bundle.js:51384
bundle.js:52743 Uncaught Typ
@crobinson42
crobinson42 / gist:458043e2079bb1799e56
Created January 1, 2016 05:21
React-Bootstrap Modal dynamic mount/dismount from page
/*
Create and attach
*/
var el;
el = document.createElement('div');
el.id = "MyReactModalView";
document.getElementsByTagName('body')[0].appendChild(el);
ReactDOM.render(<MyReactModalView />, document.querySelector('#MyReactModalView'));
/**
* ValidationMessagesView
* Shows a bootstrap alert panel with validation messages. Expects props to be
* an array.
*/
var React = require('react');
var Alert = require('react-bootstrap').Alert;
@crobinson42
crobinson42 / Query.js
Last active January 15, 2016 18:07
Sailsjs model association query
Report
.find({where: {users: "562ed24a11ea954b36f20f74" }})
.populate('users')
.exec(function (err, reports) {
console.log(reports);
});
@crobinson42
crobinson42 / Reports.js
Created January 15, 2016 20:03
SailsJs Querying Model Associations Workaround - using json attribute and find() 'contains'
module.exports = {
attributes: {
users : {
type : 'json',
defaultsTo : []
}
/*
This will create a file and trigger a download for the user.
*/
var a = window.document.createElement('a');
a.href = window.URL.createObjectURL(new Blob(['This is the text in the file..'], {type: 'text/html'}));
a.download = 'filename_test.html';
// Append anchor to body.
document.body.appendChild(a)
@crobinson42
crobinson42 / http.js
Created February 13, 2016 04:23
Add custom param to each request in Sails.js
/**
* HTTP Server Settings
* (sails.config.http)
* sails_project/config/http.js
*
* Sails.js v.11.*
*/
module.exports.http = {