Skip to content

Instantly share code, notes, and snippets.

View ewistrand's full-sized avatar
🦸‍♂️

Eric Wistrand ewistrand

🦸‍♂️
  • Truly Free
  • Traverse City Michigan
View GitHub Profile
@ewistrand
ewistrand / loop-paged-response.py
Created October 10, 2023 16:30
Loop through paged request with Python
import requests
resp = requests.get('https://url.com/api/endpoint').json()
data = resp['data']
while resp['next_page_url']:
resp = requests.get(resp['next_page_url']).json()
data.extend(resp['data'])
@ewistrand
ewistrand / nl2p.php
Last active February 17, 2020 20:12
Turn line breaks into paragraph tags
if(! function_exists('nl2p')) {
function nl2p($str) {
$arr = explode("\n", $str);
$out = '';
for($i = 0; $i < count($arr); $i++) {
if(strlen(trim($arr[$i])) > 0)
$out .= '<p>' .trim($arr[$i]) . '</p>';
}
@ewistrand
ewistrand / split_name.php
Last active February 17, 2020 20:11
Split Name Input into First, Midldle and Last names
if(! function_exists('split_name')) {
function split_name($name) {
$parts = array();
while ( strlen( trim($name)) > 0 ) {
$name = trim($name);
$string = preg_replace('#.*\s([\w-]*)$#', '$1', $name);
$parts[] = $string;
$name = trim( preg_replace('#'.$string.'#', '', $name ) );
}
@ewistrand
ewistrand / paginateCollection.php
Last active February 17, 2020 20:06
Helper function to Paginate a Laravel Collections.
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
if(! function_exists('paginate'))
{
function paginate($items, $perPage = 15, $page = null)
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
@ewistrand
ewistrand / clear-gitignore.txt
Created July 19, 2019 19:08 — forked from ainsofs/gist:2b80771a5582b7528d9e
Clear .gitignore cache
# remove specific file from git cache
git rm --cached filename
# remove all files from git cache
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@ewistrand
ewistrand / Larson Construction Group config.json
Created July 9, 2016 18:19 — forked from anonymous/config.json
Bootstrap Customizer Config
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#6fb353, 6.5%)",
"@brand-success": "#5cb85c",
@ewistrand
ewistrand / feature-image-metabox-text.php
Created July 5, 2016 19:43
Add text to featured image metabox
/** CHANGE FEATURED IMAGE META BOX CONTENT **/
add_filter( 'admin_post_thumbnail_html', 'add_featured_image_instruction');
function add_featured_image_instruction( $content ) {
$content .= '<p><i>The featured image should be 1920x665 pixels</i></p>';
return $content;
}
div:before {
position: absolute;
content: " ";
display: block;
left: 0;
top: 0;
border-right: 50px solid #fff;
border-bottom: 50px solid transparent;
width: 50% !important;
height: 0;
@ewistrand
ewistrand / gulpfile.js
Created March 3, 2016 14:25
Underscores Gulp File for Sass
var gulp = require('gulp');
var sass = require('gulp-sass');
gulp.task('styles', function() {
gulp.src('sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./'));
});
//Watch task
@ewistrand
ewistrand / wp-tags-to-search.php
Created February 25, 2016 13:21
Add tags to wordpress search
<?php
// ADD Tags To SEARCH
function my_smart_search( $search, &$wp_query ) {
global $wpdb;
if ( empty( $search ))
return $search;
$terms = $wp_query->query_vars[ 's' ];
$exploded = explode( ' ', $terms );