Skip to content

Instantly share code, notes, and snippets.

View x5lcfd's full-sized avatar
:octocat:
coding.

x5lcfd x5lcfd

:octocat:
coding.
View GitHub Profile
@x5lcfd
x5lcfd / reverse.c
Created June 3, 2013 14:51
reverse a input string.
void reverse() {
int c;
c = getchar();
if (c != '\n')
reverse();
putchar(c);
}
@x5lcfd
x5lcfd / swap.c
Last active December 20, 2015 01:19
This is a swap macro in c, and can swap arbitrary types.
#include <string.h>
#define swap(x, y) do \
{ unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x):-1];\
memcpy(swap_temp, &y, sizeof(x)); \
memcpy(&y, &x, sizeof(x)); \
memcpy(&x, swap_temp, sizeof(x)); \
} while(0)
// this snippet from stackoverflow
// http://stackoverflow.com/questions/3982348/implement-generic-swap-macro-in-c
@x5lcfd
x5lcfd / aymmarr.c
Last active August 29, 2015 14:12
A nice trick with symmetric array
static char digits[19] = { '9', '8', '7', '6', '5',
'4', '3', '2', '1','0', '1', '2', '3', '4', '5',
'6', '7', '8', '9' };
static const char* zero = digits + 9;
printf( "%c\n", zero[-1] );
@x5lcfd
x5lcfd / c2i.c
Last active August 29, 2015 14:17
/*
字符'0'在机器中存放的是其ASCII码,‘0‘对应的是0x30,以二进制表示“00110000”。
从’0’-‘9’对应的ASCII码为0x30-0x39,并且在数值上,分别对应后四位二进制所表示
的数值,如‘1’->0x31->00110001,后四位为0001。所以可以使用移位来得到后四位,
然后根据十进制的性质,每次×10逐步得到结果。
*/
long c2i (char str[]) {
long b = 0;
while(*str != '\0') {
b = b*10 + ((unsigned char)((char)(*(str++)<<4))>>4);
@x5lcfd
x5lcfd / w3g_format.txt
Last active October 17, 2016 02:04 — forked from stattrak-dragonlore/w3g_format.txt
War3 Replay File Format
*******************************************************************************
* WarCraft III Replay file format description *
* *
* document version: 1.18 *
* document date : 2007-06-26 *
* document authors: blue, nagger *
* *
* For more informtion about w3g file format, please visit: *
* http://w3g.deepnode.de *
* *
#!/usr/bin/perl
$f = $ARGV[0];
$pagestart = 0;
$charstart = 0;
$kernstart = 0;
$s = "<?xml version=\"1.0\"?>\n<font>\n";
open(F, $f);
// From http://forum.unity3d.com/threads/solved-dynamic-blurred-background-on-ui.345083/
Shader "Custom/SimpleGrabPassBlur" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_BumpAmt ("Distortion", Range (0,128)) = 10
_MainTex ("Tint Color (RGB)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Size ("Size", Range(0, 20)) = 1
}
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
#!/usr/bin/perl
$f = $ARGV[0];
$pagestart = 0;
$charstart = 0;
$kernstart = 0;
$s = "<?xml version=\"1.0\"?>\n<font>\n";
open(F, $f);
@x5lcfd
x5lcfd / CountDown.cs
Last active June 1, 2016 13:58
update usage
IEnumerator Waiting(TimeSpan elapsedTimeSpan,
System.Action<TimeSpan> timeCallback,
System.Action callback)
{
for (;elapsedTimeSpan.CompareTo(TimeSpan.Zero) >= 0;)
{
if (timeCallback != null) { timeCallback(elapsedTimeSpan); }
elapsedTimeSpan -= new TimeSpan(0, 0, 1);
yield return new WaitForSeconds(1.0f);