Skip to content

Instantly share code, notes, and snippets.

@cou929
cou929 / detect-private-browsing.js
Last active May 1, 2024 21:07
Detect private browsing mode (InPrivate Browsing or Incognito).
function retry(isDone, next) {
var current_trial = 0, max_retry = 50, interval = 10, is_timeout = false;
var id = window.setInterval(
function() {
if (isDone()) {
window.clearInterval(id);
next(is_timeout);
}
if (current_trial++ > max_retry) {
window.clearInterval(id);
@cou929
cou929 / load-external-script-snippet.js
Created September 20, 2010 14:41
Simple code snippet for loading external script from a bookmarklet.
/**
* load-external-script-snippet.js
* Kosei Moriyama <cou929@gmail.com>
*
* Simple code snippet for loading external script from a bookmarklet.
* Replace example url of script to your target script url before use.
*/
(function() {
var u = 'http://example.com/bookmarklet.js';
@cou929
cou929 / gist:4249052
Created December 10, 2012 07:31
perl ハッシュのデフォルト値. 存在しない key にアクセスすると作ってくれる
$ perl -MData::Dumper -le 'my $a = +{}; $a->{foo}->{bar}++; $a->{foo}->{bar}++; $a->{foo}->{baz}++; $a->{blah}->{blah}++; print Dumper $a;'
$VAR1 = {
'blah' => {
'blah' => 1
},
'foo' => {
'bar' => 2,
'baz' => 1
}
};
@cou929
cou929 / bar.yaml
Created February 23, 2023 15:21
unexpected behavior of swagger-cli
post:
responses:
201:
description: test
content:
application/json:
schema:
$ref: ref2.yaml
description: the order of this description directive changes between versions
@cou929
cou929 / load.html
Last active December 22, 2022 09:01
画像の読み込みにタイムアウトを付けたいけど XHR じゃないと厳しそう
<html>
<body>
<script type="text/javascript">
var blackhole_image_url = 'http://blackhole.webpagetest.org/',
wait_interval = 3000;
// 3秒じゃタイムアウトされない
loadWithImageElement(blackhole_image_url + 'element.png');
// 3秒じゃタイムアウトされない
/* https://github.com/cou929/sql-fingerprint-js */
CREATE TEMP FUNCTION fingerprint(sql STRING, matchMD5Checksum BOOL, matchEmbeddedNumbers BOOL)
RETURNS STRING
LANGUAGE js AS r"""
function fingerprint(sql, matchMD5Checksum, matchEmbeddedNumbers) {
let query = sql;
// special cases
if (/^SELECT \/\*!40001 SQL_NO_CACHE \*\/ \* FROM `/.test(query)) {
@cou929
cou929 / script-loader.js
Created September 20, 2010 15:13
Load external scripts one by one.
/**
* script-loader.js
* Load external scripts one by one.
* (Load certain script after previous script is loaded.)
*/
(function script_loader(scripts) {
if (scripts.length <= 0) return;
var uri = scripts.shift();
var script = document.createElement('script');
script.type = 'text/javascript';
var tddjs = tddjs || {};
(function(global) {
global.ajax = {};
var ajax = global.ajax;
/**
* Define ajax.create()
*/
var i, l;
@cou929
cou929 / centos_mail_bootstrap.sh
Created September 3, 2011 16:50
Postfix and dovecot setup script for CentOS (instead of sendmail)
#! /bin/sh
# postfix and dovecot setup script (instead of sendmail)
# based on http://centossrv.com/postfix.shtml
echo "### install postfix via yum if not exist"
if [ ! -e /etc/postfix/main.cf ]
then
sudo yum -y install postfix
else
@cou929
cou929 / sendgmail.py
Created January 9, 2012 10:49
Send mail via GMail smtp.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import smtplib
import sys
import os
from email.MIMEText import MIMEText
from email.Utils import formatdate
from email.Header import Header
from optparse import OptionParser