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 / warmup.php
Created January 18, 2015 16:57
If you are minifying scripts and css files using a caching plugin or using FastCGI cache then you might need to warmup your blog after purging your cache. This is a simple warm up cli script for WordPress to initiate cache or HHVM HHBC and making sure all pages/posts do not have errors. Additionally the script creates a urllist.txt file that you…
<?php
if (PHP_SAPI != 'cli') {
header('Status: 403 Forbidden');
header('HTTP/1.1 403 Forbidden', true, 403);
exit();
}
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
<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
@gadelkareem
gadelkareem / openssl_examples.md
Last active June 11, 2019 13:13
OpenSSL encrypt-decrypt examples

###Encrypt

php -r "echo openssl_encrypt('Hello OpenSSL', 'AES-256-CBC', 'SecretPass', 0, '6299868101947302');"

TLHG68yaaVtSsV3zOYtn2Q==

printf "Hello OpenSSL" | openssl enc -a -e -aes-256-cbc -K $(printf "SecretPass" | od -A n -t x1 | tr -d '\040\011\012\015') -iv $(printf "6299868101947302" | od -A n -t x1 | tr -d '\040\011\012\015')

TLHG68yaaVtSsV3zOYtn2Q==

@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 / Jenkins-alerts.html
Last active June 29, 2019 12:17
Using Jenkins JSON API to display an alert on your team dashboard, more http://gadelkareem.com/2016/06/29/using-jenkins-json-api-display-alert-build-fails/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tweets</title>
<script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script type="text/javascript" src="http://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
@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);