Skip to content

Instantly share code, notes, and snippets.

View dznz's full-sized avatar

Daniel Zollinger dznz

  • free agent
  • Auckland, New Zealand
  • X @dznz
View GitHub Profile
@dznz
dznz / .bash_profile
Created August 11, 2012 01:00
Bash rvm script loading
[[ -s "/Users/dz/.rvm/scripts/rvm" ]] && source "/Users/dz/.rvm/scripts/rvm" # This loads RVM into a shell session
@dznz
dznz / CrudeJasmineExamples.js
Last active December 16, 2015 12:59
Minor examples of Jasmine tests.
// collections/ScheduleDayCollectionSpec.js
describe("ScheduleDayCollection", function() {
var date;
var schedule_days;
beforeEach(function() {
date = "2012-07-10"
schedule_days = new wb.ScheduleDayCollection();
schedule_days.reset([{"id":"1", "date":date},{"id":"2", "date":"2012-07-11", "selected":"true"}]);
;(function(Form) {
var editors = Form.editors;
editors.List.InlineNestedModel = editors.List.NestedModel.extend({
events: {},
/**
* @param {Object} options
*/
ruby-1.9.2-p320:
system:
uname: "Darwin Daniels-MacBook-Pro.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64"
system: "osx/10.8/x86_64"
bash: "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)"
zsh: "/bin/zsh => zsh 4.3.11 (i386-apple-darwin12.0)"
rvm:
version: "rvm 1.19.5 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
@dznz
dznz / gist:5923238
Created July 3, 2013 22:00
Autoselect select event problem
Form.editors.AutoSelect = Form.editors.Text.extend({
initialize: function(options) {
var _this = this;
Form.editors.Text.prototype.initialize.call(this, options);
this.$el.autocomplete({
...
select: function(event, ui) {
@dznz
dznz / gist:6207177
Created August 11, 2013 22:29
Jasmine testing fail
it 'set default id and title', ->
id = 2;
title = "crichq";
expect(id).toEqual(2);
expect(title).toEqual("crichq");
@dznz
dznz / gist:8412835
Created January 14, 2014 04:01
Count down the number of characters that remain in a text box.
$ ->
$body = $('#question_body')
$counter = $('#js-body-count')
determineChange = ->
remainingChars = 140 - $body.val().length
if remainingChars isnt 140
$counter.text remainingChars
@dznz
dznz / gist:8552522
Last active December 16, 2020 09:15
Two different ways to plug in a simple Warden failure app to a Rails project.
##
# Simple Warden configuration, complex "controller"
# In config/initializers/warden.rb
Rails.application.config.middleware.use Warden::Manager do |manager|
manager.failure_app = UnauthorizedController
end
# app/controllers/unauthorized_controller.rb
class UnauthorizedController < ActionController::Metal
@dznz
dznz / rubocop.yml
Created September 18, 2014 04:04
My preferred Rubocop setup.
AllCops:
Excludes:
- setup_environment.rb
# Prefer a comma at the end of a multiline, to minimise diff changes and
# enable easier rearranging of lines.
TrailingComma:
EnforcedStyleForMultiline: comma
# Experimenting with the idea of having the `private`, `protected`
@dznz
dznz / gist:f9dcd594427aa31f6d8f
Created October 10, 2014 01:26
Set up a read-only user in Postgresql
CREATE ROLE readonly LOGIN PASSWORD 'some_pass';
-- Existing objects
GRANT CONNECT ON DATABASE the_db TO readonly;
GRANT USAGE ON SCHEMA public TO readonly;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO readonly;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO readonly;
-- New objects
ALTER DEFAULT PRIVILEGES FOR owner_user IN SCHEMA public GRANT SELECT ON TABLES TO readonly;
ALTER DEFAULT PRIVILEGES FOR owner_user IN SCHEMA public GRANT SELECT ON SEQUENCES TO readonly;