Skip to content

Instantly share code, notes, and snippets.

View pfeiffer's full-sized avatar

Mattias Pfeiffer pfeiffer

View GitHub Profile
@pfeiffer
pfeiffer / morph_renderer.js
Last active February 26, 2024 16:34
Turbo MorphRenderer
import { morphElement } from '../../helpers'
import MorphableSnapshot from './morphable_snapshot'
// A Renderer class that will extract morphable elements tagged with [data-turbo-morph] before
// rendering, and morph them back into the new snapshot after rendering, similar to how permanent
// elements are handled by Turbo. Useful for persisting horizontal scroll etc.
//
// Note: A morphable element must have an [id] attribute.
class MorphRenderer {
@pfeiffer
pfeiffer / turbo_hover_preloading.js
Created December 7, 2023 22:30
Turbo Hover Preloading
class Preloader {
static delay = 100
constructor (element) {
this.element = element
this.element.addEventListener("mouseenter", this.didMouseEnter)
this.element.addEventListener("mouseleave", this.didMouseLeave)
}
<?php
require_once('emoji.php'); // Provides a $GLOBALS['emoji_maps'] etc..
function emoji_unified_to_code($text){
return preg_replace_callback($GLOBALS['emoji_maps']['unified_rx'], function($m){
if (isset($m[2]) && $m[2] == "\xEF\xB8\x8E") return $m[0];
$cp = $GLOBALS['emoji_maps']['unified_to_html'][$m[1]];
return "[emoji{$cp}]";
}, $text);
}
Resque.workers.each do |worker|
worker.unregister_worker if Time.parse(worker.started) < 1.day.ago
end
def self.import(subscribers, list_id)
# `subscribers` should be an array of hashed subscribers with :email as key and optionally :data as well.
# Generate CSV:
content = CSV.generate(:force_quotes => true, :col_sep => ";") do |csv|
# First row is the headers row:
fields = [:email]
# Add additional data keys:
if data_keys = subscribers.first[:data].try(:keys)
@pfeiffer
pfeiffer / rbenv-install-system-wide.sh
Created July 20, 2012 11:50 — forked from v1nc3ntlaw/rbenv-install-system-wide.sh
rbenv install ruby 1.9.3-p194 on Debian 6 Squeeze
# Update, upgrade and install development tools:
apt-get update
apt-get -y upgrade
apt-get -y install build-essential git-core curl libssl-dev \
libreadline5 libreadline5-dev \
zlib1g zlib1g-dev \
libmysqlclient-dev \
libcurl4-openssl-dev \
libxslt-dev libxml2-dev
SearchSession.prototype = {
initialize: function(options) {
this.options = options;
this.render();
},
render: function() {
// Run through the criterias:
$.each(this.options.data, function(key, data) {
this.addCriteria(key, data).render();
@pfeiffer
pfeiffer / strace details.txt
Created April 17, 2012 12:34
elasticsearch strace
15265 <... epoll_wait resumed> {}, 8192, 500) = 0
15200 <... epoll_wait resumed> {}, 8192, 1000) = 0
15265 epoll_wait(44, <unfinished ...>
15200 accept(20, 0x7f33b525a270, [28]) = -1 EAGAIN (Resource temporarily unavailable)
15200 epoll_wait(24, <unfinished ...>
15278 <... epoll_wait resumed> {}, 8192, 1000) = 0
15266 <... epoll_wait resumed> {}, 8192, 500) = 0
25861 <... epoll_wait resumed> {}, 8192, 500) = 0
15278 accept(85, <unfinished ...>
25861 epoll_wait(2763, <unfinished ...>
class WorkoutLink < ActiveRecord::Base
belongs_to :workout
YOUTUBE_REGEXP = /youtu(?:\.be\/|be\.com\/watch\?v=)(\w{11})/
VIMEO_REGEXP = /vimeo\.com\/([\d+]+)/
def youtube_video_id
$1 if url =~ YOUTUBE_REGEXP
end
@pfeiffer
pfeiffer / dating.txt
Created January 14, 2012 13:10
Dating
Dating: http://netdate.dk/