Skip to content

Instantly share code, notes, and snippets.

@denvaar
denvaar / s3_downloads.ex
Last active January 9, 2024 02:15
Dependency free presigned S3 links
defmodule S3Downloads do
@moduledoc """
Use at your own risk.
Code heavily borrowed from:
- https://github.com/ex-aws/ex_aws/blob/main/lib/ex_aws/auth.ex
- https://gist.github.com/chrismccord/37862f1f8b1f5148644b75d20d1cb073
"""
@cmalven
cmalven / craft-localization-nginx
Last active October 22, 2019 12:59
nginx config for Craft CMS localization
server {
listen 80;
server_name site.production.designcompany.com;
root /home/forge/site.production.designcompany.com/public;
# enable gzip compression
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript image/svg+xml text/xml text/css;
@ngauthier
ngauthier / merge.rb
Created June 25, 2014 14:39
ActiveRecord Scope Merging
# Merging Scopes
# ==============
# The goal is to join two tables to get all the records where a scope on both
# side of the join is used. I used to do this with a `where()` in which I
# added some sql on the joined table. But, I wanted to use the existing scopes
# from the joining table. Turns out there's a `merge` method on a scope where
# you can merge with another scope without having to chain!
class Car < ActiveRecord::Base
has_and_belongs_to_many :people
class CommunitiesController < ApplicationController
# ...
def show
@community = Community.find(params[:id])
@users = @community.users
@ressources = Ressource.paginate(:page => params[:page], :per_page => 5)
end
@adrienbrault
adrienbrault / purge.sh
Created September 24, 2012 10:02
Script to reduce VM size before packaging for vagrant
#!/bin/sh
# Credits to:
# - http://vstone.eu/reducing-vagrant-box-size/
# - https://github.com/mitchellh/vagrant/issues/343
aptitude -y purge ri
aptitude -y purge installation-report landscape-common wireless-tools wpasupplicant ubuntu-serverguide
aptitude -y purge python-dbus libnl1 python-smartpm python-twisted-core libiw30
aptitude -y purge python-twisted-bin libdbus-glib-1-2 python-pexpect python-pycurl python-serial python-gobject python-pam python-openssl libffi5
@gudata
gudata / _page.html.slim
Created July 18, 2012 14:41
Easy implementation of nestedSortable with rails preserving the sort order http://mjsarfatti.com/sandbox/nestedSortable/
- class_for_root_only = ((root_ol rescue true) ? 'sortable' : @first_call = '')
ol class=class_for_root_only data-sort-url=sort_website_pages_path(@website)
li id="list_#{page.id}"
.handle
= link_to page.name, edit_website_page_path(@website, page)
'
= active_icon(page, :published)
.btn-group.pull-right
= link_to t('View'), website_page_path(@website, page), :class => 'btn btn-mini'
@robertjwhitney
robertjwhitney / activeadmin_sortable.js.coffee
Created July 3, 2012 03:37
Simple drag/drop reordering of records in an ActiveAdmin view table
# http://stackoverflow.com/a/8936202
#
# ActiveAdmin already includes the necessary jquery in active_admin/base,
# so just add this to javascripts/active_admin.js after //= require active_admin/base
#
#
# Serialize and Sort
#
# model_name - you guessed it, the name of the model we are calling sort on.
# This is the actual variable name, no need to change it.
@jasmarc
jasmarc / create_webpages.command
Created June 13, 2012 20:09
Creates a photo gallery from a folder full of images, somewhat per this request: http://www.idiotking.org/archives/2012/05/exercise-in-futility/
#! /usr/bin/env ruby
# 1. Save this file as "make_webpages.command"
# 2. chmod a+x+r make_webpages.command
# 3. Place make_webpages.command in folder full of pictures
# 4. Double-click make_webpages.command
extensions = "png,PNG,jpg,JPG,gif"
working_dir = File.dirname($0)
pictures = Dir.glob("#{working_dir}/*.{#{extensions}}")
@tomykaira
tomykaira / clockwork-init.sh
Created October 25, 2011 10:21
Create a new project with clockwork for heroku.
#!/bin/sh
# Licence: MIT
# Created by tomykaira, 2011-10-25
if [ $# -ne 1 ]; then
echo "Give me your new project name (only)"
exit 1
fi
@desandro
desandro / jquery.imagesloaded.js
Created January 26, 2011 18:01 — forked from paulirish/README.md
$.fn.imagesLoaded jQuery plugin
// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images
// Modified with a two-pass approach to changing image
// src. First, the proxy imagedata is set, which leads
// to the first callback being triggered, which resets
// imagedata to the original src, which fires the final,
// user defined callback.