Skip to content

Instantly share code, notes, and snippets.

View mpyw's full-sized avatar
🏠
Working from home

mpyw mpyw

🏠
Working from home
View GitHub Profile
@torsten
torsten / proxy.rb
Last active April 30, 2024 17:53
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@jwage
jwage / SplClassLoader.php
Last active April 9, 2024 21:04
Add MIT license.
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
<?php
function curl_setopt_custom_postfields($ch, $postfields, $headers = null) {
$algos = hash_algos();
$hashAlgo = null;
foreach ( array('sha1', 'md5') as $preferred ) {
if ( in_array($preferred, $algos) ) {
$hashAlgo = $preferred;
break;
}
}
@shibason
shibason / mikusan.rb
Created September 19, 2010 05:52
AA Quine & AA Quine generator (Hatsune Miku)
eval$s=%w~
a=->(b,c, d,e,f){%`#{(c)?"re quire'zlib';":'
'}g=Marshal.load(#{ (c)?'Z lib::Inflate.infl
ate(':''}'#{b}'. unpack('m')[0]#{(c)?')':
''});h= 'eval$s =%w'<<126<<($s*#{d} );i='
';j=- 1; #{ e*f}.times{|k|i<< (g[
k]== 1? h[j+=1]:32);i<<10i f
(k% #{e} ==#{e-1})};i[-7,6]
=' ' < <126<< '.join';puts(i)#`};
$*[ 0]? ( require' RMagick';include(Ma
@rsky
rsky / cli-do-not-echo-password.php
Created January 23, 2011 23:07
PHPのコマンドラインツールでパスワードを要求するときの定番コード
<?php
// STDOUT or STDERR は場合に応じて
fwrite(STDERR, 'Password: ');
if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
// WindowsではエコーバックをOFFにできない?
@flock(STDIN, LOCK_EX);
$password = fgets(STDIN);
@flock(STDIN, LOCK_UN);
} else {
system('stty -echo'); // エコーバックをOFFにする
@briancavalier
briancavalier / simple-promise-retry.js
Created February 24, 2011 18:35
A few general patterns for retries using promises
function keepTrying(otherArgs, promise) {
promise = promise||new Promise();
// try doing the important thing
if(success) {
promise.resolve(result);
} else {
setTimeout(function() {
keepTrying(otherArgs, promise);
@schacon
schacon / gist:942899
Created April 26, 2011 19:19
delete all remote branches that have already been merged into master
$ git branch -r --merged |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
awk '{split($0,a,"/"); print a[2]}' |
xargs git push origin --delete
@bstpierre
bstpierre / hexecho
Created August 25, 2011 14:51
Dump a (binary) file as a series of hex escape sequences
#!/bin/bash
#
#
# Dump a (binary) file as a series of hex escape sequences suitable
# for bash's builtin "echo -n -e".
#
# `od -tx1` outputs each byte as two hex digits, on multiple lines,
# with each line beginning with the offset.
@sugyan
sugyan / activity.pl
Created December 12, 2011 07:50
Twitter activity API test
#!/usr/bin/env perl
use strict;
use warnings;
use Config::Pit;
use Data::Dumper;
use Furl;
use HTTP::Request::Common;
use JSON::XS 'decode_json';
use OAuth::Lite::Consumer;
@Dither
Dither / cssify.js
Created February 25, 2012 17:38
Convert XPath to CSS selector
// JavaScript function for converting simple XPath to CSS selector.
// Ported by Dither from [cssify](https://github.com/santiycr/cssify)
// Example: `cssify('//div[@id="girl"][2]/span[@class="body"]//a[contains(@class, "sexy")]//img[1]')`
var sub_regexes = {
"tag": "([a-zA-Z][a-zA-Z0-9]{0,10}|\\*)",
"attribute": "[.a-zA-Z_:][-\\w:.]*(\\(\\))?)",
"value": "\\s*[\\w/:][-/\\w\\s,:;.]*"
};