Skip to content

Instantly share code, notes, and snippets.

View begeekmyfriend's full-sized avatar

Leo Ma begeekmyfriend

View GitHub Profile
@begeekmyfriend
begeekmyfriend / binary_search.c
Created March 2, 2014 03:43
Only less than 10% programmers all over the world can get it right.
int binary_search_first_position(int *A, int n, int target)
{
int low = -1, high = n;
assert(A != NULL && n >= 0);
while (low + 1 < high)
{
int mid = (low + high) >> 1;
if (A[mid] < target)
low = mid;
else
@begeekmyfriend
begeekmyfriend / dep_sort.lua
Last active May 1, 2017 14:48
Module Dependence Regitster Sequence
--[[
Date: 2014-8-1
Licence: MIT
Author: <begeekmyfriend@gmail.com>
<xfguo@credosemi.com>
]]
--[[
module_relation table
key -- module name
@begeekmyfriend
begeekmyfriend / msg_tips.c
Created February 2, 2015 14:48
Message enum and string pair
#define MSG_CODEC(ACTION) \
ACTION( UNKNOWN, ""/* unknown */ ) \
ACTION( REQ_GET, "get " ) \
ACTION( REQ_GETS, "gets " ) \
ACTION( REQ_DELETE, "delete " ) \
ACTION( REQ_CAS, "cas " ) \
ACTION( REQ_SET, "set " ) \
ACTION( REQ_ADD, "add " ) \
ACTION( REQ_REPLACE, "replace " ) \
ACTION( REQ_APPEND, "append " ) \
@begeekmyfriend
begeekmyfriend / mib_tree.c
Last active April 13, 2021 23:46
MIB tree structure demo
/*
* This file is part of SmartSNMP
* Copyright (C) 2014, Credo Semiconductor Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
@begeekmyfriend
begeekmyfriend / build_ffmpeg_with_libx264_libaacplus.sh
Created May 9, 2016 02:15
cross building ffmpeg with libx264 and libaacplus for Android
HOST=linux-x86_64
NDK=/opt/android-ndk-r8e
PLATFORM=$NDK/platforms/android-14/arch-arm
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/$HOST
CPU=armv7-a
PREFIX=$(pwd)/../build_android/$CPU
@begeekmyfriend
begeekmyfriend / bag.c
Last active September 30, 2023 12:14
0-1 bag problem
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* https://zhuanlan.zhihu.com/p/345364527 */
static inline int max(int a, int b)
{
return a > b ? a : b;
}
#include <stdio.h>
#include <stdlib.h>
static void show(int *nums, int lo, int hi)
{
int i;
for (i = lo; i <= hi; i++) {
printf("%d ", nums[i]);
}
#include <stdio.h>
#include <stdlib.h>
static inline void swap(int *a, int *b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
void sort(int *nums, int size)
{
int i, j;
for (i = 1; i < size; i++) {
int tmp = nums[i];
for (j = i; j > 0 && tmp < nums[j - 1]; j--) {
nums[j] = nums[j - 1];
}
nums[j] = tmp;
}
void sort(int *nums, int size)
{
int i, flag = size;
while (flag > 0) {
int len = flag;
flag = 0;
for (i = 1; i < len; i++) {
if (nums[i - 1] > nums[i]) {
int tmp = nums[i - 1];
nums[i - 1] = nums[i];