Skip to content

Instantly share code, notes, and snippets.

@Xananax
Xananax / drake.js
Created April 25, 2016 12:12
Drake Equation Calculator
/**
A little bare-bones drake calculator whipped together in ten minutes just to test some values and have fun.
Should work in all modern browsers.
**/
function createDrake(element){
if(!element){element = document.body;}
const container = document.createElement('div');
container.id = 'drake';
@Xananax
Xananax / outlook.html
Last active April 18, 2016 16:52
Pagination examples
<!-- Outlook Pagination -->
<tr>
<td class="nvft">
<table cellspacing="0" cellpadding="0" class="hdvt">
<tbody>
<tr>
<td class="ihdv">
<img src="https://r1.res.office365.com/owa/15.1.477.5/themes/basic/clear.gif" alt="">
</td>
</tr>
@Xananax
Xananax / hide-watched-youtube.js
Created March 17, 2016 15:06
Hide youtube watched thumbnails one-liner
//this leaves whitespace where the thumbnail was.
[].forEach.call(document.querySelectorAll('.watched-badge'),function(el){el.parentNode.parentNode.parentNode.parentNode.style='display:none'})
@Xananax
Xananax / lookup.js
Last active March 10, 2016 14:52
Looks up deep values in a javascript object or array
/**
// Super simple version of the below; if you just want to look up deep values, that's all you need:
function lookup_simple(obj,path,delimiter='.'){
if(obj==null || !path || !path.length){return obj;}
path = Array.isArray(path) ? path : path.split(delimiter);
const rest = path.slice(1);
const current = obj[path[0]];
return (rest.length ? lookup_simple(current,rest) : current)
}
// ...And that's all that's needed for the simple lookup. For a more advanced version, read on
@Xananax
Xananax / keycodes.js
Last active February 27, 2016 05:19
Tired of looking keycodes up everytime
export const by_numbers = {
8:"backspace"
, 9:"tab"
, 13:"enter"
, 16:"shift"
, 17:"ctrl"
, 18:"alt"
, 19:"pause/break"
, 20:"caps lock"
, 27:"escape"
@Xananax
Xananax / Tomato.sh
Created December 2, 2015 20:43
A pomodoro bash script
#!/usr/bin/env bash
# Depends on:
# - notify-send
# - paplay
# base stolen from: http://snipplr.com/view/39697/a-simple-timer-to-apply-the-pomodoro-technique/
#
scriptname=$(basename $0 .sh)
scriptvers='0.1'
@Xananax
Xananax / Testing_Sum.js
Last active November 5, 2015 12:20
Simple performance test of sum-like functions
// accurate time resolution
// stolen from https://github.com/myrne/performance-now
const now = (function(){
if((typeof performance !== "undefined" && performance !== null) && performance.now) {
return function nowPerformance() {
return performance.now();
};
}
if ((typeof process !== "undefined" && process !== null) && process.hrtime) {
let hrtime = process.hrtime;
/**
* Creates or updates a group and attached files and sub-groups
* @param {Object} rethink object with {r,conn}
* @param {Object|String} mainGroup either a group name, or an object {id,name}
* @param {Array} files an array of files paths or an array of {id,path}
* @param {Array} groups an array of groups names or an array of {id,name}
* @param {Function} callback a nodeback with signature (err,results)
*
* This function creates or updates a group on the fly
* Examples:
class TreeNode extends Component{
render(){
return (<table>
{this.props.files.map(function r(child){
return [<tr>{child.name}</tr>]
.concat(child.files.map(r))
})}
</table>)
}
}
function renderNodes({name,directories,files}){
return [<tr>{name}</tr>]
.concat(directories.map(renderNodes))
.concat(files.map(file=><tr>{file}</tr>))
}
class Root extends Component{
render(){
return (<table>
<thead>{this.props.name}</thead>