Skip to content

Instantly share code, notes, and snippets.

@Endle
Endle / gist:9321564
Created March 3, 2014 09:42
Test C array out of range
/* gcc t.c -Wall -Werror -o test && ./test */
#include <stdio.h>
int arr[10];
int main()
{
int n;
scanf("%d", &n);
printf("got %d\n", arr[n]);
return 0;
}
/*****************
* cellBlockA.js *
*****************
*
* Good morning, Dr. Eval.
*
* It wasn't easy, but I've managed to get your computer down
* to you. This system might be unfamiliar, but the underlying
* code is still JavaScript. Just like we predicted.
*
@Endle
Endle / FUD 2014 Beijing
Last active August 29, 2015 14:01
Regular Expression for FUD 2014 Beijing Air Ticket
#!/usr/bin/python3
FILE='asia'
fin = open(FILE, 'r')
strings = fin.readlines()
strings.sort()
strings = [s.strip() for s in strings]
print(strings)
@Endle
Endle / gist:d0b30b1a70756a1f0fa2
Last active August 29, 2015 14:03
用位运算求 f(x, y) -> 2^y > x
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
uint32_t slow(uint32_t b)
{
int n, i;
for(n=-1, i = 1; i <= b; i<<=1, n++);
/* not optimal */
@Endle
Endle / log4
Created July 26, 2014 05:47
Gist by paste.py @ 2014-07-26 13:47:20.388872
0009:trace:mshtml:HTMLDOMNode_Release (0x1f0b18) ref=1
0009:trace:mshtml:HTMLDOMNode_AddRef (0x120f9a18) ref=3
0009:trace:mshtml:HTMLDOMNode_AddRef (0x120f9a18) ref=4
0009:trace:mshtml:HTMLDOMNode_Release (0x120f9a18) ref=3
0009:trace:mshtml:HTMLAnchorElement_handle_event CLICK
0009:trace:mshtml:get_target_window L""
0009:trace:mshtml:HTMLWindow2_AddRef (0x1eed70) ref=3
0009:trace:mshtml:nsURI_AddRef (0x1f1838) ref=5
0009:Call msvcrt.memcmp(10448388,6b28876c,00000021) ret=6b06a143
0009:Ret msvcrt.memcmp() retval=00000000 ret=6b06a143
@Endle
Endle / gist:d5180e69bbcc1cfebc02
Created August 7, 2014 00:34
Talk in IRC about code style
<endle> 你为什么不用 int 呢?
<StarBrilliant> 不是表示运算用的整数不要用int
<StarBrilliant> 只有用来运算的时候才用int
<StarBrilliant> 比如,如果是表示内存中一个东西的大小
<StarBrilliant> 用 size_t
<StarBrilliant> 如果是表示时间的秒数用 clock_t
<StarBrilliant> 表示字符用 wchar_t
<StarBrilliant> 这些都是等价的整数
<StarBrilliant> 但是不是 int
<endle> 哦,明白你的意思了
@Endle
Endle / bfs.py
Last active August 29, 2015 14:05
函数式广搜
def expand_dict(record, new_nodes, dist):
'''record is a dict showes previous distance
now_nodes is a set for the nodes we found
dist is a number, showes the distance for new_nodes
return a dict(record1)
'''
new_dict = {i:dist for i in new_nodes}
#more beautiful assert needed
assert(set(new_dict.keys()).intersection(set(record.keys())) == set())
new_record = {a:b for a,b in list(new_dict.items()) + list(record.items())}
@Endle
Endle / gist:5e5ca62b0f586e1f49e8
Created August 22, 2014 03:54
slidedown error
/home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/open4-1.3.4/lib/open4.rb:37:in `exec': No such file or directory - /usr/local/bin/pygmentize (Errno::ENOENT)
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/open4-1.3.4/lib/open4.rb:37:in `block in popen4'
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/open4-1.3.4/lib/open4.rb:85:in `call'
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/open4-1.3.4/lib/open4.rb:85:in `block in do_popen'
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/open4-1.3.4/lib/open4.rb:62:in `fork'
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/open4-1.3.4/lib/open4.rb:62:in `do_popen'
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/open4-1.3.4/lib/open4.rb:34:in `popen4'
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/makers-mark-0.1.1/vendor/albino.rb:63:in `execute'
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/makers-mark-0.1.1/vendor/albino.rb:70:in `colorize'
from /home/lizhenbo/.rvm/gems/ruby-2.0.0-p353/gems/makers-mark-0.1.1/lib/makers-mark/genera
@Endle
Endle / sample.s
Created August 22, 2014 04:11
Code sample for HrbLUG
.file "sample.c"
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "C:\\sample.txt\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
leal 4(%esp), %ecx
@Endle
Endle / log
Created November 5, 2014 14:52
Gist by paste.py @ 2014-11-05 22:52:47.437824
make_package: Building xulrunner...
mozconfig is unchanged
make -f /home/lizhenbo/src/gecko/client.mk realbuild CREATE_MOZCONFIG_JSON=
Adding client.mk options from /home/lizhenbo/src/wine_gecko-2.35-devel-x86/mozconfig:
CONFIG_GUESS=i686-w64-mingw32
MOZ_OBJDIR=/home/lizhenbo/src/wine_gecko-2.35-devel-x86
OBJDIR=/home/lizhenbo/src/wine_gecko-2.35-devel-x86
FOUND_MOZCONFIG=/home/lizhenbo/src/wine_gecko-2.35-devel-x86/mozconfig
make[1]: Entering directory `/home/lizhenbo/src/gecko'
make -j8 -C /home/lizhenbo/src/wine_gecko-2.35-devel-x86