Skip to content

Instantly share code, notes, and snippets.

@pofider
pofider / electron-script.js
Last active Aug 4, 2016
node js and electron IPC doesn't work on linux
View electron-script.js
process.send('I am ok')
process.exit(0);
@pofider
pofider / nginx.conf
Created Jun 7, 2016
running jsreport on subpath behind nginx proxy
View nginx.conf
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
jsreport extension adding request query string into intput data
View jsreport.config.js
module.exports = {
'name': 'query-string',
'main': 'queryString.js'
}
@pofider
pofider / jsreport-ebs.config
Created Sep 10, 2015
jsreport running on elastic beanstalk and storing data on EBS
View jsreport-ebs.config
# .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 / 01-ebs.config
Created Sep 10, 2015
Attach EBS volume to amazon elastic beanstalk
View 01-ebs.config
# .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 Apr 10, 2015
Send email notification using jsreport script
View jsreport-script-sending-email.js
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 / UnfilteredFlushListener.cs
Created Mar 22, 2015
Flushing with enabled filter causes sometimes exceptions in NHibernate when updating collections.
View UnfilteredFlushListener.cs
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 Aug 29, 2015
Adding where condition into NHibernate update statements
View MultitenantEntityPersister.cs
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 Mar 22, 2015
NHibernate listener assuring that logged in user cannot reach data from other tenants
View MultitenantAssuranceListener.cs
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 Mar 22, 2015
Mapping multitenant filter to the entities
View MultitenantEntityBase.cs
public class MultitenantEntityBase<T> : EntityMapBase<T>
{
protected MultitenantEntityBase()
{
//...
ApplyFilter<MultitenantFilter>();
Map(a => a.TenantId).Not.Nullable();
}
}