Skip to content

Instantly share code, notes, and snippets.

View nethoncho's full-sized avatar
🍊

Net Honcho nethoncho

🍊
View GitHub Profile
/*
* letsencrypt certificates with node js express / http
* key is obvious, privkey.pem
* ca and cert were not obvious to me.
* ca uses chain.pem
* cert uses fullchain.pem
*
* You can test your project with https://www.ssllabs.com/ssltest/
*
*/
"use strict";
exports.queryAll = function(conn, sql, args, cb) {
var allRows = [];
conn.execute(sql, args, {
resultSet: true
}, function(err, result) {
if (err) return cb(err);
function fetch() {
@nethoncho
nethoncho / visibilitychange.js
Created February 15, 2015 12:57
Handling document.visibilitychange in AngularJS
// See http://megatuto.com/formation-JAVASCRIPT.php?JAVASCRIPT-Examples=handling+document.visibilitychange+in+AngularJS+Categorie+javascript+angularjs&article=1773
angular.module('myApp', [])
.run(['$rootScope', '$document', function($rootScope, $document) {
$document[0].addEventListener("visibilitychange", function() {
$rootScope.$broadcast('$visibilitychange', $document[0].hidden);
});
}])
.controller('UserNavCtrl', ['$scope', '$log',
function($scope,$log) {
$scope.$on('$visibilitychange', function(event, data) {
@nethoncho
nethoncho / debounceExample.js
Last active August 29, 2015 14:15
angular debounce example
// Example from https://scotch.io/tutorials/making-skinny-angularjs-controllers
// Search the goat database
$scope.searchGoats = _.debounce(function(query) {
$http.get('/goats/search/' + query)
.then(function(response) {
$scope.goats = response.data;
});
}, 300);
@nethoncho
nethoncho / inet_aton.php
Last active May 10, 2022 08:00
JavaScript inet_aton
// http://stackoverflow.com/a/21559595
// ip example: 192.168.2.1
function inet_aton(ip){
// split into octets
var a = ip.split('.');
var buffer = new ArrayBuffer(4);
var dv = new DataView(buffer);
for(var i = 0; i < 4; i++){
dv.setUint8(i, a[i]);
}
@nethoncho
nethoncho / button_driver.h
Created July 21, 2014 14:12 — forked from mweyland/button_driver.h
xmos button driver
#ifndef BUTTON_DRIVER_H_
#define BUTTON_DRIVER_H_
interface button_interface
{
void pressed(void);
};
void button_driver(in port button_port, client interface button_interface button_interface);
@nethoncho
nethoncho / find_network_test.php
Last active November 8, 2019 00:32
PHP: Find Network and Broadcast for given IP and Subnet
#!/usr/bin/php
<?php
$input = new stdClass();
$input->ip = '70.71.72.73';
$input->netmask = '255.255.255.0';
$input->ip_int = ip2long($input->ip);
$input->netmask_int = ip2long($input->netmask);
// Network is a logical AND between the address and netmask