Skip to content

Instantly share code, notes, and snippets.

View sanmai's full-sized avatar

Alexey Kopytko sanmai

View GitHub Profile
@sanmai
sanmai / dropbox_ext4.c
Created August 15, 2018 07:34 — forked from dimaryaz/dropbox_ext4.c
Dropbox ext4 hack
/*
* dropbox_ext4.c
*
* Compile like this:
* gcc -shared -fPIC -ldl -o libdropbox_ext4.so dropbox_ext4.c
*
* Run Dropbox like this:
* LD_PRELOAD=./libdropbox_ext4.so ~/.dropbox-dist/dropboxd
*/

Hey guys,

I have a really terrible hack, but it appears to work, so...

Dropbox calls statfs64 to get the filesystem type. Now, if only there was a way to change its return value to "ext4"... oh wait, there is!

Here's code of the new function: dropbox_ext4.c

/*
@sanmai
sanmai / stats_rand_gen_normal.php
Created April 27, 2018 06:21
Marsaglia polar method in PHP - stats_rand_gen_normal polyfill
<?php
if (!function_exists('stats_rand_gen_normal')) {
function stats_rand_gen_normal($mu, $sigma) {
do {
$u = (rand() / getrandmax()) * 2 - 1;
$v = (rand() / getrandmax()) * 2 - 1;
$s = $u * $u + $v * $v;
} while ($s >= 1 || $s == 0);
$multiplier = sqrt(-2 * log($s) / $s);
We can't make this file beautiful and searchable because it's too large.
10430,10504,1,1
10472,10534,13,2
10472,10548,3,3
14470,14672,1,4
14470,14698,13,5
15119,15342,3,6
16140,16409,1,7
17453,17513,1,8
17453,17542,1,9
17453,17640,7,10
@sanmai
sanmai / Makefile
Last active October 8, 2022 21:23
Trying to force `--jobs` with GNU Make 4.1
CPUS ?= $(shell nproc)
MAKEFLAGS += --jobs=$(CPUS)
all:
@echo \'$(MAKEFLAGS)\' must have --jobs=$(CPUS)
@sanmai
sanmai / toHankaku.js
Last active January 19, 2018 06:57
Convert full-width digits to half-width (ASCII) digits. 入力値を半角に変換して返却する
function toHankaku(original) {
var result = '';
for (var i = 0; i < original.length; i = i+1) {
var tmp = original.charCodeAt(i);
if ((0xff0f < tmp) && (tmp < 0xff1a)) {
result += String.fromCharCode(tmp - 0xfee0);
} else {
result += String.fromCharCode(tmp);
}
}
@sanmai
sanmai / mail.go
Created September 20, 2017 06:40
Vendoring example
package main
import (
"example.com/example"
)
func main() {
example.Hello()
}
$ add-date-suffix access.log.2.gz
'access.log.2.gz' -> 'access.log-20170821.gz'

Use this script if you happen to forget to add dateext for logrotate:

tee /etc/logrotate.d/defaults <<EOF
dateext
compress
delaycompress

EOF

@sanmai
sanmai / README.md
Last active August 26, 2017 02:21
Generate nginx config for use with Cloudflare
  1. Put update-cf.sh to /etc/nginx/;
  2. chmod +x /etc/nginx/update-cf.sh
  3. Add an entry in crontab to call it weekly: @weekly sleep $RANDOM; /etc/nginx/update-cf.sh
  4. Add /etc/nginx/cloudflare.conf
  5. Use it.

Example:

server {

server_name www.example.com;

@sanmai
sanmai / SC02BOMLL1.txt
Last active June 29, 2017 09:01
Firmware SC-02B / SC02BOMLL1
sha1sum:
50f6b5f560006b894e279f70f7d34297bfb7580f SC02BOMLL1_SC02BDCMLL1_DCM.zip
md5sum:
7e9df962fb0fc7c7f6f54f46e1a26a43 SC02BOMLL1_SC02BDCMLL1_DCM.zip
Samsung GALAXY S, SC-02B
Phone Samsung GALAXY S