Skip to content

Instantly share code, notes, and snippets.

@kapusta
kapusta / compare.js
Created March 12, 2018 13:47
compare two objects without recursion
(function() {
var obj1 = {
foo: 'qwerty',
bar: 'asdfgh',
};
var obj2 = {
foo: '123456',
bar: '098765',
@kapusta
kapusta / pizero-bak.md
Last active December 13, 2020 22:59
Backup a #pizero Disk

Backup a #pizero to Disk

This guide assumes you're using a Mac, an SD card and the disk mounts at /dev/disk2

List disks

Find the disk...

diskutil list

Look for the disk that matches the size of the SD card you put into the card slot. Again, we're going to assume it landed at /dev/disk2

@kapusta
kapusta / nojq.js
Created September 1, 2016 21:12
the answer to a question i was asked years ago, but sans jQuery
var tbl = document.querySelectorAll('table.someId');
var rows = Array.from(tbl.querySelectorAll('tr')).filter(function(row, idx) { return (idx % 2);});
tbl.removeChild(tbl.querySelector('tbody'));
rows.forEach(function (row) {
tbl.appendChild(row);
});
@kapusta
kapusta / foo-multiselect-required.js
Last active November 2, 2015 18:07
fooMultiselectRequired lets you set a ui-select as required
/**
@memberof yourApp
@ngdoc directive
@name fooMultiselectRequired
@description ui-select does not handle required correctly when it's a multi-select, so here's a directive to fix that. See [this github issue](https://github.com/angular-ui/ui-select/issues/258) for more info. This directive is based on LeleDev's example, but adds an extra check.
@returns {boolean}
@example <ui-select multiple foo-multiselect-required name="whatever" ng-model="ctrl.payload.wahtever" theme="select2">
*/
(function(angular){
'use strict';
@kapusta
kapusta / partial.js
Created May 14, 2015 17:18
a javascript `partial` function
// http://stackoverflow.com/questions/321113/how-can-i-pre-set-arguments-in-javascript-function-call-partial-function-appli
// usage example: object.someEvent = partial(myFuncRef, arg1, arg2);
var partial = function(func) {
var args = Array.prototype.slice.call(arguments, 1);
return function() {
var allArguments = args.concat(Array.prototype.slice.call(arguments));
return func.apply(this, allArguments);
};
};
@kapusta
kapusta / angular-local-storage.broadcasts.js
Created May 8, 2015 20:15
angular-local-storage broadcasts events when it does stuff, listen for those events thusly...
// https://github.com/grevory/angular-local-storage#setnotify
$scope.$on("LocalStorageModule.notification.setitem", function (key, newVal, type) {
$log.log("LocalStorageModule.notification.setitem", key, newVal, type);
});
$scope.$on("LocalStorageModule.notification.removeitem", function (key, type) {
$log.log("LocalStorageModule.notification.removeitem", key, type);
});
@kapusta
kapusta / scdl.js
Created February 12, 2015 16:25
a crappy soundcloud download initiator, go to a SC page with downloads, open console, paste this in, hit return
(function(doc){
var buttonNodeList = doc.querySelectorAll('.sc-button-download');
var buttonArray = Array.prototype.slice.call(buttonNodeList);
var startAt = parseInt(prompt("Provide a number to start at..."), 10) || 0;
for (var i = startAt; i < buttonArray.length; i++) {
if (confirm("try to download track #"+ i + "?" + " " + buttonArray[i].download)) {
buttonArray[i].click();
}
@kapusta
kapusta / nodeList.js
Created January 20, 2015 20:19
iterate over the results of a node list from querySelectorAll()
// http://jsperf.com/nodelist-to-array/27
// https://developer.mozilla.org/en-US/docs/Web/API/Document.querySelectorAll
var nodeList = function(nodes) {
return Array.prototype.slice.call(nodes);
};
nodeList(yourNodes).map(function(val, idx, arr) {
// your logic here
});
@kapusta
kapusta / onDelayedKeyup.coffee
Last active August 29, 2015 14:06 — forked from davidstump/gist:d0b9f87f6a132c2991fb
a keyup debouncing directive, needs to be decaffeinated
@App.directive "onDelayedKeyup", ['$timeout', ($timeout) ->
(scope, element, attrs) ->
timer = false
element.bind "keyup", ->
$timeout.cancel(timer) if timer
timer = $timeout ->
scope.$apply attrs.onKeyup
, 500
]
@kapusta
kapusta / index.html
Created April 2, 2014 20:19
basic d3 for jimdotcom
<!DOCTYPE html>
<html lang="en" ng-app="butcher">
<head>
<title>jimdotcom</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css">
<link rel="stylesheet" href="/css/nv.d3.min.css">