Skip to content

Instantly share code, notes, and snippets.

View raedatoui's full-sized avatar

Raed Atoui raedatoui

View GitHub Profile
@raedatoui
raedatoui / gist:3230784
Created August 1, 2012 21:10
json responses
def render_json_response(type, hash)
unless [ :ok, :error ].include?(type)
raise "Invalid json response type: #{type}"
end
default_json_structure = {
:status => type,
:data => nil,
:error => nil,
@raedatoui
raedatoui / gist:2597831
Created May 4, 2012 21:26
Swagger nested resources
//resources.json
{
"apiVersion": "0.1",
"apis": [
{
"description": "Operations about projects",
"path": "/project.{format}"
},
{
"description": "Operations about tickets",
@raedatoui
raedatoui / gist:2492728
Created April 25, 2012 19:39
kill process by name in Terminal
alias kp=kill_process
kill_process(){
ps -ef | grep $@ | grep -v grep | awk '{print $2}' | xargs kill -9
}
e.g: you may have ran 'rails s &', 'gitk &', 'middleman &'
you kill with kp rails
useful to logout of all current ssh connections
@raedatoui
raedatoui / gist:2473221
Created April 23, 2012 19:22
pyramid tiles using imagemagick
convert image.tif -resize 1.5625% -crop 256x256 +repage +adjoin out/1/tile_1_%d.jpg
convert image.tif -resize 3.125% -crop 256x256 +repage +adjoin out/2/tile_2_%d.jpg
convert image.tif -resize 6.25% -crop 256x256 +repage +adjoin out/3/tile_3_%d.jpg
convert image.tif -resize 12.5% -crop 256x256 +repage +adjoin out/4/tile_4_%d.jpg
convert image.tif -resize 25% -crop 256x256 +repage +adjoin out/5/tile_5_%d.jpg
convert image.tif -resize 50% -crop 256x256 +repage +adjoin out/6/tile_6_%d.jpg
convert image.tif -crop 256x256 +repage +adjoin out/7/tile_7_%d.jpg
@raedatoui
raedatoui / gist:2325600
Created April 7, 2012 05:43
nginx worpdress config
server {
listen 80;
server_name raedatoui.com www.raedatoui.com;
access_log /srv/www/raedatoui.com/logs/access.log;
error_log /srv/www/raedatoui.com/logs/error.log;
root /srv/www/raedatoui.com/public;
location / {
#index index.html index.htm index.php;
@raedatoui
raedatoui / gist:2271033
Created April 1, 2012 03:49
wp mu aggregate
function wpmu_latest_post_links($blog_path, $how_many = 10, $how_long_days = 30, $how_many_words = 50, $more_text = "[...]", $remove_html = true, $sort_by = 'post_date') {
global $wpdb;
//first, gat all blog id
$query = "SELECT blog_id FROM $wpdb->blogs WHERE blog_id !='1' AND path='" . $blog_path . "'";
$blogs = $wpdb->get_col($query);
if ($blogs) {
//we use blog id to loop post query
foreach ($blogs as $blog) {
@raedatoui
raedatoui / gist:2161387
Created March 22, 2012 18:33
mysql select concat links
SELECT CONCAT('http://naturevalleytrailview.com/',parks.slug,'/',trails.slug,'#panorama-',interest_points.slug)
FROM `interest_points`
LEFT JOIN trails ON trails.id = interest_points.trail_id
LEFT JOIN parks ON parks.id = trails.park_id
WHERE `poi_type_id` = 1 ORDER BY parks.id
@raedatoui
raedatoui / gist:2055952
Created March 17, 2012 07:05
active admin sort by association
### Model
class ModelA < ActiveRecord::Base
has_many :modelb
end
class ModelB < ActiveRecord::Base
belongs_to :modela
has_many :modelc
end
@raedatoui
raedatoui / gist:2055870
Created March 17, 2012 06:51
active admin tricks
index do
column :image, :sortable => :image do |model|
if model.image.to_s.nil?
raw('&#8212;')
else
raw('&#x2713')
end
end
end
@raedatoui
raedatoui / gist:2055723
Created March 17, 2012 06:18
process all images in a folder using imagemagick
find . -iname "*.jpg" | perl -e 'for(<>) { chomp $_;@a=split(/\//,$_);$str = "convert -resize 15% -quality 60 $_ _".$a[-1];print $str."\n";`$str`}'