Skip to content

Instantly share code, notes, and snippets.

@dannyid
dannyid / gitfiti-helper-bookmarklet.js
Last active August 29, 2015 14:24
Draw drawings on your github contribution timeline and export them to a template. Works alongside https://github.com/gelstudios/gitfiti
/**
* To install:
* 1. Right click on bookmark bar
* 2. Click 'Add Page'
* 3. Give it a title
* 4. Paste the below into the 'URL' field
* 5. Save
*
* To use:
* 1. Navigate to your user page on GitHub, like https://github.com/dannyid
@dannyid
dannyid / uuid.js
Created July 23, 2015 20:42
Generate a UUID
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
@dannyid
dannyid / googleSearchUrl.js
Last active May 30, 2017 03:40
What do these parameters even mean?
const language = `en`,
numResults = `100`, // 1 to 100
personalization = `0`, // Non-personalized
encoding = `UTF-8`,
verbatim = `li:1`, // No auto-correct and no location
ssl = `ssl`;
const googleSearchUrl = `https://www.google.com/search` +
`?q=${keyword}` +
`&hl=${language}` +
@dannyid
dannyid / copyToClipboard.js
Created September 25, 2015 06:34
For use in a Chrome extension. Don't forget to enable the "clipboardWrite" permission.
function copyToClipboard(text) {
const input = document.createElement('input');
input.style.position = 'fixed';
input.style.opacity = 0;
input.value = text;
document.body.appendChild(input);
input.select();
document.execCommand('Copy');
document.body.removeChild(input);
};
@dannyid
dannyid / calculateColorContrast.js
Last active October 8, 2015 21:18
Find the best contrast color to overlay onto given color.
export function getContrastYIQ(color, colorType){
let r, g, b;
const start = color.indexOf('#') === 0 ? 1 : 0;
if (colorType === 'hex') {
r = parseInt(color.substr(start, 2), 16);
g = parseInt(color.substr(start + 2, 2), 16);
b = parseInt(color.substr(start + 4, 2), 16);
} else if (colorType == 'rgb') {
[r, g, b] = color.slice(4, -1).split(',').map(str => +str);
@dannyid
dannyid / Spread.md
Last active February 10, 2017 07:58
Updating Deep Immutable Object with ES6 Spread. From: https://github.com/sebmarkbage/ecmascript-rest-spread/blob/master/Spread.md

Updating Deep Immutable Object

let newVersion = {
  language: 'Default Language', // Set default for unspecified properties
  ...previousVersion,
  name: 'New Name', // Override the name property
  address: {
    ...previousVersion.address,
    zipCode: '99999' // Update nested zip code
 },
@dannyid
dannyid / team-treehouse-download-video-bookmarklet.md
Last active September 14, 2016 09:19
Download the video you're currently watching on TeamTreehouse.com

###What does it do?

Downloads the HD version of the Team Treehouse video you're currently watching.

###How to use:

  1. Right click on your bookmarks bar and choose Add Page...
  2. Give it a name and paste the below code in the URL section
@dannyid
dannyid / javascript-puzzle.js
Last active November 28, 2016 04:13
Javascript puzzle.
// Given:
var i = '1';
// 1. What is the value of the below expression?
// 2. What is the value of `i` afterwards?
++i + +i+++i+i +++i+i+i+++i++ +i+++i;
@dannyid
dannyid / disable-notification-center.sh
Created November 21, 2016 05:41
How to disable Notification Center on macOS
# Disabling Notification Center
# “process not found” error shouldn't matter
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
killall NotificationCenter
# Enabling Notification Center
launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
@dannyid
dannyid / docker-regenerate-certs.sh
Created November 21, 2016 06:10
Fix Docker reboot IP/cert mismatch problem
docker-machine regenerate-certs