Skip to content

Instantly share code, notes, and snippets.

@tayhimself
tayhimself / ProgrammaticNotebook.ipynb
Created August 31, 2022 13:36 — forked from fperez/ProgrammaticNotebook.ipynb
Creating an IPython Notebook programatically
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tayhimself
tayhimself / d3-test.html
Created August 25, 2022 18:53
Reminder of steps needed to create a plot
<!DOCTYPE html>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<div id="chart"></div>
<style>
.grid line {
stroke: #ddd;
}
@tayhimself
tayhimself / scroll-affix.js
Created August 19, 2022 14:30
Affix sidebar vanilla js
// element height that we want to scroll
let elheight = document.getElementById("check-sidebar").offsetHeight
window.addEventListener('scroll', (e) => {
//last_known_scroll_position = window.scrollY;
let scrollTop = window.pageYOffset;
if( scrollTop > elheight ){
document.getElementById('check-sidebar').style.top="40px";
document.getElementById('check-sidebar').style.position="fixed";
}
from flask import Flask, url_for
from werkzeug.urls import url_encode
app = Flask(__name__)
def cdn_url_builder(error, endpoint, values):
if endpoint != 'cdn':
return
@tayhimself
tayhimself / cspheader.php
Last active September 25, 2021 14:59 — forked from phpdave/cspheader.php
CSP Header for PHP or Apache or .htaccess - Content Security Protocol
<?
//CSP only works in modern browsers Chrome 25+, Firefox 23+, Safari 7+
$headerCSP = "Content-Security-Policy:".
"connect-src 'self' ;". // XMLHttpRequest (AJAX request), WebSocket or EventSource.
"default-src 'self';". // Default policy for loading html elements
"frame-ancestors 'self' ;". //allow parent framing - this one blocks click jacking and ui redress
"frame-src 'none';". // vaid sources for frames
"media-src 'self' *.example.com;". // vaid sources for media (audio and video html tags src)
"object-src 'none'; ". // valid object embed and applet tags src
"report-uri https://example.com/violationReportForCSP.php;". //A URL that will get raw json data in post that lets you know what was violated and blocked
SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN=32768;
SET @tables = NULL;
SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables
FROM information_schema.tables
WHERE table_schema = (SELECT DATABASE());
SELECT IFNULL(@tables,'dummy') INTO @tables;
SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE stmt FROM @tables;
@tayhimself
tayhimself / get-image-urls.js
Created November 12, 2020 23:55 — forked from tobek/get-image-urls.js
Save images from chrome inspector/dev tools network tab
/* open up chrome dev tools (Menu > More tools > Developer tools)
* go to network tab, refresh the page, wait for images to load (on some sites you may have to scroll down to the images for them to start loading)
* right click/ctrl click on any entry in the network log, select Copy > Copy All as HAR
* open up JS console and enter: var har = [paste]
* (pasting could take a while if there's a lot of requests)
* paste the following JS code into the console
* copy the output, paste into a text file
* open up a terminal in same directory as text file, then: wget -i [that file]
*/
@tayhimself
tayhimself / php-int.md
Created July 13, 2018 22:10
PHP intl extension using macOS 10.13 PHP 7.1.x

If you're using brew you need to do nothing. weprovide/valet-plus#127

If you're using the native macos PHP, make sure php is running fine, and see what modules are installed

$php -m

You will see a bunch of modules but they're missing intl

Go here and choose the install script you need to go https://php-osx.liip.ch/

@tayhimself
tayhimself / README.md
Created July 11, 2018 16:50 — forked from joyrexus/README.md
form-data vs -urlencoded

Nice answer on stackoverflow to the question of when to use one or the other content-types for POSTing data, viz. application/x-www-form-urlencoded and multipart/form-data.

“The moral of the story is, if you have binary (non-alphanumeric) data (or a significantly sized payload) to transmit, use multipart/form-data. Otherwise, use application/x-www-form-urlencoded.”


Matt Bridges' answer in full:

The MIME types you mention are the two Content-Type headers for HTTP POST requests that user-agents (browsers) must support. The purpose of both of those types of requests is to send a list of name/value pairs to the server. Depending on the type and amount of data being transmitted, one of the methods will be more efficient than the other. To understand why, you have to look at what each is doing

@tayhimself
tayhimself / GulpRevVersionStrategy.php
Created October 26, 2017 22:47
VersionStrategy for using assets versioned with gulp-rev in Symfony
<?php
namespace AppBundle\Twig;
use Exception;
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
class GulpRevVersionStrategy implements VersionStrategyInterface
{
private $manifestFilename;