Skip to content

Instantly share code, notes, and snippets.

@kijtra
kijtra / kana2alpha.php
Created May 21, 2011 04:43
[PHP] ひらがな、カタカナからアルファベットに変換する処理をクラス化。こちらのJavaScriptを参考にした。 → http://tenderfeel.xsrv.jp/mootools/382/
<?php
class kana2roma {
var $charset='utf-8';
var $mode_Krows = 'k'; //か・く・こ(k or c)
var $mode_XArows = 'l'; //小文字ぁ行と「っ」( L or X)
var $mode_TYrows = 'ch'; //ち行+小文字や行(ty or ch or cy)
var $mode_SYrows = 'sh'; //し行+小文字や行(sy or sh)
var $mode_JYrows = 'j'; //じ行+小文字や行(j or zy or jy)
var $mode_Sstr = 'sh'; //し(s or sh or c)
@maskit
maskit / gist:2252422
Created March 30, 2012 15:57
WebSocket traffic sniffer
(function () {
WebSocket.prototype._send = WebSocket.prototype.send;
WebSocket.prototype.send = function (data) {
this._send(data);
this.addEventListener('message', function (msg) {
console.log('>> ' + msg.data);
}, false);
this.send = function (data) {
this._send(data);
console.log("<< " + data);
@jbroadway
jbroadway / Slimdown.md
Last active July 7, 2024 08:56
Slimdown - A simple regex-based Markdown parser.
@ziadoz
ziadoz / index.php
Last active June 2, 2023 23:08
Simple PHP / jQuery CSRF Protection
<?php
// See: http://blog.ircmaxell.com/2013/02/preventing-csrf-attacks.html
// Start a session (which should use cookies over HTTP only).
session_start();
// Create a new CSRF token.
if (! isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32));
}
@codler
codler / gist:3906826
Created October 17, 2012 17:18
Support HTTP Header Range, mp4, php.php/mp4.mp4
<?php
# Nginx don't have PATH_INFO
if (!isset($_SERVER['PATH_INFO'])) {
$_SERVER['PATH_INFO'] = substr($_SERVER["ORIG_SCRIPT_FILENAME"], strlen($_SERVER["SCRIPT_FILENAME"]));
}
$request = substr($_SERVER['PATH_INFO'], 1);
$file = $request;
$fp = @fopen($file, 'rb');
@baniol
baniol / canvas_animation.html
Created March 29, 2014 09:54
basic canvas animation, javascript, requestAnimationFrame, solar system
<html>
<head>
<style type="text/css">
/*canvas{ width: 300px; height: 300px;}*/
</style>
</head>
<body>
<canvas id="canvas" width="300" height="300"></canvas>
@Fysac
Fysac / counter.php
Last active January 20, 2023 17:28
Database-less, sessionless way to count online users in PHP.
<?php
$timeout = 300; // 5 minutes
$time = time();
$ip = $_SERVER["REMOTE_ADDR"];
$file = "users.txt";
$arr = file($file);
$users = 0;
for ($i = 0; $i < count($arr); $i++){
if ($time - intval(substr($arr[$i], strpos($arr[$i], " ") + 4)) > $timeout){
@jonathanstark
jonathanstark / verify-google-recaptcha-with-php
Last active July 16, 2024 17:06
Verify Google reCAPTCHA with PHP
#
# Verify captcha
$post_data = http_build_query(
array(
'secret' => CAPTCHA_SECRET,
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $_SERVER['REMOTE_ADDR']
)
);
$opts = array('http' =>
@jacobbubu
jacobbubu / countries.json
Created April 9, 2015 07:13
Chinese country names and their ISO code
[
{
"ISO2": "AD",
"ISO3": "AND",
"DIGITS": "20",
"ISO-3166-2": "ISO 3166-2:AD",
"English": " Andorra",
"China": "安道尔",
"Taiwan": "安道爾",
"Hongkong": "安道爾",
@n0531m
n0531m / list_gcp_iprange.sh
Last active July 11, 2024 19:34
Google Cloud Platform : ip address range
#!/bin/bash
# https://cloud.google.com/compute/docs/faq#find_ip_range
# nslookup -q=TXT _cloud-netblocks.googleusercontent.com 8.8.8.8
myarray=()
for LINE in `dig txt _cloud-netblocks.googleusercontent.com +short | tr " " "\n" | grep include | cut -f 2 -d :`
do
myarray+=($LINE)
for LINE2 in `dig txt $LINE +short | tr " " "\n" | grep include | cut -f 2 -d :`