Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
sp3c73r2038 / mongo.demo.php
Created April 9, 2012 09:47
mongodb connection demo for php
<?php
error_reporting(E_ALL);
$m = new Mongo("mongodb://127.0.0.1:27017");
$db = $m->selectDB("test");
$coll = $db->selectCollection("foo");
@sp3c73r2038
sp3c73r2038 / gd.cropimage.php
Created June 4, 2012 03:47
crop_image in gd equivalent to cropImage in imagick
<?php
function cropImage ($image, $width, $height, $x, $y) {
list($w, $h) = getimagesize($image);
$nw = (($width + $x) >= $w) ? $w - $x : $width;
$nh = (($height + $y) >= $h) ? $h - $y : $height;
// var_dump($nw);
// var_dump($nh);
@sp3c73r2038
sp3c73r2038 / poll.js
Created July 3, 2012 15:07
loop for calling a function
var a = function (i) {
console.log(i)
setTimeout(a(++i), 1000); // wrong, the 1st parameters should be a function but passed a function calling by mistaken.
}
@sp3c73r2038
sp3c73r2038 / poll.js
Created July 3, 2012 15:13
loop for calling a function
var a = function (i) {
console.log(i)
setTimeout(function () {
a(++i);
}, 1000); // now correct
}
@sp3c73r2038
sp3c73r2038 / truble.shooting.of.scribe.markdown
Created July 11, 2012 01:31
truble shooting of scribe

truble shooting of scribe

依赖

  • 整体
    • 这些依赖是必须的,以RHEL/CentOS举例
yum install automake libtool flex bison pkgconfig gcc-c++ libevent-devel
@sp3c73r2038
sp3c73r2038 / socket.crossdomain.py
Created July 19, 2012 14:42
simple socket server for serving flash crossdomain policy
import errno
import functools
import socket
from tornado import ioloop, iostream
def connection_ready(sock, fd, events):
while True:
try:
connection, address = sock.accept()
except socket.error, e:
@sp3c73r2038
sp3c73r2038 / lpfc_scsi.c.patch
Created August 31, 2012 13:22
patching drivers/scsi/lpfc/lpfc_scsi.c for kernel 3.4.9 gentoo workaround with -Werror while compile WITH CONFIG_LPFC_SCSI
--- /usr/src/linux/drivers/scsi/lpfc/lpfc_scsi.c 2012-05-21 06:29:13.000000000 +0800
+++ lpfc_scsi.c 2012-08-31 21:12:33.619966584 +0800
@@ -1897,7 +1897,6 @@
dma_addr_t physaddr;
int i = 0, num_bde = 0, status;
int datadir = sc->sc_data_direction;
- uint32_t rc;
uint32_t checking = 1;
uint32_t reftag;
unsigned blksize;
@sp3c73r2038
sp3c73r2038 / screenshot
Last active April 14, 2023 19:52
a script using ImageMagick to take screenshots
#!/bin/bash
DIR="${HOME}/images/screenshots"
DATE="$(date +%Y%m%d-%H%M%S)"
NAME="${DIR}/screenshot-${DATE}.png"
LOG="${DIR}/screenshots.log"
# Check if the dir to store the screenshots exists, else create it:
if [ ! -d "${DIR}" ]; then mkdir -p "${DIR}"; fi
@sp3c73r2038
sp3c73r2038 / create.exif.php
Created October 30, 2012 04:51
php using PEL manipulate the exif data
<?php
error_reporting(E_ALL);
$root_path = dirname(__FILE__);
$lib_path = $root_path . "/lib/";
include_once($lib_path . 'PelJpeg.php');
include_once($lib_path . 'PelTag.php');
include_once($lib_path . 'PelIfd.php');
@sp3c73r2038
sp3c73r2038 / post.py
Last active April 7, 2023 15:27
urlopen with proxy support
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import urllib2
data = urllib2.urlencode({'foo': 'bar'})
r = urllib2.Request('https://www.google.com', # url
data, # post data