Skip to content

Instantly share code, notes, and snippets.

View inoryy's full-sized avatar
:octocat:

Roman Ring inoryy

:octocat:
View GitHub Profile

Redirecting to last visited page after registration.

Imagine this scenario: A new user on your awesome webpage finds an awesome link, but it's only open to registered users, so he's automatically redirected to login form, then he goes to a register page (or fills embedded form right there) and then gets redirected back to a homepage. Somewhat frustrating experience, don't you think?

Well, let's solve this little problem with some help from [symfony2 authentication listener] (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php). More specifically, by exploiting [already existing feature] (https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php#L270) for login form. This feature is actually a simple session parameter that is set the moment

Redirecting to last visited page after registration.

Imagine this scenario: A user on your webpage finds an awesome link, but it's only open to registered users.

Normally our user will be redirected to login page and if they already have an account, they can login and get redirected to the page they were looking for. This is possible thanks to Symfony2 Authentication listener where a session parameter is set to what the last page was before firewall was hit and then purged the moment you login.

But what if they're a new user? After clicking another link to register and filling out the form, how can you redirect them back to the page they're actually looking for?

@inoryy
inoryy / gist:2151792
Created March 21, 2012 19:34
sortable ex
/**
*
* @Gedmo\SortableGroup
* @ORM\Column(name="fieldName", type="integer")
*/
protected $field;
/**
* @var integer
* @Gedmo\SortablePosition
@inoryy
inoryy / database_dump.sh
Created August 16, 2012 17:54
Simple database backup & email script
#!/bin/bash
mysqldump <db_name> | gzip > /path/to/backups/<db_name>_`date +'%H-%M_%d-%m-%Y'`.sql.gz
echo "<Project name> database backup" | mutt -s "[Backup] `date +'%H:%M %d-%m-%Y'`" <email@email.com> -a /path/to/backups/$(ls /path/to/backups/ -tr | tail -n 1)
--- core/modules/book/book.services.yml
+++ core/modules/book/book.services.yml
@@ -2,3 +2,7 @@
book.manager:
class: Drupal\book\BookManager
arguments: ['@database']
+ access_check.book.removable:
+ class: Drupal\book\Access\BookNodeIsRemovableAccessCheck
+ tags:
+ - { name: access_check }

Keybase proof

I hereby claim:

  • I am inoryy on github.
  • I am inoryy (https://keybase.io/inoryy) on keybase.
  • I have a public key whose fingerprint is AE1C 94AE 75A4 4DF3 C4EA 99BE 981B B6DB 559A 2267

To claim this, I am signing this object:

<?php
final class FormTypes {
const HIDDEN = 'hidden';
const TEXT = 'text';
// ...
private __constructor() {}
}
import pandas
from sklearn.linear_model import LogisticRegression
from sklearn import cross_validation
def sanitize(dataset):
dataset["Age"] = dataset["Age"].fillna(dataset["Age"].median())
dataset["Fare"] = dataset["Fare"].fillna(dataset["Fare"].median())
dataset.loc[dataset["Sex"] == "male", "Sex"] = 0
dataset.loc[dataset["Sex"] == "female", "Sex"] = 1
@inoryy
inoryy / pnorm.py
Created March 16, 2016 17:35
Normal Distribution via Box–Muller transform
from random import random
from math import log, cos, sin, sqrt, pi
# Implementation of Box-Muller transform to
# generate two random numbers from N(mu, sigma) distribution
def pnorm(mu = 0, sigma = 1):
r = sqrt(-2*log(random()))
a = 2*pi*random()
return sigma*r*cos(a) + mu, sigma*r*sin(a) + mu
#!/home/inoryy/anaconda3/bin/python
import sys, time
from math import sqrt, acos, pi, cos, sin
from decimal import Decimal, ROUND_HALF_UP
class Point(object):
__slots__ = 'x', 'y'
def __init__(self, x, y):