Skip to content

Instantly share code, notes, and snippets.

View raedatoui's full-sized avatar

Raed Atoui raedatoui

View GitHub Profile
@raedatoui
raedatoui / gist:2044730
Created March 15, 2012 15:13
Expression Engine JSON output
[{exp:channel:categories channel="sections" style="linear"}
{"name":"{category_name}",
"thumb":"{category_image}",
"id":"{category_id}",
"image":"{image}",
"description":"{category_description}",
"pages":{exp:json:entries channel="sections" orderby="display_order" sort="asc" category="{category_id}"}},
{/exp:channel:categories}
{"id":"-1"}]
@raedatoui
raedatoui / gist:2055680
Created March 17, 2012 06:10
Converting GPS from mmmm ss to dddd for Google Maps API
## SAMPLE data 3603.7517 N 11212.6268 W
lat_sign = LAT_FROM_DATA > 0 ? 1:-1
lat = LAT_FROM_DATA
lat = lat[0,lat.length-1] #strip N
arr = lat.split('.')
if arr[0].length == 4
deg= arr[0][0,2].to_f
min = arr[0][2,4].to_f
seconds = arr[1].to_f
lat = (deg + min/60 + seconds/600000).to_f
@raedatoui
raedatoui / gist:2055720
Created March 17, 2012 06:16
avi jpg sequence using ffmpeg
ffmpeg -i input.avi -y -an -sameq -f image2 out/still-%03d.jpg
@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`}'
@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: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: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: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: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: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