Skip to content

Instantly share code, notes, and snippets.

View morgant's full-sized avatar

Morgan Aldridge morgant

View GitHub Profile
@pmbuko
pmbuko / rename_mac_to_primary_local_user.sh
Last active August 29, 2015 14:27
This script will change the hostname of a Mac to a dot-separated version of the full name of the most-commonly-logged-in user with a local home found under /Users.
#!/bin/bash
# This script will change the hostname of a Mac to a dot-separated version
# of the full name of the most-commonly-logged-in user with a local home.
# Give a list of usernames to ignore, separated by spaces
ignore_list=( root admin administrator bukowinskip )
# Get a list of usernames sorted by login frequency, limited to the last 100 logins
login_list=$(last -t console -100 | \
@splorp
splorp / gist:776730
Created January 12, 2011 19:36
Preferences to disable local storage in Safari
# To disable Safari’s annoying modal local database
# storage dialog, use this Terminal command:
defaults write com.apple.Safari WebKitDatabasesEnabledPreferenceKey -bool false
# To disable local storage altogether, use this command:
defaults write com.apple.Safari WebKitLocalStorageEnabledPreferenceKey -bool false
@ekoeppen
ekoeppen / gist:854390
Created March 4, 2011 09:28
Newton Voyager Platform Driver Interface
#include <NewtonGestalt.h>
#include <NewtonScript.h>
#include <BufferList.h>
#include <BufferSegment.h>
class TGPIOInterface
{
public:
NewtonErr ReadGPIOData (UByte, ULong *);
};
@kangax
kangax / gist:1051534
Created June 28, 2011 16:28 — forked from maxim/progressify.rb
Progressify - a progress bar approximator for smoothness
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Progressify</title>
<script>
var Plot = (function() {
function Point(duration, progress) {
this.duration = duration;
@dpk
dpk / realpath.c
Created February 22, 2012 13:44
Command-line interface to realpath(3)
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
int main (int argc, char *argv[]) {
char* instr;
char outstr[PATH_MAX];
instr = argv[1];
@kirkegaard
kirkegaard / ldapconn.php
Created February 16, 2015 22:32
Check if user exists in one or more groups in Apple ldap tree
<?php
$ldapuser = 'user';
$ldappass = 'pass';
// Required groups
$groups = array('cn=group1', 'cn=group2');
// Ldap stuff
$directory = 'directory.example.dk';
@morgant
morgant / compress_and_encrypt-no_exposed_password.txt
Last active July 10, 2018 21:22
Compress & Encrypt to Disk Using OpenSSL in Bash Without Exposing Password
#
# This is the simplest and cleanest way I've come up with for securely compressing (gzip, in this example) & encrypting data to disk with OpenSSL from a bash script without exposing the password to inspection of process or environment variable using `ps` and the likes. Naturally, `cat` is just used as an example so the data can come from anywhere. If the compressed data is to be sent via email instead of written to disk, don't use '-out' and use '-a' to base64 encode the compressed data.
#
# References:
# http://www.madboa.com/geek/openssl/#encrypt-simple
# http://unix.stackexchange.com/questions/29111/safe-way-to-pass-password-for-1-programs-in-bash#answer-29186
# http://stackoverflow.com/questions/6607675/shell-script-password-security-of-command-line-parameters/6607773#6607773
# https://gist.github.com/philfreo/2321650
cat "$file" | gzip -c | openssl enc -e -salt -aes-256-cbc -pass fd:3 -out "$file.gz.enc" 3<<<"$password"
@gruber
gruber / Reply.scpt
Last active October 22, 2020 19:48
Prompt with options to "Reply" or "Reply All" when replying to a message with multiple recipients in Apple Mail for Mac OS X. Also does away with top-posting.
tell application "Mail"
set _sel to get selection
if (count of _sel) > 1 then
-- multiple message selection, usually a conversation thread
choose from list {"Reply", "Reply All"} with prompt "Unknown recipient count." default items {"Reply"}
try
set _menu_command to item 1 of the result
on error
return
@edwardsharp
edwardsharp / bucket_sync_service.rb
Created May 10, 2016 23:18
ruby class to copy from one aws s3 bucket to another based on bantic/bucket_sync_service.rb
require 'aws-sdk'
class BucketSyncService
attr_reader :from_bucket, :to_bucket, :logger
attr_accessor :debug
DEFAULT_ACL = "public-read"
def initialize(from_bucket, to_bucket)
@samuelcole
samuelcole / ultimate_url_re.js
Created April 14, 2011 19:44
Ultimate Url Regex!
/*
Based off of Gruber's awesome url regex: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
In addition:
- Should match 'example.com', 'google.net', 'google.org'. (only com, net, and org are whitelisted).
- Should not match 'sam@samuelcole.name'.
*/
var URL_RE = /(?:(?=[\s`!()\[\]{};:'".,<>?«»“”‘’])|\b)((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/|[a-z0-9.\-]+[.](?:com|org|net))(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))*(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]|\b))/gi