Skip to content

Instantly share code, notes, and snippets.

View tbleckert's full-sized avatar
💭
I may be slow to respond.

Tobias Bleckert tbleckert

💭
I may be slow to respond.
View GitHub Profile
@sindresorhus
sindresorhus / esm-package.md
Last active May 3, 2024 10:19
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@windyjonas
windyjonas / sanitize-filename.php
Created March 28, 2017 13:35
Sanitize decomposed filenames in WordPress
class Sanitize_Filename {
public function __construct() {
add_filter( 'wp_handle_upload_prefilter', [ $this, 'sanitize_decomposed_utf8_file' ] );
}
/**
* Sanitize the filename in a file object
*
* @param array $file In file
@fabricelejeune
fabricelejeune / Efficient font stack with Sass.md
Last active March 16, 2023 23:52
Efficient font stack with Sass

Efficient font stack with Sass

The strength of Sass is the mixins and functions. Being able to automate many of the repetitive coding for CSS is both amazing in building and maintaining a clean and efficient code. I often find many developers creating complex systems for simple tasks, such as managing a font stack. This can be tedious to set up and employ. In this article, I will explain how I automate this system.

The font stack is one of those problems which are often solved by simple variables. In this instance, it makes a lot of sense and is easy enough to work with. But when you work with our (beloved) designers from Dogstudio, you can be sure of having to use lot of font variants. It quickly happens that I do not remember all the properties of each variants. And when I say "use lot of font variants", I mean at least 15 in most cases.

Sass maps to the rescue

Instead of simply define variables, I will ceate a font stack map and a mixin to use the map easily.

@kottenator
kottenator / simple-pagination.js
Created July 13, 2015 20:44
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@imjasonh
imjasonh / markdown.css
Last active February 12, 2024 17:18
Render Markdown as unrendered Markdown (see http://jsbin.com/huwosomawo)
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@acrookston
acrookston / ImageZoom.swift
Created January 14, 2015 19:12
Swift image zoom
// The image is originally animated on to the view controller then added to the scroll view.
// So, there might be some animation residue in here.
// Class needs: <UIScrollViewDelegate>
func viewDidLoad() {
let width = UIScreen.mainScreen().bounds.size.width
let aspect: CGFloat = width / shotWidth
var frame = CGRectMake(0, 0, shotWidth * aspect, shotHeight * aspect)
self.scrollView = UIScrollView(frame: frame)
@makenova
makenova / Difference between debounce and throttle.md
Last active February 22, 2023 03:09
Javascript function debounce and throttle

Difference between Debounce and Throttle

Debounce

Debounce a function when you want it to execute only once after a defined interval of time. If the event occurs multiple times within the interval, the interval is reset each time.
Example A user is typing into an input field and you want to execute a function, such as a call to the server, only when the user stops typing for a certain interval, such as 500ms.

Throttle

@tbrianjones
tbrianjones / free_email_provider_domains.txt
Last active April 24, 2024 10:24
A list of free email provider domains. Some of these are probably not around anymore. I've combined a dozen lists from around the web. Current "major providers" should all be in here as of the date this is created.
1033edge.com
11mail.com
123.com
123box.net
123india.com
123mail.cl
123qwe.co.uk
126.com
150ml.com
15meg4free.com
@grena
grena / format-size.php
Last active January 25, 2019 09:34
Snippet to convert bytes size to human readable size in PHP.
<?php
function filesize_formatted($path)
{
$size = filesize($path);
$units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
}
@jbwyme
jbwyme / Mixpanel PHP API Example Index.php
Last active August 4, 2017 12:32
Mixpanel PHP API Usage
<?php
require_once("/path/to/vendor/mixpanel/mixpanel-php/lib/Mixpanel.php"); // import the Mixpanel class
// get the Mixpanel singelton (will be created if it doesn't exist)
$mp = Mixpanel::getInstance("MIXPANEL_PROJECT_TOKEN");
// this would likely come from a database or session variable
$user_id = 12345;