Skip to content

Instantly share code, notes, and snippets.

Hossam Hammady hammady

Block or report user

Report or block hammady

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@hammady
hammady / wordpress_wpforo_slack_plugin.php
Last active Aug 12, 2017
WordPress + wpForo + Slack
View wordpress_wpforo_slack_plugin.php
<?php
# add the following towards the end of wpforo/wpforo.php using plugin editor (before the final })
add_filter( 'slack_get_events', function( $events ) {
$events['wpforo_after_add_topic'] = array(
'action' => 'wpforo_after_add_topic',
'description' => __( 'When a forum post is published', 'slack' ),
'default' => false,
'message' => function( $args ) {
$excerpt = wp_trim_words( strip_shortcodes( $args['body'] ), 55, '&hellip;' );
@hammady
hammady / solr.service
Created Jan 9, 2017
systemd service file for Apache SOLR
View solr.service
# put this file in /etc/systemd/system/ as root
# below paths assume solr installed in /opt/solr, SOLR_PID_DIR is /data
# and that all configuration exists in /etc/default/solr.in.sh which is the case if previously installed as an init.d service
# change port in pid file if differs
# note that it is configured to auto restart solr if it fails (Restart=on-faliure) and that's the motivation indeed :)
# to switch from systemv (init.d) to systemd, do the following after creating this file:
# sudo systemctl daemon-reload
# sudo service solr stop # if already running
# sudo systemctl enable solr
# systemctl start solr
@hammady
hammady / clean-logs.sh
Created Aug 24, 2016
Clean your S3 logs
View clean-logs.sh
#!/bin/bash
echo "Prerequisites:"
echo "sudo apt-get install awscli"
echo "aws configure"
echo "Usage:"
echo "aws s3 ls s3://BUCKET/PREFIX/ | cut -c32- | ./clean-logs.sh"
bucket=SET_BUCKET_NAME
prefix=SET_PREFIX
@hammady
hammady / csv2webcards.erb
Created Apr 19, 2015
Simple ERB template to convert CSV rows to HTML cards
View csv2webcards.erb
<!--
If your input file is in Excel format, use xlsx2csv python tool available at
https://github.com/dilshod/xlsx2csv
Usage is simple, you need ruby installed (including erb)
rename the input file to input.csv, then just run:
erb csv2webcards.erb > output.html
Now open output.html in any browser to see the HTML cards
Author: Hossam Hammady (github@hammady.net)
-->
View boston.json
{"error": 42716.2954, "samples": 506, "value": [22.532806324110698], "label": "RM <= 6.94", "type": "split", "children": [{"error": 17317.3210, "samples": 430, "value": [19.93372093023257], "label": "LSTAT <= 14.40", "type": "split", "children": [{"error": 6632.2175, "samples": 255, "value": [23.349803921568636], "label": "DIS <= 1.38", "type": "split", "children": [{"error": 390.7280, "samples": 5, "value": [45.58], "label": "CRIM <= 10.59", "type": "split", "children": [{"error": 0.0000, "samples": 4, "value": [50.0], "label": "Leaf - 4", "type": "leaf"}, {"error": 0.0000, "samples": 1, "value": [27.9], "label": "Leaf - 5", "type": "leaf"}]}, {"error": 3721.1632, "samples": 250, "value": [22.90520000000001], "label": "RM <= 6.54", "type": "split", "children": [{"error": 1636.0675, "samples": 195, "value": [21.629743589743576], "label": "LSTAT <= 7.57", "type": "split", "children": [{"error": 129.6307, "samples": 43, "value": [23.969767441860473], "label": "TAX <= 222.50", "type": "split", "children": [{"err
@hammady
hammady / patch_ROCR_WSS.R
Created Feb 17, 2014
After sourcing this patch, you can use "wss" as a new measure in plotting performance curves, same like fp, tp, rec, auc, ... You should have ROCR installed and imported first
View patch_ROCR_WSS.R
# Patch ROCR R package to support plotting of WSS (Work Saved over Sampling)
# Author: Hossam Hammady (hhammady@qf.org.qa)
# Organization: Qatar Computing Research Institute; Data Analytics Group (http://da.qcri.qa)
# Date: 17-Feb-2014
# License: MIT
# Description: After sourcing this patch, you can use "wss" as a new measure in
# .. plotting performance curves, same like fp, tp, rec, auc, ...
# .. You should have ROCR installed and imported first
@hammady
hammady / erbify-css.sh
Created Apr 17, 2013
BASH script to convert image urls in .CSS files to .ERB style asset paths. Example usage: ./erbify-css.sh src libfoo input-file.css converts: .showgrid { background: url(src/grid.png); } to: .showgrid { background: url(<%=asset_path("libfoo/grid.png")%>); }
View erbify-css.sh
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Usage: $0 <substitute-path> <with-path> <css-file>"
exit 1
fi
from=$1
to=$2
file=$3
View download_railscasts.rb
#!/usr/local/bin/ruby
# A script to download the latest episodes from railscasts.com
#
# author: modsaid <mahmoud@modsaid.com>
# mechanize support: Hossam Hammady <github@hammady.net>
# gem install mechanize
require 'rubygems'
require 'mechanize'
View performance_test_helper.rb
# See http://m.onkey.org/running-rails-performance-tests-on-real-data
# fixed to work with Rails 3.2.8
# START : HAX HAX HAX
# Load Rails environment in 'test' mode
RAILS_ENV = "test"
require File.expand_path('../../config/environment', __FILE__)
# Re-establish db connection for 'performance' mode
silence_warnings { RAILS_ENV = "performance" }
You can’t perform that action at this time.