Skip to content

Instantly share code, notes, and snippets.

View BrianLian's full-sized avatar

BrianLian BrianLian

View GitHub Profile
@BrianLian
BrianLian / gist:10092284
Created April 8, 2014 04:52
mcast_iface_receive.coffee
os = require 'os'
dgram = require 'dgram'
test_receive = (ifaddr)->
MDNS_PORT = 5353 # OSX refuses app to use port 5353
MDNS_ADDRESS = "224.0.0.251"
s = dgram.createSocket('udp4')
ver = Number(process.versions.node.split('.')[1])
if ver==10
@BrianLian
BrianLian / ipaddr_input.c
Last active June 16, 2016 14:27
ipaddr_input
#include<stdio.h>
#include<stdlib.h>
int main() {
uint32_t ipaddr;
ipaddr = 3764655192ul; // 224.100.20.88
printf("%d.%d.%d.%d\n",
(ipaddr>>24)&0xFF,
(ipaddr>>16)&0xFF,
@BrianLian
BrianLian / function_pointer.c
Created June 16, 2016 14:28
function_pointer
#include <stdio.h>
typedef int (*g)(int, int);
//function宣告
int doAdd(int, int);
int doMinus(int, int);
g table[] = {
doAdd,
@BrianLian
BrianLian / argc_argv.c
Created June 16, 2016 14:29
argc_argv
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
void CLI_TMP(char *msg, ...)
{
va_list argptr;
int a,b;
char *c;
@BrianLian
BrianLian / struct_alignment.c
Created June 16, 2016 14:30
struct_alignment
#include <stdio.h>
#include <stdlib.h>
struct test {
char a;
int b;
char c;
long d;
};
@BrianLian
BrianLian / angular_uibModal_resolve and_resuts_example.coffee
Created August 5, 2016 07:27
angular uibModal resolve and resuts example
$scope.edit=(who,index)->
modalInstance = $uibModal.open
templateUrl: 'editModal'
resolve :
scheduleType : -> $scope.scheduleType
devices : ->$scope.devices
controller: [ '$scope', '$uibModalInstance', 'scheduleType', 'devices', ($scope, $uibModalInstance, scheduleType, devices)->
$scope.scheduleType = scheduleType
$scope.devices = devices
$scope.ui = {}
@BrianLian
BrianLian / get_interface_ipaddr.go
Created March 14, 2017 09:17
Get Interface's IP Address
package main
import "net"
import "fmt"
func main() {
ifaces, err := net.Interfaces()
_ = err // handle err
for _, v := range ifaces {
addrs, err := v.Addrs()
@BrianLian
BrianLian / convert_ipv4_between_uint_and_string.c
Created April 13, 2017 10:37
convert ipV4 between uint and string
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int ipv4_to_string(uint32_t ipaddr, char *str) {
memset (str, 0, sizeof(char) * 50);
sprintf(str, "%d.%d.%d.%d", (ipaddr >> 24)&0xFF,
(ipaddr >> 16)&0xFF, (ipaddr >> 8)&0xFF, (ipaddr)&0xFF);