Skip to content

Instantly share code, notes, and snippets.

@lewiswalsh
lewiswalsh / gist:c491a059800d18f0e811
Created March 18, 2015 15:29
jQuery: Hide on click outside of element
$(document).on('mouseup', function(e){
var my_element = $('<my_element_selector>');
if(
!my_element.is(e.target) // if the target of the click isn't the live_search_results...
&& my_element.has(e.target).length === 0 // ...nor a descendant of the live_search_results
&& my_element.is(":visible") // Is it even showing on screen?
){ my_element.slideUp(); }
});
@lewiswalsh
lewiswalsh / gist:e0ee9b6eedce9c825274
Created February 8, 2016 16:37
Strip problematic characters from files
sed -i -e 's/\r$//' <file or files>
@lewiswalsh
lewiswalsh / gist:2f12698db38e4491c7d9
Created March 19, 2016 14:26
Quickly resize a video to make it smaller with FFmpeg
ffmpeg -i input.mp4 -filter:v scale=480:-1 -c:a copy output.mp4
@lewiswalsh
lewiswalsh / keybase.md
Created June 20, 2018 20:39
keybase.md

Keybase proof

I hereby claim:

  • I am lewiswalsh on github.
  • I am lewiswalsh (https://keybase.io/lewiswalsh) on keybase.
  • I have a public key ASCsSgDIC4Lp66CimJ8WmCzX70CIzBFMrsRhCx_Np_L4LAo

To claim this, I am signing this object:

@lewiswalsh
lewiswalsh / vob2mp4.sh
Created July 24, 2018 11:53
Convert DVD VOB files to MP4
#!/bin/bash
ffmpeg -i "concat:VTS_01_1.VOB|VTS_01_2.VOB|VTS_01_3.VOB|VTS_01_4.VOB|VTS_01_5.VOB" -strict -2 outfile.mp4
@lewiswalsh
lewiswalsh / findpi.ps1
Created August 3, 2018 09:13
Find raspberry pi on the network
arp -a | findstr b8-27-eb
@lewiswalsh
lewiswalsh / gist:1c54b213541e8f13e497f1e3a20e8e14
Created August 12, 2018 20:54
See time and other stats about a command
/usr/bin/time -v <your command or program with arguments>
@lewiswalsh
lewiswalsh / insert_from_tables.sql
Created September 3, 2018 18:20
Insert into table from two other tables on common field
INSERT INTO ab_product_categories (category_id, product_id)
SELECT c.id AS category_id, p.id as product_id
FROM ab_products AS p, ab_categories AS c
WHERE c.old_id = p.old_cat_id;
@lewiswalsh
lewiswalsh / gist:71a605c3c6f18d430466af57897b90f8
Created June 7, 2020 13:38
Cat a file with line numbers
cat -n <filename>
@lewiswalsh
lewiswalsh / upsert.js
Last active May 27, 2022 18:37
KnexJS 'upsert', update on duplicate key else insert #knex #mysql
knex(TABLE_NAME)
.insert({ data : data })
.onConflict(PRIMARY_KEY)
.merge()
.then((res) => {
...
})
.catch((err) => {
...
});