Skip to content

Instantly share code, notes, and snippets.

View Alir3z4's full-sized avatar
💭
Rock'nRolla

Alireza Savand Alir3z4

💭
Rock'nRolla
View GitHub Profile
@Alir3z4
Alir3z4 / middleware.py
Last active December 16, 2020 13:01
When running on AWS Elastic Beanstalk, we suffer an issue where HTTPS requests arriving at the load balancer are propagated to the individual hosts as HTTP requests. If the host issues a redirect it issues it using the same scheme as its incoming request (HTTP) when it should use HTTPS. This issue isn't unique to AWS EB, it's discussed in the co…
from django.http import HttpResponsePermanentRedirect
class SecureRequestPropagationMiddleware(object):
"""
When running on AWS Elastic Beanstalk, we suffer
an issue where HTTPS requests arriving at the load
balancer are propagated to the individual hosts as
HTTP requests. If the host issues a redirect it
issues it using the same scheme as its incoming
@Alir3z4
Alir3z4 / admin.py
Last active December 16, 2020 13:01
from django.utils.translation import ugettext_lazy as _
class MyUserAdmin(UserAdmin):
# The forms to add and change user instances
form = UserChangeForm
add_form = UserCreationForm
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
@Alir3z4
Alir3z4 / if.py
Created October 13, 2013 09:10
Ahmad gist
# Filename : if.py
number = 23
guess = int(raw_input('Enter an integer : '))
if guess == number:
print "Congratulations, you guessed it." # New block starts here
print "(but you do not win any prizes!)" # New block ends here
elif guess < number:
print "No, it is a little higher than that" # Another block
# You can do whatever you want in a block ...
else:
@Alir3z4
Alir3z4 / disable_submit_on_form.js
Created August 25, 2013 17:33
Disable form submit
$(window).keydown(function (event) {
if (event.keyCode == 13) {
event.preventDefault();
return false;
}
});
@Alir3z4
Alir3z4 / vr_ruby_sample_code.rb
Created August 23, 2013 20:07
VerticalResponse.com Ruby The Ruby lifecycle sample code demonstrates all the steps needed to send out an email campaign. These examples require the soap4r-ruby1.9 gem to be installed.
# FOR PARTNER DEVELOPERS
# You will need to have your certificates installed for any partner-specific calls to work.
# The cert simply needs to be accessible by this code and its abosolute path added to lines 20 & 21 below.
# For administrative actions, like creating accounts and transferring credits, you should not use impersonate_user when calling login.
# Rather, impersonate_user should only be called when making calls on behalf of a subaccount: creating emails, lists, getting reporting, etc.
#
# FOR EVERYONE
# This code will take you through creating a list and campaign, associating the two, and launching the campaign.
# There are several sections that you can update, including the email address we send the email to and the HTML content.
# The only section you MUST update is the username and password below.
@Alir3z4
Alir3z4 / atlas_lapack_post_installation.txt
Created August 7, 2013 16:31
installing atlas-lapack atlas-lapack
On multi-core/thread systems libf77blas.so, libstcblas.so and
liblapack.so.3.4.1 are single-threaded, libptcblas.so, libptf77blas.so
and libptlapack.so.3.4.1 are multi-threaded. By default
libcblas.so, libblas.so and liblapack.so point to the multi-threaded
versions.
The default can be changed by making libcblas.so, libblas.so and
liblapack.so.3 point to the single threaded libraries, i.e.
ln -sf libf77blas.so libblas.so; ln -sf libstcblas.so libcblas.so;
ln -sf liblapack.so.3.4.1 liblapack.so.3
import signal
class TimeoutError(Exception):
pass
def timeout_handler(signum, frame):
raise TimeoutError('Fuck you time')
@Alir3z4
Alir3z4 / die_magento_die.php
Created July 26, 2013 21:08
Die Magento Die!
<?php
/**
* Example of simple product POST using Admin account via Magento REST API. OAuth authorization is used
*/
$callbackUrl = "http://magento-site.com/oauth_admin.php";
$temporaryCredentialsRequestUrl = "http://magento-site.com/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://magento-site.com/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://magento-site.com/oauth/token';
$apiUrl = 'http://magento-site.com/api/rest';
$consumerKey = '<CONSUMER_KEY>';
BEGIN;
CREATE TABLE `filer_folder` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`parent_id` integer,
`name` varchar(255) NOT NULL,
`owner_id` integer,
`uploaded_at` datetime NOT NULL,
`created_at` datetime NOT NULL,
`modified_at` datetime NOT NULL,
`lft` integer UNSIGNED NOT NULL,
BEGIN;
CREATE TABLE `form_designer_formdefinition` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` varchar(255) NOT NULL UNIQUE,
`require_hash` bool NOT NULL,
`private_hash` varchar(40) NOT NULL,
`public_hash` varchar(40) NOT NULL,
`title` varchar(255),
`body` longtext,
`action` varchar(255),