Skip to content

Instantly share code, notes, and snippets.

View aihaddad's full-sized avatar

Ahmed Elhaddad aihaddad

  • Helsinki, Finland
View GitHub Profile
@evan-007
evan-007 / gulpfile.js
Last active August 19, 2016 01:33
gulp shell example
var gulp = require('gulp');
var connect = require('gulp-connect');
var modRewrite = require('connect-modrewrite');
var runSequence = require('run-sequence');
var shell = require('gulp-shell');
//proxy all requests to /api to localhost:3000 for rails api
gulp.task('connect', function(){
connect.server({
root: './app',
@kurenn
kurenn / gist:4421177
Last active March 29, 2017 21:16
This gist shows how to make a polymorphic association for users in rails which have an specific role, such as Member, Admin...works with devise
##Userable
module Userable
def self.included(base)
base.has_one :user, :as => :userable, :dependent => :destroy, :autosave => true
base.validate :user_must_be_valid
base.alias_method_chain :user, :autobuild
base.extend ClassMethods
base.define_user_accessors
end
@TimFletcher
TimFletcher / 20120625030355_add_deleted_at_to_user.rb
Created November 7, 2012 17:05
Trashable 'concern' for Rails models
# db/migrate/20120625030355_add_deleted_at_to_user.rb
class AddDeletedAtToUser < ActiveRecord::Migration
def change
add_column :users, :deleted_at, :time
end
end
@dnlserrano
dnlserrano / create.json.jbuilder
Last active October 18, 2017 01:40
Custom Token Authentication SessionController with DRY Authenticatable Logout
json.success true
json.data do
json.auth_token @user.authentication_token
json.message "login successful"
end
@c0ze
c0ze / jekyll-s3.rake
Last active April 4, 2020 13:53
deploys a jekyll site to s3 bucket. you must provide aws credentials in .env. Aws sdk v2 compatible. contains optional minifier and gzip.
require "aws-sdk"
require "dotenv"
require "reduce"
Dotenv.load
def local_dir; './_site'; end
def access_key; ENV['AWS_ACCESS_KEY']; end
def secret_key; ENV['AWS_SECRET_KEY']; end
@bluemont
bluemont / url_validator.rb
Created June 25, 2012 04:27
ActiveModel URL Validator
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = begin
URI.parse(value).kind_of?(URI::HTTP)
rescue URI::InvalidURIError
false
end
unless valid
record.errors[attribute] << (options[:message] || "is an invalid URL")
@bramswenson
bramswenson / sqs_notes.md
Last active September 25, 2020 07:27
Amazon SQS Notes
@mjallday
mjallday / README.md
Last active September 25, 2020 09:47
SQS Latency Measuring

SQS Latency testing

Run this from an ec2 instance in the us-west-1 region.

It will create two queues and feed messages into the first queue with a timestamp, this message will then be read and the difference between the message timestamp and the current time computed and pushed into a response queue. Reading these times will give you the latency between publishing to a queue and receiving the message.

@beugley
beugley / s3_get.py
Last active December 4, 2021 14:58
Python boto3 script to download an object from AWS S3 and decrypt on the client side using KMS envelope encryption
#!/usr/bin/env python
###############################################################################
# This script downloads an object from AWS S3. If the object was encrypted,
# it will be decrypted on the client side using KMS envelope encryption.
#
# Envelope encryption fetches a data key from KMS and uses it to encrypt the
# file. The encrypted file is uploaded to an S3 bucket along with an encrypted
# version of the data key (it's encrypted with a KMS master key). You must
# have access to the KMS master key to decrypt the data key and file. To
# decrypt, the file is downloaded to the client, the encrypted data key is