Skip to content

Instantly share code, notes, and snippets.

@ls0f
ls0f / progress_bar.py
Created October 10, 2015 02:59
Text Progress Bar in the Console
#coding:utf-8
# http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console
import sys
import time
i = 0
while i<100:
time.sleep(0.3)
i += 1
#sys.stdout.write("\r{}".format(i))
@ls0f
ls0f / fork_buffer.c
Created October 9, 2015 13:03
fork and buffer
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int i;
for(i=0; i<2; i++){
fork();
printf("-");
}
@ls0f
ls0f / buffer_overflow_example.c
Created October 9, 2015 03:46
buffer overflow attack example
#include <stdio.h>
#include <string.h>
/*
gcc compile with -fno-stack-protector to disable "stack Smashing Protection"
*/
int main(void)
{
char buff[6];
@ls0f
ls0f / imagemagick-install-steps
Created September 25, 2015 08:17 — forked from rodleviton/imagemagick-install-steps
Installing Image Magick on Ubuntu 14.04
sudo -i
cd
apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
wget http://www.imagemagick.org/download/ImageMagick-6.8.7-7.tar.gz
tar xzvf ImageMagick-6.8.9-1.tar.gz
cd ImageMagick-6.8.9-1/
./configure --prefix=/opt/imagemagick-6.8 && make
checkinstall
#coding:utf-8
# https://gist.github.com/opensourcegeek/9822127
from gevent import monkey
monkey.patch_all()
import logging
import gevent
from gevent.queue import Queue, Empty
import pymysql as db
#coding:utf-8
def insert_sort(array):
if len(array) <= 1:
return
for i in range(1, len(array)):
j = i
#coding:utf-8
def quick_sort(sort_list):
if len(sort_list) <= 1:
return sort_list
m = sort_list[0]
return quick_sort(filter(lambda x: x<=m, sort_list[1:])) + [m] + \
quick_sort(filter(lambda x: x>m, sort_list[1:]))
@ls0f
ls0f / bubble_sort.py
Last active September 14, 2015 02:05
#coding:utf-8
def bubble_sort(sort_list):
length = len(sort_list)
while length > 1:
for i in range(1, length):
if sort_list[i] < sort_list[i-1]:
sort_list[i], sort_list[i-1] = sort_list[i-1],sort_list[i]
#coding:utf-8
from gevent import monkey
monkey.patch_all()
import os
import tornado
import logging
import tornado.wsgi
import tornado.httpserver
@ls0f
ls0f / showBigOrLittleEnd.c
Created August 31, 2015 03:54
查看机器是大端还是小段
#include<stdio.h>
typedef unsigned char * byte_pointer;
int showBigOrLittleEnd()
{
int i = 0x01;
byte_pointer bp = (byte_pointer) &i;
if (bp[0] == 0x01)
return 1;