Skip to content

Instantly share code, notes, and snippets.

@adamwathan
adamwathan / promise-take-at-least.js
Last active February 26, 2023 14:25
Promise.takeAtLeast
// Creates a new promise that automatically resolves after some timeout:
Promise.delay = function (time) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time)
})
}
// Throttle this promise to resolve no faster than the specified time:
Promise.prototype.takeAtLeast = function (time) {
return new Promise((resolve, reject) => {
@mwrouse
mwrouse / ReadJSON.html
Last active March 1, 2023 14:19
Reading JSON File Input
<!DOCTYPE html>
<html>
<head>
<title>File Input</title>
</head>
<body>
<input type="file" id="fileInput">
<script src="index.js"></script>
</body>
@kfriend
kfriend / respond_and_process.php
Created March 11, 2016 01:35
PHP: Send response and continue processing
<?php
// Buffer all upcoming output...
ob_start();
// Send your response.
echo "Testing response";
// Get the size of the output.
$size = ob_get_length();
@datasage
datasage / PushId.php
Created February 11, 2016 16:37
Push ID
<?php
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
@max-mapper
max-mapper / readme.md
Last active March 16, 2023 15:18
Video stabilization using VidStab and FFMPEG (Mac OS X)

Video stabilization using VidStab and FFMPEG

Examples here use the default settings, see the VidStab readme on GitHub for more advanced instructions.

Here's an example video I made

Install ffmpeg with the vidstab plugin from homebrew

brew install ffmpeg --with-libvidstab
@scofennell
scofennell / DraggableSortableCheckboxesfortheWordPressCustomizer.js
Last active March 19, 2018 03:46
Draggable/Sortable Checkboxes for the WordPress Customizer
/**
* A jQuery plugin for making a sortable/draggable multi-checkbox.
*/
jQuery( window ).load(function() {
// The li that wraps this whole section of the customizer. Sort of like a fieldset.
var el = jQuery( '.customize-control-checkbox_group' );
jQuery( el ).lxbAfCheckboxGroup();
@vluzrmos
vluzrmos / compat_l5.php
Last active November 1, 2022 20:43
Lumen L5 compatibility helpers. That file should be added on root path of your project... and added to your composer.json
<?php
if(!function_exists('config_path'))
{
/**
* Return the path to config files
* @param null $path
* @return string
*/
function config_path($path=null)
@manuelmeurer
manuelmeurer / paypal_controller.rb
Created March 8, 2014 10:03
Paypal Recurring stuff
class Admin::PaypalController < AdminController
skip_load_and_authorize_resource
before_filter :load_current_account, except: :ipn
skip_before_filter :authenticate_admin_user!, :verify_authenticity_token, :redirect_to_dashboard_if_account_is_disabled, :redirect_to_dashboard_if_maintenance, only: :ipn
rescue_from PaypalNotification::RecordInvalid, with: :notify_airbrake_and_render_nothing
rescue_from PaypalNotification::ResponseInvalid, with: :notify_airbrake_and_render_nothing
rescue_from PaypalNotification::HandlingFailed, with: :notify_airbrake_and_render_nothing
@jsteiner
jsteiner / database_cleaner.rb
Created January 10, 2014 20:31
Database Cleaner
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
@flomotlik
flomotlik / Gemfile
Last active April 6, 2021 13:17
Puma on Heroku
gem 'foreman'
gem 'puma'