Skip to content

Instantly share code, notes, and snippets.

View nethoncho's full-sized avatar
🍊

Net Honcho nethoncho

🍊
View GitHub Profile
@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
@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 / 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 / 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 / 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) {
"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() {
/*
* 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/
*
*/
/*
* config/bootstrap.js
* Example of how to redirect all http request to https
* See http://jsbot.io/node/http-and-https-handle-with-sailsjs
*
*/
module.exports.bootstrap = function(cb) {
var express = require("express")
var app = express();
@nethoncho
nethoncho / ! pg-migrate-demo
Last active October 25, 2017 03:27
Postgresql database migration management
# https://github.com/salsita/node-pg-migrate
npm install node-pg-migrate
@nethoncho
nethoncho / ! Ubuntu nginx meteor proxy
Last active October 27, 2017 04:18
Meteor nginx application proxy on Ubuntu 16.04.3 LTS
# Use sudo before each command if not logged in as root
#
# Install nginx https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04
apt-get update
apt-get install nginx
# Check that HTTP port 80 and HTTPS port 443 are open
ufw app status
# Make sure nginx starts on boot