Skip to content

Instantly share code, notes, and snippets.

@jduhls
jduhls / git_migrate.sh
Created December 21, 2017 22:47
Migrate a git repo
mkdir TEMP_REPO_FOLDERNAME # create a new folder
cd TEMP_REPO_FOLDERNAME
git init --bare .git # create a bare repo
git remote add origin SOURCE_REMOTE_URL # add a remote
git fetch origin refs/heads/*:refs/heads/* # fetch heads
git fetch origin refs/tags/*:refs/tags/* # fetch tags
git init # reinit work tree
git checkout master # checkout a branch
git remote rm origin # remove remote repo url
git remote add origin NEW_REMOTE_URL # new remote url
/* Usage: $.selectorCache('#element')
* or to refresh cache: $.selectorCache('#element', true)
*
* Credit: https://ttmm.io/tech/selector-caching-jquery/
*/
(function($){
var debug = false;
function SelectorCache() {
var collection = {};
@jduhls
jduhls / bootstrap-modal-animate-css.js
Last active May 7, 2017 05:42
Bootstrap Modal + Animate.css
/*
* Tested With:
* animate.css (v3.5.1): https://github.com/daneden/animate.css
* Bootstrap modal.js (v3.3.6): http://getbootstrap.com
* Usage: Be sure your modal div has class "animated" instead of "fade"
* and add the new data attributes for animate.css animation to use.
* Example:
* <div id="my-modal" class="modal animated" data-animate-css-show="fadeInRight" data-animate-css-hide="fadeOutLeft">
*
* You can also use $(el).animateCss(class) to animate.css other stuff.
@jduhls
jduhls / convert_utf8mb4.sql
Last active May 6, 2016 16:56
Convert an entire database to utf8mb4 (credit: http://stackoverflow.com/a/24391682)
delimiter //
DROP PROCEDURE IF EXISTS convert_database_to_utf8mb4 //
CREATE PROCEDURE convert_database_to_utf8mb4()
BEGIN
DECLARE table_name VARCHAR(255);
DECLARE done INT DEFAULT FALSE;
DECLARE cur CURSOR FOR
@jduhls
jduhls / index.js
Last active October 28, 2017 15:36
nodejs randomly long request simulator
var http = require('http');
//Select the port on which to run this delayed request server:
var port = 8080;
//Select the maximum number of seconds to delay requests to this server:
var seconds = 1440; //Iknowright?!?! I needed a delay of up to 24 minutes!
//Gets random delay time in ms (maximum of var seconds):
var timeout = Math.floor((Math.random() * seconds) + 1) * 1000;
var server = http.createServer(function (req, res) {
//IMPORTANT! Override nodejs default 2 minute connection timeout - never timeout connections:
(function($, Drupal){
// Our function name is prototyped as part of the Drupal.ajax namespace, adding to the commands:
Drupal.ajax.prototype.commands.custom_javascript_function = function(ajax, response, status) {
// The value we passed in our Ajax callback function will be available inside the
// response object. Since we defined it as selectedValue in our callback, it will be
// available in response.selectedValue. Usually we would not use an alert() function
// as we could use ajax_command_alert() to do it without having to define a custom