Skip to content

Instantly share code, notes, and snippets.

View hammady's full-sized avatar

Hossam Hammady hammady

View GitHub Profile
# 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" }
#!/usr/local/bin/ruby
# A script to download the latest episodes from railscasts.com
#
# author: modsaid <[email protected]>
# mechanize support: Hossam Hammady <[email protected]>
# gem install mechanize
require 'rubygems'
require 'mechanize'
@hammady
hammady / erbify-css.sh
Created April 17, 2013 06:28
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")%>); }
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Usage: $0 <substitute-path> <with-path> <css-file>"
exit 1
fi
from=$1
to=$2
file=$3
@hammady
hammady / patch_ROCR_WSS.R
Created February 17, 2014 07:21
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
# Patch ROCR R package to support plotting of WSS (Work Saved over Sampling)
# Author: Hossam Hammady ([email protected])
# 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 / boston.json
Last active March 22, 2019 07:55 — forked from pprett/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 / csv2webcards.erb
Created April 19, 2015 12:30
Simple ERB template to convert CSV rows to HTML cards
<!--
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 ([email protected])
-->
@hammady
hammady / clean-logs.sh
Created August 24, 2016 08:34
Clean your S3 logs
#!/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 / solr.service
Created January 9, 2017 08:18
systemd service file for Apache SOLR
# 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 / wordpress_wpforo_slack_plugin.php
Last active August 12, 2017 13:03
WordPress + wpForo + Slack
<?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;' );