Skip to content

Instantly share code, notes, and snippets.

@iangreenleaf
iangreenleaf / bitcoin_idle
Created June 2, 2011 02:04
Bitcoin mining when idle
#!/bin/bash
# Monitors for signals from gnome-screensaver and activates or deactivates
# bitcoin miners accordingly.
# Params to the mining programs are all hardcoded. Change 'em manually. Leave the "&"s.
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'" | \
while read line; do
case "$line" in
@ninnypants
ninnypants / remove-empty-p.php
Last active January 3, 2023 01:11
Remove empty p tags from WordPress posts
<?php
add_filter( 'the_content', 'remove_empty_p', 20, 1 );
function remove_empty_p( $content ){
// clean up p tags around block elements
$content = preg_replace( array(
'#<p>\s*<(div|aside|section|article|header|footer)#',
'#</(div|aside|section|article|header|footer)>\s*</p>#',
'#</(div|aside|section|article|header|footer)>\s*<br ?/?>#',
'#<(div|aside|section|article|header|footer)(.*?)>\s*</p>#',
'#<p>\s*</(div|aside|section|article|header|footer)#',
@kriskhaira
kriskhaira / .gitignore
Last active March 25, 2019 23:20
My usual .gitignore template
#----------------------------------------------------------------------------
# EMBER-CLI DEFAULT
#----------------------------------------------------------------------------
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
# dependencies
traceroute to 216.81.59.173 (216.81.59.173), 100 hops max, 60 byte packets
1 router1-dal.linode.com (67.18.7.161) 0.698 ms 0.685 ms 0.756 ms
2 xe-2-0-0.car03.dllstx2.networklayer.com (67.18.7.89) 0.341 ms 0.326 ms 0.311 ms
3 po101.dsr02.dllstx2.networklayer.com (70.87.254.77) 0.584 ms 0.663 ms 0.665 ms
4 po22.dsr02.dllstx3.networklayer.com (70.87.255.69) 0.809 ms 0.861 ms 0.947 ms
5 ae17.bbr02.eq01.dal03.networklayer.com (173.192.18.230) 0.501 ms 0.478 ms 0.451 ms
6 ae7.bbr01.eq01.dal03.networklayer.com (173.192.18.208) 0.475 ms 0.653 ms 10gigabitethernet3-1.core1.dal1.he.net (206.223.118.37) 6.020 ms
7 10gigabitethernet3-1.core1.dal1.he.net (206.223.118.37) 1.455 ms 1.581 ms 10gigabitethernet5-4.core1.atl1.he.net (184.105.213.114) 21.941 ms
8 10gigabitethernet5-4.core1.atl1.he.net (184.105.213.114) 22.013 ms 216.66.0.26 (216.66.0.26) 20.970 ms 21.238 ms
9 10.26.26.102 (10.26.26.102) 58.340 ms 56.423 ms 216.66.0.26 (216.66.0.26) 20.832 ms
@sarim
sarim / repairsqlite.sh
Created September 6, 2013 08:14
Sqlite db repair script
#!/bin/bash
DBSTATUS=$(sqlite3 "$1" "PRAGMA integrity_check")
if [ "$DBSTATUS" == "ok" ] ; then
echo DB ALREADY OK
else
echo FIXING CORRUPT DB
TMPDB=$(mktemp -t sarim)
echo ".mode insert
.dump" | sqlite3 "$1" > $TMPDB
@mikermcneil
mikermcneil / using-raw-socket-io-in-sails.js
Created September 17, 2013 18:32
Using raw socket.io functionality in a Sails.js controller
module.exports = {
/**
*
* Using raw socket.io functionality from a Sails.js controller
*
*/
index: function (req,res) {
@SoreThumb
SoreThumb / utm_tracking
Last active December 7, 2017 02:25 — forked from devinsays/utm_tracking
Fork of https://gist.github.com/devinsays/6831221 ; Yes, Devin basically wrote a few lines that I had to expand into 50. :) See some example uses in the content below. This fork allows you to use the current URL to change links on the page-- includes auto-replacement of existing UTM variables.
(function($) {
$.fn.utm_tracking = function(domain, source, medium, campaign) {
$(this).find('a[href^="' + domain + '"]').each(function() {
var url = $(this).attr('href');
$(this).attr( 'href', url + '?utm_source=' + source + '&utm_medium=' + medium + '&utm_campaign=' + campaign );
});
}
$.fn.utm_tracking_via_obj = function(domain, utmObj) {
utmObj = utmObj || $.utm_data_from_url();
$(this).find('a[href^="' + domain + '"]').each(function() {
@tkambler
tkambler / gist:71050d80f1a57ea83c18
Last active August 2, 2024 09:53
Calculate size of used LocalStorage space
/**
* Returns the total amount of disk space used (in MB) by localStorage for the current domain.
*/
var getLocalStorageSize = function() {
var total = 0;
for (var x in localStorage) {
// Value is multiplied by 2 due to data being stored in `utf-16` format, which requires twice the space.
var amount = (localStorage[x].length * 2) / 1024 / 1024;
total += amount;
}
@paulirish
paulirish / what-forces-layout.md
Last active November 15, 2024 16:45
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@joar
joar / jq-insert-var.sh
Last active July 25, 2024 00:55
Add a field to an object with JQ
# Add field
echo '{"hello": "world"}' | jq --arg foo bar '. + {foo: $foo}'
# {
# "hello": "world",
# "foo": "bar"
# }
# Override field value
echo '{"hello": "world"}' | jq --arg foo bar '. + {hello: $foo}'
{