Skip to content

Instantly share code, notes, and snippets.

@jhthorsen
jhthorsen / jquery.fixedheader.js
Created November 2, 2012 23:24
Fixed table header
(function($) {
$.fn.fixedHeader = function() {
this.each(function() {
var $table = $(this);
var $dummy = $('<table><tr></tr></table>');
var $th = $table.find('thead:first tr:first th').clone();
var $td = $table.find('tbody:first tr:first td');
var place = function() {
$dummy.css({
@jhthorsen
jhthorsen / queue.js
Created November 22, 2012 10:52
Queue callbacks in javascript
/*
* queue.js allow you to run async callbacks in serial.
*/
var Queue = {
callbacks: [],
idle: true,
// Queue.add(function() {});
// Used to add a new function to the callback queue
@jhthorsen
jhthorsen / jquery.disableouterscroll.js
Created November 22, 2012 23:55
disable outer scroll
(function($) {
$.fn.disableOuterScroll = function() {
return this.bind('mousewheel DOMMouseScroll', function(e) {
var scrollTo = null;
if(e.type == 'mousewheel') {
scrollTo = (e.originalEvent.wheelDelta * -1);
}
else if(e.type == 'DOMMouseScroll') {
scrollTo = 40 * e.originalEvent.detail;
@jhthorsen
jhthorsen / add-style-attr.js
Last active December 15, 2015 21:29
How to add inline styling (<tag style="...">) from calculated styles.
/*
add inline styling (<tag style="...">) from calculated css.
1. Paste the code below into the javascript console
2. Go back to the "Elements" view, where all the selected element and all sub elements has inline styling
*/
// add to whole document
$('body, body *').each(function(){var $e=$(this);$e.attr('style',$.map(["opacity","filter","azimuth","background","background-attachment","background-color","background-image","background-position","background-repeat","border","border-collapse","border-color","border-spacing","border-style","border-top","border-right","border-bottom","border-left","border-top-color","border-right-color","border-bottom-color","border-left-color","border-top-style","border-right-style","border-bottom-style","border-left-style","border-top-width","border-right-width","border-bottom-width","border-left-width","border-width","bottom","caption-side","clear","clip","color","content","counter-increment","counter-reset","cue","cue-after","cue-before","cursor","direction","display","elevati
$.fn.passThrough = function() {
this.hover(
function() { $(this).fadeTo('fast', 0.2); },
function() { $(this).fadeTo('fast', 1.0); }
);
this.each(function() {
var self = this;
var last;
$(self).bind('click mousemove mouseout', function (e) {
#!/usr/bin/env perl
package No::Headers;
use Mojo::Base "Mojo::Headers";
sub to_string { "" };
package main;
use Mojolicious::Lite;
get "/" => sub {
my $c = shift;
@jhthorsen
jhthorsen / mojo.log
Created July 24, 2014 12:44
make a new mojolicious dist #mojo
git remote update
git rebase origin/master
# no diff
git tag v5.17
perl Makefile.PL; make manifest; make dist
1) make sure master is in a good state
2) tag release
3) perl Makefile.PL; make manifest; make dist
4) upload release, ...optional...
@jhthorsen
jhthorsen / watch-port.sh
Last active May 13, 2022 01:04
Fix iwlwifi power save
#!/bin/sh
EXPRESSION=${1:-"tcp port 22"};
DEVICE="wlan0";
while tcpdump -p -c 1 -i $DEVICE "$EXPRESSION"; do
iwconfig $DEVICE power off;
sleep 600;
iwconfig $DEVICE power on;
done
@jhthorsen
jhthorsen / dom-events.js
Last active January 8, 2022 21:06
emit, on, once in pure javascript
Object.prototype.emit = function(name, d) {
this.dispatchEvent(new CustomEvent(name, { detail: d }));
return this;
};
Object.prototype.on = function(name, cb) {
this.addEventListener(name, cb, false);
return cb;
};
Object.prototype.once = function(name, cb) {
var wrapper = function() {
plugin 'OAuth2', {
google => {
key => 'public app id from google',
secret => 'private secret from google',
},
};