Skip to content

Instantly share code, notes, and snippets.

View James1x0's full-sized avatar
Building

James James1x0

Building
View GitHub Profile
@James1x0
James1x0 / indexof.hbs
Created January 5, 2015 21:29
Index from itemController
{{#each foo in content}}
foo{{foo.fooIndexComputed}}
{{#each bar in foo.bar}}
bar{{bar.barIndexComputed}} of foo{{foo.fooIndexComputed}}
{{/each}}
{{/each}}
<!--
foo0
bar0 of foo0
bar1 of foo0
@James1x0
James1x0 / wp-ffmpeg-thumbnail
Created January 7, 2014 20:03
Wordpress Thumbnail Generation with ffmpeg-php.
function ExtractThumb($in, $out) {
$thumb_stdout;
$errors;
$retval = 0;
// Delete the file if it already exists
if (file_exists($out)) { unlink($out); }
// Use ffmpeg to generate a thumbnail from the movie
$cmd = "ffmpeg -i $in -ss 00:00:01 -f image2 -vframes 1 -s 300x200 $out";
exec($cmd, $thumb_stdout, $retval);
// Queue up the error for processing
@James1x0
James1x0 / run-along.js
Last active January 11, 2016 18:31
Neat little random array generator I came up with for a thought experiment.
function runAlongFolks ( init, iter, deviation ) {
var n = init || 150,
arr = [];
for ( var i = 0; i < iter; i++ ) {
var a = Math.floor(Math.random() * (deviation - (-deviation) + 1)) - deviation;
arr.push(n);
n += a;
}

Each config gets called with:

  var mod = require(conf.directory);

  if ( conf.crud ) {
    methodMixins(mod, conf);
  }

 app.use(mount('/api/v1', Resource(conf.name, mod).middleware()));
✓ should POST new records
mocha:runner run suite Acceptance :: Resource :: Payment Method GET /payment-methods/:id +1ms
GET /payment-methods/:id
koa:application use responseTime +0ms
koa:application use compress +0ms
koa:application use bodyParser +0ms
koa:application use - +0ms
koa:application use dispatch +0ms
koa:application use - +0ms
debug: routes: bt
@James1x0
James1x0 / components.x-test.js
Created December 15, 2016 22:20
updateattrs?
import Ember from 'ember';
export default Ember.Component.extend({
updates: Ember.A(),
didReceiveAttrs () {
this._super(...arguments);
this.get('updates').pushObject('didReceiveAttrs ' + new Date());
},
@James1x0
James1x0 / emberscrollspy.js
Last active January 30, 2017 17:28
Ember Scrollspy
import Ember from 'ember';
import windowBinderMixin from '../mixins/window-binder';
export default Ember.View.extend(windowBinderMixin, {
templateName: 'scroll-spy',
classNames: [ 'scroll-spy-view', 'affix' ],
// Bind the window events on view insertion
didInsertElement: function () {
this.setupWindowBindings();
@James1x0
James1x0 / unokata.js
Created April 22, 2022 18:24
I play next on a reverse in uno, change my mind
let currentTurn = 3;
const players = [
'you',
'someone',
'me'
];
function logCurrentPlayer () {
return players[(currentTurn % players.length) - 1];
}
@James1x0
James1x0 / momentjs.humanized.triplesplit.time.js
Created January 15, 2014 19:42
Get a humanized, "Morning", "Afternoon", "Evening" from moment.js **Great for user greetings!**
function getGreetingTime (m) {
var g = null; //return g
if(!m || !m.isValid()) { return; } //if we can't find a valid or filled moment, we return.
var split_afternoon = 12 //24hr time to split the afternoon
var split_evening = 17 //24hr time to split the evening
var currentHour = parseFloat(m.format("HH"));
if(currentHour >= split_afternoon && currentHour <= split_evening) {