This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/smtp' | |
def send_email (to:, msg:, subject:, from_name:, from:, password:) | |
message = "From: #{from_name} <#{from}>\n" \ | |
"To: <#{to}>\n"\ | |
"Subject: #{subject}\n"\ | |
"#{msg}\n" | |
smtp = Net::SMTP.new 'smtp.gmail.com', 587 | |
smtp.enable_starttls | |
smtp.start('gmail.com', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change the relevant {{ PARTS OF THIS FILE }} for your remote address etc. | |
# Make sure this unit file is named similarly to your mountpoint; e.g., for /mnt/mymountpoint name this file mnt-mymountpoint.mount | |
# On Ubuntu: | |
# $ sudo cp mnt-mymountpoint.mount /lib/systemd/system/ | |
# $ sudo systemctl enable mnt-mymountpoint.mount | |
# $ sudo systemctl start mnt-mymountpoint.mount | |
# On Fedora: | |
# $ sudo cp mnt-mymountpoint.mount /etc/systemd/system | |
# $ sudo systemctl enable mnt-mymountpoint.mount | |
# $ sudo systemctl start mnt-mymountpoint.mount |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Deletes currently playing song in Clementine (works on GNU/Linux). Helps thin out a music library. | |
# 1. chmod a+x rmcl | |
# 2. add to PATH | |
# 3. use in GNOME by Alt+F2 + 'rmcl', easy | |
function is_playing() { | |
qdbus org.mpris.MediaPlayer2.clementine /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player PlaybackStatus | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function roundTiesToEven(n) { | |
var TOLERANCE = 1e-6 | |
if (Math.abs(n%1 - 0.5) <= TOLERANCE) { | |
var f = Math.floor(n) | |
return f%2 === 0 ? f : f+1 | |
} else { | |
return Math.round(n) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.google.com/search?source=hp&q=%s&oq=%s&btnI=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"database/sql" | |
_ "github.com/lib/pq" | |
"log" | |
) | |
// queryMap is used for quickly running a SQL query that returns only one | |
// row. Important: This shouldn't ever return errors and shouldn't ever | |
// be applied on user input. Ideally, you're querying non-nullable | |
// columns using keys you got from some trusted (non-human) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var urlHostname = function(url) { | |
var a = document.createElement('a') | |
a.href = url | |
return a.hostname | |
} | |
var reProtocol = /https?/, l = document.links | |
for (var idx = 0; idx < l.length; ++idx) { | |
if (urlHostname(l[idx].href) !== window.location.hostname && reProtocol.test(l[idx].href)) { | |
l[idx].setAttribute('target', '_blank') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Y = f => (x => x(x))(x => f(v => x(x)(v))) | |
// example | |
let factorial = Y(fact => n => n === 1 ? 1 : n*fact(n-1)) | |
factorial(4) // => 24 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-columns | |
[_] | |
#{"part_id" "name" "image_paths"}) | |
(defn update | |
[_ _ _] | |
"UPDATED!!") | |
(defmacro UPDATER | |
[table] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ clang++ -std=c++11 -O3 leftpad.cc -o leftpad | |
// $ ./leftpad | |
#include <string.h> | |
#include <stdio.h> | |
namespace leftpad { | |
enum Dirn { | |
Left = 0, | |
Right = 1, |