Skip to content

Instantly share code, notes, and snippets.

@cereal-s
cereal-s / gist:4346df99d116786a3b54036b2e84a728
Created November 25, 2016 16:00 — forked from abesto/gist:3476594
Go: Newton's method for square root
/*
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)
@cereal-s
cereal-s / exercise.tour.go
Created November 27, 2016 22:33 — forked from zyxar/exercise.tour.go
tour.golang exercise solutions
/* Exercise: Loops and Functions #43 */
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(2.)
@cereal-s
cereal-s / rot13.php
Created November 28, 2016 17:45
ROT13 implementation
<?php
/**
* ROT13 implementation
*
* @see https://en.wikipedia.org/wiki/ROT13
* @param string $message
* @return string
*/
function rot13($message)
@cereal-s
cereal-s / rot13.filter.php
Created November 28, 2016 18:22
ROT13 implementation with php://filter
<?php
/**
* ROT13 implementation with php://filter
*
* @see http://php.net/manual/en/wrappers.php.php
* @param string $message
* @return string
*/
function rot13_filter($message)
@cereal-s
cereal-s / read.file.php
Created November 28, 2016 22:18
Read file
<?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}";
<?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);
<?php
$word = 'scmo';
$pspell_config = pspell_config_create("it");
# Available modes:
#
# PSPELL_FAST
# PSPELL_NORMAL
# PSPELL_BAD_SPELLERS # this will slow down the script
#!/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
@cereal-s
cereal-s / dict.pwl
Last active December 19, 2016 12:15
hello
world
apple
fruit
banana
yellow
orange
strawberry
cherry
pie
<?php
header('Content-Type: text/csv');
$data[] = ['sent'
, 'success'
, '114661698'
, '709081462'
, '+919900123456'
];