Skip to content

Instantly share code, notes, and snippets.

View escuccim's full-sized avatar

Eric A. Scuccimarra escuccim

View GitHub Profile
escuccim / SetLanguage.php
Created January 10, 2017 12:30
Laravel Middleware to set language from subdomain
View SetLanguage.php
namespace App\Http\Middleware;
use Closure;
class SetLanguage
* Handle an incoming request.
escuccim / helpers.php
Created January 10, 2017 12:32
Laravel Helper to set language from session
View helpers.php
function setLanguage(){
// set the app locale
App::setLocale( session('locale') ? session('locale') : config('app.locale'));
// set PHP locale for formatting dates
if(App::getLocale() == 'fr')
setlocale(LC_TIME, 'fr_CH.UTF-8');
escuccim / helpers.php
Last active January 11, 2017 11:20
Laravel helper function to get translated page title and description from lang file metadata.php
View helpers.php
function getMetaData($type){
// set a default so it doesn't break phpunit
$page = $_SERVER['REQUEST_URI'];
$page = "/";
// if we are looking at a blog article just use the default for the main blog page
if(strpos($page, 'blog') !== false) {
$page = '/blog';
escuccim / metadata.php
Last active January 11, 2017 11:21
Laravel MetaData translation file
View metadata.php
return [
'default-title' => 'Default page title',
'default-description' => 'My whatever whatever web site default description text',
'/termsandconditions-title' => 'Terms and Conditions',
'/termsandconditions-description' => 'Terms and conditions for the website',
'/privacypolicy-title' => 'Privacy Policy',
'/privacypolicy-description' => 'Privacy policy for the website',
escuccim / BackupDB.php
Created January 30, 2017 15:04
Laravel Command to Backup File to Amazon S3
View BackupDB.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Aws\Laravel\AwsFacade as AWS;
class BackupDB extends Command
escuccim / unaccent.php
Created April 12, 2017 07:49
PHP Function to Remove Accents from Strings
View unaccent.php
function unaccent($string)
return preg_replace('~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);~i', '$1', htmlentities($string, ENT_COMPAT, 'UTF-8'));
escuccim / gist:e8c49993616468e6305e062e4d5765b2
Created April 12, 2017 07:59
MySQL Query to delete duplicate rows
View gist:e8c49993616468e6305e062e4d5765b2
DELETE n1 FROM names n1, names n2 WHERE > AND =
escuccim /
Created January 28, 2018 10:55
Code to sync columns for two pandas dataframes
# For two dataframes X1 and X2, sync columns in X2 to be same as X1 in same order.
missing_cols = set( X1.columns ) - set( X2.columns )
for c in missing_cols:
X2[c] = 0
X2 = X2[X1.columns]
escuccim /
Created April 17, 2018 09:01
Python Function to Flatten Nested Lists
# this works just like "unlist" in R
def flatten(l):
out = []
for item in l:
if isinstance(item, (list, tuple)):
return out
escuccim /
Created June 7, 2018 11:21
mean encoding in python
# mean encoding
means = X_tr.groupby(col).target.mean()
train_new[col+'_target_mean'] = train_new[col].map(means)
val_new[col+'_target_mean'] = val_new[col].map(means)