Skip to content

Instantly share code, notes, and snippets.

View gadelkareem's full-sized avatar
🎯
Focusing

Gadelkareem gadelkareem

🎯
Focusing
View GitHub Profile
@gadelkareem
gadelkareem / Custom validation messages in blueprint for sails.js
Created December 10, 2014 16:39
Custom validation messages in blueprint for sails.js
// For adding custom messages if using blueprint
// In reponses/badrequest.js
// after
// if (sails.config.environment === 'production') {
// data = undefined;
// }
// add
if (data.invalidAttributes !== undefined) {
var attributes = data.invalidAttributes;
@gadelkareem
gadelkareem / Custom validation messages for sails js
Created December 29, 2014 08:24
Custom validation messages for sails js
//in api/models/User.js
function validationError(invalidAttributes, status, message) {
var WLValidationError = require('../../node_modules/sails/node_modules/waterline/lib/waterline/error/WLValidationError.js');
return new WLValidationError({
invalidAttributes: invalidAttributes,
status: status,
message: message
}
);
}
@gadelkareem
gadelkareem / mailcatcher
Created January 7, 2015 16:13
mailcatcher init script for ubuntu trusty
#! /bin/sh
### BEGIN INIT INFO
# Provides: mailcatcher
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@gadelkareem
gadelkareem / mysql-simple-migrate.sh
Last active June 20, 2016 16:54
Simple MySQL migration bash script
#!/usr/bin/env bash
set -e
mkdir -p /root/tmp
#migrate "original db params" "new db params" "new db name"
function migrate(){
mysqldump --skip-lock-tables --single-transaction --add-drop-table $1 > /root/tmp/${3}.sql
---
- include_vars: secrets.yml
- apt: pkg={{ item }} state=present update_cache=yes
with_items:
- build-essential
- mime-support
- libfuse-dev
- libcurl4-openssl-dev
@gadelkareem
gadelkareem / BaseEntity.php
Created November 28, 2016 21:12
Easily convert Doctrine Entities into readable array for debugging
<?php
namespace App\Entity;
abstract class BaseEntity
{
public function toArray()
{
$properties['__type'] = get_class($this);
$properties += get_object_vars($this);
<VirtualHost *:80>
ProxyPreserveHost On
ServerName proxy-test.example.com
FilterDeclare MYFILTER
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $text/
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/xml
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/json
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/javascript
<Location />
#disable gzip
package main
import (
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"fmt"
"strconv"
"time"
"sync"
)
@gadelkareem
gadelkareem / postgres_solr.sql
Created April 5, 2018 00:40
Convert postgres timestamp to solr date format
SELECT to_char('2018-02-28 18:48:11.196+00'::timestamp, 'YYYY-MM-DD"T"HH24:MI:SSZ')
@gadelkareem
gadelkareem / vault.sh
Last active April 9, 2018 23:17
Ansible vault encrypt/decrypt shell script
#!/usr/bin/env bash
####Usage
# ./vault.sh encrypt
# ./vault.sh dencrypt
# ./vault.sh encrypt /full/path/to/file.yml
######
set -euo pipefail