Skip to content

Instantly share code, notes, and snippets.

Dmitri Moore demisx

Block or report user

Report or block demisx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
demisx /
Last active Jan 25, 2016
  • There is no exposed reference from the model to bookshelf (e.g. can't do something like Ad.Bookshelf.knex). Need to require the bookshelf instance itself.

Getting count of models matching certain criteria

// select count(*) from "ads" where "classified_id" = 2'
Ad.where({ classified_id: 2 })
  .query() // <- returns QueryBuild instance
  .then(function (count) {
    console.log('\n***', count);
demisx /
Last active Jan 28, 2018
AngularJS 1.x Unit Testing with Mocha/Chai/Chai-as-promised

UI States

describe('state', function() {
  var stateName ='app.classified';
  var $state;
  var h;

  beforeEach(function() {
demisx / gulpfile.js
Last active Jun 24, 2019
Gulp 4 gulpfile.js
View gulpfile.js
// Gulp 4
var gulp = require('gulp');
var using = require('gulp-using');
var grep = require('gulp-grep');
var changed = require('gulp-changed');
var del = require('del');
var coffee = require('gulp-coffee');
var less = require('gulp-less');
var coffeelint = require('gulp-coffeelint');
var sourcemaps = require('gulp-sourcemaps');

Angular application directory structure

Leverages Angular UI Router instead of core ngRoute module. UI Router allows us to organize our application interface into a state machine. Unlike the $route service in the Angular ngRoute module, which is organized around URL routes, UI-Router is organized around states, which may optionally have routes, as well as other behavior, attached.

LIFT* Organization principle:

  • L - Locating code easy
  • I - Identify code at a glance
demisx / syntax.css
Last active May 5, 2019
Syntax highlighter CSS file
View syntax.css
.highlight { background: #ffffff; }
.highlight .c { color: #999988; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { font-weight: bold } /* Keyword */
.highlight .o { font-weight: bold } /* Operator */
.highlight .cm { color: #999988; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #999988; font-style: italic } /* Comment.Single */
.highlight .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
demisx /
Created Apr 26, 2014
JavaScript Falsy vs. Truthy

The following values are always falsy:

  • false
  • 0 (zero)
  • "" (empty string)
  • null
  • undefined
  • NaN (a special Number value meaning Not-a-Number!)

All other values are truthy, including "0" (zero in quotes), "false" (false in quotes), empty functions, empty arrays, and empty objects.

demisx / webrick-ssl.rb
Created Apr 17, 2014
Configure Webrick Server as SSL
View webrick-ssl.rb
#!/usr/bin/env ruby
require 'rubygems'
require 'rails/commands/server'
require 'rack'
require 'webrick'
require 'webrick/https'
module Rails
class Server < ::Rack::Server
def default_options
demisx / gist:10417077
Created Apr 10, 2014
Generate Self-signed SSL certificate
View gist:10417077
$ openssl req -new -newkey rsa:2048 -sha1 -days 365 -nodes -x509 -keyout server.key -out server.crt
demisx /
Last active Feb 6, 2019
Regenerate and Springify Rails 4 binstubs
cd my_rails_app_root_dir
rm bin/*
bundle exec rake rails:update:bin
bundle binstubs rspec-core
spring binstub --all
You can’t perform that action at this time.