Skip to content

Instantly share code, notes, and snippets.

@pofider
pofider / 01-ebs.config
Created September 10, 2015 15:14
Attach EBS volume to amazon elastic beanstalk
# .ebextensions/01-ebs.config
commands:
01clear-if-unmounted:
command: if ! mount | grep /media/ebs_volume > /dev/nul; then rm -rf /media/ebs_volume; fi
02attach-volume:
command: aws ec2 attach-volume --region eu-central-1 --volume-id vol-ddb08e34 --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --device /dev/sdh
ignoreErrors: true
03wait:
command: sleep 10
04trymount:
@pofider
pofider / jsreport-script-sending-email.js
Created April 10, 2015 12:36
Send email notification using jsreport script
function afterRender(done) {
var SendGrid = require('sendgrid');
var sendgrid = new SendGrid('xxx', 'xxx');
sendgrid.send({
to: request.data.email, from: 'jan.blaha@hotmail.com', subject: request.template.name,
html: new Buffer(response.content).toString()
}, function(err, message) {
if (err)
done(err);
@pofider
pofider / electron-script.js
Last active August 4, 2016 08:05
node js and electron IPC doesn't work on linux
process.send('I am ok')
process.exit(0);
@pofider
pofider / nginx.conf
Created June 7, 2016 11:11
running jsreport on subpath behind nginx proxy
upstream jsreport {
# change port 8080 with the port you are running jsreport on
server 127.0.0.1:8080;
keepalive 15;
}
server {
listen 80;
# change my-domain.net with the host you run nginx on
@pofider
pofider / jsreport.config.js
Last active May 31, 2016 08:57
jsreport extension adding request query string into intput data
module.exports = {
'name': 'query-string',
'main': 'queryString.js'
}
@pofider
pofider / jsreport-ebs.config
Created September 10, 2015 15:43
jsreport running on elastic beanstalk and storing data on EBS
# .ebextensions/01-ebs.config
commands:
01clear-if-unmounted:
command: if ! mount | grep /media/ebs_volume > /dev/nul; then rm -rf /media/ebs_volume; fi
02attach-volume:
command: aws ec2 attach-volume --region eu-central-1 --volume-id vol-ddb08e34 --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --device /dev/sdh
ignoreErrors: true
03wait:
command: sleep 10
04trymount:
@pofider
pofider / UnfilteredFlushListener.cs
Created March 22, 2015 17:45
Flushing with enabled filter causes sometimes exceptions in NHibernate when updating collections.
public class UnfilteredFlushListener : DefaultFlushEventListener
{
protected override void PerformExecutions(IEventSource session)
{
var filter = session.GetEnabledFilter("multitenancy");
session.DisableFilter("multitenancy");
base.PerformExecutions(session);
if (filter != null)
session.EnabledFilters.Add("multitenancy", filter);
}
@pofider
pofider / MultitenantEntityPersister.cs
Last active August 29, 2015 14:17
Adding where condition into NHibernate update statements
public class MultitenantEntityPersister : SingleTableEntityPersister
{
public MultitenantEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping)
: base(persistentClass, cache, factory, mapping)
{
}
protected override NHibernate.SqlCommand.SqlCommandInfo GenerateUpdateString(bool[] includeProperty, int j, bool useRowId)
{
var index = base.GetPropertyIndex("TenantId");
@pofider
pofider / MultitenantAssuranceListener.cs
Created March 22, 2015 16:49
NHibernate listener assuring that logged in user cannot reach data from other tenants
public class MultitenantAssuranceListener : IPostLoadEventListener, IPreUpdateEventListener, IPreInsertEventListener, IPreDeleteEventListener
{
public void OnPostLoad(PostLoadEvent @event)
{
if (@event.Entity is IHaveTenant)
{
var tenantId = ((IHaveTenant)@event.Entity).TenantId;
if (Scope.CurrentTenant.Id != tenantId)
throw new InvalidOperationException("Ilegal data access.");
}
@pofider
pofider / MultitenantEntityBase.cs
Created March 22, 2015 16:24
Mapping multitenant filter to the entities
public class MultitenantEntityBase<T> : EntityMapBase<T>
{
protected MultitenantEntityBase()
{
//...
ApplyFilter<MultitenantFilter>();
Map(a => a.TenantId).Not.Nullable();
}
}