A Brief Introduction to Multi-Threading in PHP
- Foreword
- Execution
- Sharing
- Synchronization
- Pitfalls
| M[16],X=16,W,k;main(){T(system("stty cbreak") | |
| );puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i | |
| ,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M | |
| [w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<< | |
| (l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k) | |
| ]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d | |
| -1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X] | |
| *i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4; | |
| )s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4|| | |
| puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2 |
| import os,tty;tty.setcbreak(0);M=['']*16 | |
| def G(v): | |
| p=['']*4;u=list(filter(str,v));i=3 | |
| while u:z=u.pop();p[i]=u and z==u[-1]and 2*u.pop()or z;i-=1 | |
| return p | |
| def Y(M,k):i=1;M=zip(*[iter(M)]*4);exec'M=map([list,G][i*k==k*k],zip(*M))[::-1];i+=1;'*4;return sum(M,[]) | |
| while 1: | |
| r=id(M)%71+17 | |
| while M[r%16]*r:r-=1 | |
| if r:M[r%16]=r%7%2*2+2 |
| /** | |
| * An experiment in how DAGs work for common subexpression elimination. | |
| */ | |
| package compiler; | |
| import java.io.BufferedReader; | |
| import java.io.FileNotFoundException; | |
| import java.io.FileReader; | |
| import java.io.IOException; | |
| import java.io.Reader; |
| #! /usr/bin/env python3 | |
| # Convert all markdown files in the current folder to PDF using pandoc | |
| import os | |
| import subprocess | |
| import time | |
| MARKDOWN_EXTS = ('.markdown', '.md') | |
| # Using abspath means I don't have to manually specify the folder name | |
| ROOT_FOLDER = os.path.split(os.path.abspath(__file__))[0] |
This is a very simply routing system that makes it easy to test requests to different paths. This is very limited so do not use for your applications - it's just for fun.
require('route.php');
// A user profile
route('/(\w+)/profile', function($path, $user)
{
print "Hello " . $user;
| <?php | |
| function twitterify($str) { | |
| $str = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $str); | |
| $str = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $str); | |
| $str = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $str); | |
| $str = preg_replace("/#(\w+)/", "<a href=\"http://twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $str); | |
| return $str; | |
| } |
| #!/bin/bash | |
| # This deploy hook gets executed after dependencies are resolved and the | |
| # build hook has been run but before the application has been started back | |
| # up again. This script gets executed directly, so it could be python, php, | |
| # ruby, etc. | |
| export COMPOSER_HOME="$OPENSHIFT_DATA_DIR/.composer" | |
| if [ ! -f "$OPENSHIFT_DATA_DIR/composer.phar" ]; then | |
| curl -s https://getcomposer.org/installer | /usr/local/zend/bin/php -- --install-dir=$OPENSHIFT_DATA_DIR |
| /* | |
| <a href="posts/2" data-method="delete"> <---- We want to send an HTTP DELETE request | |
| - Or, request confirmation in the process - | |
| <a href="posts/2" data-method="delete" data-confirm="Are you sure?"> | |
| */ | |
| (function() { |
| data:text/html;charset=utf-8, <title>TextEditor</title> <link rel="shortcut icon" href="http://g.etfv.co/https://docs.google.com"/> <style> html{height: 100%;} body{background: -webkit-linear-gradient(#f0f0f0, #fff); padding: 3%; height: 94%;} .paper { font: normal 12px/1.5 "Lucida Grande", arial, sans-serif; width: 50%; height: 80%; margin: 0 auto; padding: 6px 5px 4px 42px; position: relative; color: #444; line-height: 20px; border: 1px solid #d2d2d2; background: #fff; background: -webkit-gradient(linear, 0 0, 0 100%, from(#d9eaf3), color-stop(4%, #fff)) 0 4px; background: -webkit-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -moz-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -ms-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -o-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; -webkit-background-size: 100% 20px; -moz-background-size: 100% 20px; -ms-background-size: 100% 20px; -o-background-size: 100% 20p |