This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A Tour of Go: page 44 | |
http://tour.golang.org/#44 | |
Exercise: Loops and Functions | |
As a simple way to play with functions and loops, implement the square root function using Newton's method. | |
In this case, Newton's method is to approximate Sqrt(x) by picking a starting point z and then repeating: z - (z*z - x) / (2 * z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Exercise: Loops and Functions #43 */ | |
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func Sqrt(x float64) float64 { | |
z := float64(2.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ROT13 implementation | |
* | |
* @see https://en.wikipedia.org/wiki/ROT13 | |
* @param string $message | |
* @return string | |
*/ | |
function rot13($message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ROT13 implementation with php://filter | |
* | |
* @see http://php.net/manual/en/wrappers.php.php | |
* @param string $message | |
* @return string | |
*/ | |
function rot13_filter($message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# @see http://php.net/manual/en/wrappers.php.php | |
# | |
# NOTA BENE | |
# __FILE__ does not work as expected when executed by eval() | |
$file = __FILE__; | |
# or by convert.quoted-printable-encode | |
print include "php://filter/convert.base64-encode/resource={$file}"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$n = range(0,9); | |
$a = range('a','z'); | |
$t = count($a); | |
for($i = 0; $i < $t; $i++) | |
for($z = 0; $z < $t; $z++) | |
mkdir(__DIR__.'/dirs/'.$a[$i].$a[$z], 0700); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$word = 'scmo'; | |
$pspell_config = pspell_config_create("it"); | |
# Available modes: | |
# | |
# PSPELL_FAST | |
# PSPELL_NORMAL | |
# PSPELL_BAD_SPELLERS # this will slow down the script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
if LC_ALL=C grep -q '[^[:print:][:space:]]' "/path/to/file.jpg"; then | |
echo "file contains non-ascii characters" | |
else | |
echo "file contains ascii characters only" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hello | |
world | |
apple | |
fruit | |
banana | |
yellow | |
orange | |
strawberry | |
cherry | |
pie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Type: text/csv'); | |
$data[] = ['sent' | |
, 'success' | |
, '114661698' | |
, '709081462' | |
, '+919900123456' | |
]; |