Skip to content

Instantly share code, notes, and snippets.

View LukaszWiktor's full-sized avatar

Łukasz Wiktor LukaszWiktor

View GitHub Profile
@LukaszWiktor
LukaszWiktor / vue-focus.js
Last active January 28, 2017 17:40
Vue 2.x directive - automatic focus when element gets visible (works well with v-show)
Vue.directive('focus', {
update: function (el) {
if (!el.offsetParent) { // element not visible
el.dataset.focused=false;
} else if (el.dataset.focused!=="true") { // focus hasn't been forced yet
el.dataset.focused=true;
el.focus();
}
}
})
@LukaszWiktor
LukaszWiktor / postgres-remove-field-from-json.sql
Created November 25, 2016 16:20
PostrgreSQL - remove a nested JSON field if it's null
-- before: data_json = {object: {id: 123, result: null}}
-- after: data_json = {object: {id: 123}}
UPDATE events
SET data_json = data_json::jsonb #- '{object,result}'
WHERE json_typeof(data_json->'object'->'result') = 'null';
@LukaszWiktor
LukaszWiktor / logentries_manual_setup.md
Created May 25, 2016 09:23 — forked from ostinelli/logentries_manual_setup.md
How to use a single Logentries account on Heroku

If you have multiple applications on Heroku and would like to use a single Logentries account for all of them, this is how you do it. Basically, do not use add-ons, and send all drains to your account.

  • In your Logentries account, click on Add Log
  • Select Manual
  • In the form that appears, input the following:
    • Log Name: access.log
    • Select Set: new set named myapp-{environment}, for instance myapp-staging (at least, this is how I like to name my entries)
    • Select the Plain TCP, UDP - logs are sent via syslog option
  • Click on Create Log Token
@LukaszWiktor
LukaszWiktor / index.html
Last active August 29, 2015 14:25 — forked from jtrussell/index.html
jsbin - AngularJS, basic template
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Angular JS</title>
</head>
<body ng-app="jsbin">
<div ng-controller="DemoCtrl as demo">
<h1>Hello {{demo.name}}</h1>
</div>
// traditional
if (this.currentView == 'gantt') {
this.currentView = 'table';
} else {
this.currentView = 'gantt';
}
// tricky
var toggle = {'gantt' : 'table', 'table' : 'gantt'}
this.currentView = toggle[this.currentView];