Skip to content

Instantly share code, notes, and snippets.

@mrsweaters
mrsweaters / nohup.sh
Last active April 9, 2020 17:59
NOHUP
nohup script > script.out 2>&1 &
nohup sh -c 'mysqldump -u user db > db.sql' &
@mrsweaters
mrsweaters / command.sh
Created September 5, 2019 18:43
ld: library not found for -lssl error
To fix for a manual gem install:
brew install openssl
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
To fix for all bundle installs:
brew install openssl
bundle config --global build.mysql2 --with-opt-dir="$(brew --prefix openssl)"
bundle install
@mrsweaters
mrsweaters / sample_text.rb
Created August 13, 2019 17:10
Get organic samples and backfill from constants.
def self.sample_text(attr, scope: self, size: 3)
@organic = scope.last(size).map{|item| ActionController::Base.helpers.strip_tags(item.public_send(attr)) }.compact
defaults = "#{scope}::SAMPLE_#{attr.upcase}".constantize
(@organic + defaults).uniq.first(size)
end
const SvgInjectFillContentDirective = $compile => ({
restrict: "ECA",
priority: -400,
require: "svgInject",
link(scope, $element, $attr, ctrl) {
if (toString.call($element[0]).match(/SVG/)) {
// WebKit: https://bugs.webkit.org/show_bug.cgi?id=135698 --- SVG elements do not
// support innerHTML, so detect this here and try to generate the contents
// specially.
$element.empty();
@mrsweaters
mrsweaters / prefetch.js
Created February 1, 2019 02:48
TurboLinks with Prefetch on Hover
const hoverTime = 300;
const fetchers = {};
function prefetch(url) {
const iframe = document.createElement('iframe');
iframe.hidden = true;
iframe.src = url;
iframe.addEventListener('load', () => {
const snapshot = Turbolinks.Snapshot.fromHTMLElement(iframe.contentDocument.documentElement);
Turbolinks.controller.cache.put(url, snapshot);
@mrsweaters
mrsweaters / status.sh
Created January 7, 2019 21:40
Check Status of SystemD service
systemctl status service-name.service
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
add_header Content-Security-Policy "default-src 'none'; img-src 'self' data: https://helio-assets-prod.zurb.com https://prod-testrun.s3-accelerate.amazonaws.com https://www.gravatar.com *.wp.com https://www.googletagmanager.com https://*.intercomassets.com https://*.intercomcdn.com https://d3utalfm9bp35r.cloudfront.net https://www.google-analytics.com; script-src 'self' 'unsafe-inline' *.algolianet.com *.algolia.net https://js.stripe.com https://*.kissmetrics.com https://cdn.headwayapp.co https://cdnjs.cloudflare.com https://*.intercomcdn.com https://*.intercom.io https://www.googletagmanager.com https://d20luy73ujukeu.cloudfront.net https://www.google-analytics.com; style-src 'self' 'unsafe-inline'; object-src 'none'; media-src 'self' https://*.intercomcdn.com https://d20luy73ujukeu.cloudfront.net; font-src 'self' https://*.intercomcdn.com; connect-src 'self' *.algolianet.com *.algolia.net https://*.kissmetrics.com h
@mrsweaters
mrsweaters / pg_check.rb
Created October 30, 2018 23:13
PG Version Check
def pg_exists?
begin
Gem::Specification::find_all_by_name('pg', '1.1.3')
rescue Gem::MissingSpecVersionError
false
end
end
@mrsweaters
mrsweaters / count.sh
Created October 29, 2018 21:17
Count files in a directory
ls -l . | egrep -c '^-'
@mrsweaters
mrsweaters / usingRootScopeController.js
Created October 18, 2018 16:43 — forked from pablotdl/usingRootScopeController.js
AngularJS service instead of $rootScope
'use strict'
/**
* A sample controller that stores data in the $rootScope
*/
angular.module('sample').controller('usingRootScopeController', ['$rootScope', '$scope', function ($rootScope, $scope) {
// Resets the list of items.
$scope.reset = function () {
$rootScope.someList = [];
}