Skip to content

Instantly share code, notes, and snippets.

#include "ffi.h"
STATIC mp_obj_t example_printf(size_t n_args, const mp_obj_t *args) {
ffi_cif cif;
ffi_type **types = alloca(n_args * sizeof(ffi_type *));
ffi_raw *values = alloca(n_args * sizeof(ffi_raw));
void **arg_values = alloca(n_args * sizeof(void *));
ffi_arg result;
@kikuchan
kikuchan / excel-conv.php
Created April 8, 2016 18:05
Excelカラム名っぽいやつの相互変換
<?php
function fwd_conv($v) {
// 必要な桁数を求める のと同時に 該当桁数内での順番に変換する
for ($c = 1; $v >= pow(26, $c); $c++) $v -= pow(26, $c);
// 目標桁数のアルファベット26進表現に変換
$r = base_convert($v, 10, 26);
$r = str_pad($r, $c, '0', STR_PAD_LEFT);
$t = '0123456789abcdefghijklmnopqrstuvwxyz';
return strtr($r, $t, substr($t, 10));
@kikuchan
kikuchan / sysv-pgsql-jail.patch
Created June 3, 2015 18:37
A patch to run multiple (version of, if you want, ) PostgreSQL (with same uid) simultaneously on FreeBSD jail. (Change sysv_sem/shm policy to per jail basis)
diff --git a/kern/sysv_sem.c b/kern/sysv_sem.c
index 53b63e0..25fe343 100644
--- a/kern/sysv_sem.c
+++ b/kern/sysv_sem.c
@@ -506,6 +506,17 @@ semvalid(int semid, struct semid_kernel *semakptr)
semakptr->u.sem_perm.seq != IPCID_TO_SEQ(semid) ? EINVAL : 0);
}
+static int
+jail_check_semperm(td, semakptr)
@kikuchan
kikuchan / obey-maxBounds-during-drag.js
Created November 19, 2013 19:16
Obey maxBounds during dragging a map on leaflet 0.7
/*
Obey maxBounds during dragging a map on leaflet 0.7
New option "maxBoundsResistance" (0.0 - 1.0) controls its reaction;
0.0: No effect
0.8: Modern reaction (default)
1.0: Strictly forbid
*/
L.Map.addInitHook(function() {
@kikuchan
kikuchan / restrict-to-maxBounds.js
Created November 13, 2013 18:22
Try to restrict user to drag to outside of maxBounds on Leaflet 0.6.4, nicely. (It access private objects, so it might not work properly on another version)
L.Map.addInitHook(function() {
var map = this;
this.dragging._draggable.on("predrag", function() {
var bounds_sw = map.latLngToLayerPoint(map.options.maxBounds.getSouthWest()).add(this._newPos);
var bounds_ne = map.latLngToLayerPoint(map.options.maxBounds.getNorthEast()).add(this._newPos);
var size = map.getSize();
if (bounds_ne.y > 0) {
this._newPos.y -= bounds_ne.y / 1.2;
}
@kikuchan
kikuchan / gist:3692138
Created September 10, 2012 16:59
gauche array-mul simple benchmark
(use gauche.array)
(define Tarray (array (shape 0 3 0 3) 1 0 0 0 1 0 0 0 1))
(define sxsy (array (shape 0 3 0 1) 1 1 1))
(dotimes (y 100)
(display ".")(flush)
(dotimes (x 100)
(array-mul Tarray sxsy)))
(newline)
@kikuchan
kikuchan / mgs-unpack.c
Created July 29, 2012 05:02
unpacker for multi game scripter
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
uint8_t read_uint8(FILE *fp)
{
int ch = fgetc(fp);
uint8_t ret = 0;
if (ch == EOF) return 0; /* XXX */
@kikuchan
kikuchan / patch-xpdf-Japanize.diff
Created June 19, 2012 07:13
xpdf outline japanizer - xpdf しおり日本語化
--- xpdf/XPDFApp.cc 2011-08-16 06:08:53.000000000 +0900
+++ xpdf/XPDFApp.cc 2012-06-19 15:48:43.000000000 +0900
@@ -36,8 +36,8 @@
static String fallbackResources[] = {
"*.zoomComboBox*fontList: -*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
- "*XmTextField.fontList: -*-courier-medium-r-normal--12-*-*-*-*-*-iso8859-1",
- "*.fontList: -*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
+ "*XmTextField.fontList: -misc-fixed-medium-r-*-*-14-*-*-*-*-*-iso10646-1:80",
+ "*.fontList: -misc-fixed-medium-r-*-*-14-*-*-*-*-*-iso10646-1:80",
(use srfi-1) ; iota
(use srfi-43) ; vector-for-each
(define fail #f)
;;; write following at the end of file
;;; to initialize the value of the fail.
(call/cc
(lambda (cc)
(set! fail