Skip to content

Instantly share code, notes, and snippets.

Eric A. Scuccimarra escuccim

Block or report user

Report or block escuccim

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@escuccim
escuccim / SetLanguage.php
Created Jan 10, 2017
Laravel Middleware to set language from subdomain
View SetLanguage.php
<?php
namespace App\Http\Middleware;
use Closure;
class SetLanguage
{
/**
* Handle an incoming request.
@escuccim
escuccim / helpers.php
Created Jan 10, 2017
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
escuccim / helpers.php
Last active Jan 11, 2017
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
if(isset($_SERVER['REQUEST_URI']))
$page = $_SERVER['REQUEST_URI'];
else
$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
escuccim / metadata.php
Last active Jan 11, 2017
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
escuccim / BackupDB.php
Created Jan 30, 2017
Laravel Command to Backup File to Amazon S3
View BackupDB.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Aws\Laravel\AwsFacade as AWS;
class BackupDB extends Command
{
/**
@escuccim
escuccim / unaccent.php
Created Apr 12, 2017
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
escuccim / gist:e8c49993616468e6305e062e4d5765b2
Created Apr 12, 2017
MySQL Query to delete duplicate rows
View gist:e8c49993616468e6305e062e4d5765b2
DELETE n1 FROM names n1, names n2 WHERE n1.id > n2.id AND n1.name = n2.name
@escuccim
escuccim / synccolumns.py
Created Jan 28, 2018
Code to sync columns for two pandas dataframes
View synccolumns.py
# 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
escuccim / flatten.py
Created Apr 17, 2018
Python Function to Flatten Nested Lists
View flatten.py
# this works just like "unlist" in R
def flatten(l):
out = []
for item in l:
if isinstance(item, (list, tuple)):
out.extend(flatten(item))
else:
out.append(item)
return out
@escuccim
escuccim / mean_encode.py
Created Jun 7, 2018
mean encoding in python
View mean_encode.py
# 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)
You can’t perform that action at this time.