Skip to content

Instantly share code, notes, and snippets.

View magnusdahlstrand's full-sized avatar

Magnus Dahlstrand magnusdahlstrand

View GitHub Profile
@magnusdahlstrand
magnusdahlstrand / ExtractSelectionsAsDocuments.jsx
Last active September 10, 2023 14:03
Script for splitting selected objects from one Illustrator file into multiple Illustrator (.ai) files.
// Shortcuts
var doc = app.activeDocument;
var selection = doc.selection;
function main() {
var outputFolder = Folder.selectDialog( 'Select folder for extracted objects.', '~' );
if(!outputFolder) {
alert('You have to select a folder to save the files to!\nExiting.');
return;
@magnusdahlstrand
magnusdahlstrand / muteAdium.sh
Created November 5, 2012 18:35
Rewrites the Adium sound preferences file to mute all sounds.
#!/bin/sh
# It's still a bit quick and dirty, and is only tested on Snow Leopard.
adium_sound_settings_path="/Users/$USER/Library/Application Support/Adium 2.0/Users/Default/Sounds.plist"
temp_file_path="/tmp/muteadium_tmp.xml"
if [ ! -r "$adium_sound_settings_path" -a ! -w "$adium_sound_settings_path" ]; then
echo "Unable to read/write settings file."
exit 1
@magnusdahlstrand
magnusdahlstrand / Documents folder layout
Created October 26, 2012 12:10
Docpad - setup for multiple languages
/src
/documents
/articles
/gallery
/de
/articles
/gallery
/es
/articles
/gallery
@magnusdahlstrand
magnusdahlstrand / findFiles_createDirs
Created September 12, 2012 14:00
Create directories from file names (useful for docpad)
mkdir associated-files && cd $_
find ../source/html/documents/collection -type f -mindepth 3 | gsed -e 's/\/[a-z]\+\///g' | cut -d'/' -f2 | cut -d'.' -f1 | xargs mkdir
@magnusdahlstrand
magnusdahlstrand / gist:2829187
Created May 29, 2012 15:53
Import git repo into another repo while keeping the history of both.
//From http://stackoverflow.com/a/8396318/657977
Switch [NAME] for whatever name you want to call it
Switch [PATH or URL] for the path or url to the repo you want to include.
git remote add [NAME]_remote [PATH or URL]
git fetch [NAME]_remote
git merge -s ours --no-commit [NAME]_remote/master
git read-tree --prefix=[NAME]/ -u [NAME]_remote/master
git commit -m "Imported [NAME] as a subtree."
@magnusdahlstrand
magnusdahlstrand / Gene.py
Created May 16, 2012 16:02
Different implementations of a nonce generator
from random import random
from hashlib import md5
generate_nonce = lambda: md5(str(random())).hexdigest()
# How to:
# 1. Call the generate_nonce function:
print generate_nonce()
@magnusdahlstrand
magnusdahlstrand / Default (OSX).sublime-keymap
Last active October 2, 2015 18:38
User Sublime Text keymap
/*
User settings (shouldn't be overwritten on update)
*/
[
//Scroll down 10 rows
{ "keys": ["ctrl+up"], "command": "scroll_lines", "args": {"amount": 10.0} },
{ "keys": ["ctrl+down"], "command": "scroll_lines", "args": {"amount": -10.0} },
//Switch view by tab order
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },
@magnusdahlstrand
magnusdahlstrand / scriptloader.js
Created March 23, 2012 17:05
Javascript-based script loader
//Source
loadScript = (function(document, tagName) {
var scriptElement = document.getElementsByTagName(tagName)[0];
return function(url) {
var element = document.createElement(tagName);
element.src = element.async = url;
scriptElement.parentNode.insertBefore(element, scriptElement);
}
}(document, 'script'));
@magnusdahlstrand
magnusdahlstrand / gist:1923948
Created February 27, 2012 13:58
Remove all ._* and .AppleDouble-files
Remove ._*- and .AppleDouble-files from folders.
Adapted from Torkel's comment on http://hints.macworld.com/article.php?story=20021118060850652
Cred to hiber for suggesting adding -print0/-0 to solve whitespace issue.
See all ._*-files:
find . -name '._*' | more
Remove all ._*-files:
find . -name '._*' -print0 | xargs -0 rm
@magnusdahlstrand
magnusdahlstrand / gist:1770351
Created February 8, 2012 15:10
Ways of dom node creation and appending.
<a class="button icon clock run">run code</a>
var el = document.createElement('a');
el.setAttribute('class', 'button icon clock run');
el.innerHTML = 'run code';
document.body.appendChild(el);