Skip to content

Instantly share code, notes, and snippets.

View xcambar's full-sized avatar

Xavier Cambar xcambar

View GitHub Profile
@xcambar
xcambar / nginx-cors.conf
Last active November 1, 2021 09:27 — forked from algal/nginx-cors.conf
nginx configuration for CORS (Cross-Origin Resource Sharing), with an origin whitelist, and HTTP Basic Access authentication allowed
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@xcambar
xcambar / app_components_throw-test.js
Created January 29, 2020 11:55
Testing component initialisation and required arguments in Ember 3.15 (Octane)
import Component from '@glimmer/component';
export default class ThrowTestComponent extends Component {
constructor() {
super(...arguments)
if (!this.args.test) {
throw new Error('hello')
}
}
}
@xcambar
xcambar / controllers.application.js
Last active December 6, 2018 13:36
textarea demo
import Ember from 'ember';
export default Ember.Controller.extend({
testString: 'Ember Twiddle'
});
@xcambar
xcambar / daily_planning.md
Last active November 21, 2018 20:27
A day at work - or "how to save my productivity and sanity against distractions and their minions: notifications"

Rules

  • No Desktop/Browser notifications
  • Read E-mails
    • early in the morning
    • late in the afternoon
    • quick check after lunch, action allowed based on volume
  • Slack
    • active notifications only for #blocking channels
  • Catch up discussions on early morning and late afternoon
import Component from '@ember/component'
export default Component.extend({
tagName: '',
aIsChecked: false,
bIsChecked: false,
someOtherMethod() {
console.log('someOtherMethod() this = ', this)
},
someMethod() {
@xcambar
xcambar / strip_tags.js
Last active September 3, 2018 09:42
Efficiently and securely remove <script> tags from source HTML
// This code would normally inject global variables and run an alert
// if injected in your document naively
const source = '<p>bla <script>window.SHIT=true</script></p><script>alert("SHIT")</script>'
// Crete a DocumentFragment from the source HTML
const frag = document.createRange().createContextualFragment(source)
// Remove all the <script> nodes
[...frag.querySelectorAll('script')].forEach((e)=> {
e.parentNode.removeChild(e)
@xcambar
xcambar / hull-restify.js
Created March 3, 2014 17:14
Example of Hull API with node-restify
var restify = require('restify');
var client = restify.createJsonClient({
url: 'https://YOUR_ORG_NAMESPACE.hullapp.io',
headers: {
'Hull-App-Id': 'YOUR_APP_ID',
'Hull-Access-Token': 'YOUR_APP_SECRET'
}
});
//
// This script shows how to add custom traits to a user
//
var hull = require('hull');
hull.conf({
appId: 'abcd',
orgUrl: 'https://demo.hullapp.io',
appSecret: '1234'
@xcambar
xcambar / controllers.application.js
Created April 20, 2018 18:29
ember-modal-dialog: double onClose call
import Ember from 'ember';
export default Ember.Controller.extend({
countClose: 0,
incCloseCount() {
this.incrementProperty('countClose');
}
});
@xcambar
xcambar / vagrant.sh
Last active February 2, 2017 10:53
Show vagrant status
[ -e .vagrant ] && (VBoxManage showvminfo $(cat .vagrant/machines/default/virtualbox/id) --machinereadable | grep 'VMState=' | sed 's/.*"\(.*\)"[^"]*$/\1/)