$_SERVER get code status
function getHttpStatus($url)
{
$headers = get_headers($url, 1);
return $headers[0];
}
All generations.
function getHttpStatus($url)
{
$headers = get_headers($url, 1);
return $headers[0];
}
function compare(a, b){
if(a>b){
return true
}
return false
}
compare(1.1, 2.2)
function printTime(name, age) {
console.log(name + " is " + age + " years old.");
}
printTime("Bob", 32);
function cutArray(arrayToCut, from, to) {
return arrayToCut.slice(from, to);
}
cutArray([2, 3, 4, 5, 6, 7, 8, 9], 2, 5)
def max(a, b):
return a if a > b else b
max(1, 2)
function saveToJson(path, data) {
fs.writeFile(path, data, err => {
console.log(err);
});
}
function openFromJson(path) {
return JSON.parse(fs.readFileSync(path).toString());
}
function getLast1000() {
return array_slice(getAll(), -1000);
}
$last1000 = getLast1000();
def pack(archive, file):
return gz_file(file, archive)
pack('archive.tar.gz', 'file.txt')
const users = [
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "Sincere@april.biz",
address: {
street: "Kulas Light",
suite: "Apt. 556",
city: "Gwenborough",
zipcode: "92998-3874",
geo: {
lat: "-37.3159",
lng: "81.1496"
}
},
phone: "1-770-736-8031 x56442",
website: "hildegard.org",
company: {
name: "Romaguera-Crona",
catchPhrase: "Multi-layered client-server neural-net",
bs: "harness real-time e-markets"
}
},
{
id: 2,
name: "Ervin Howell",
username: "Antonette",
email: "Shanna@melissa.tv",
function get_tld($url) {
$tld = '';
$parsed_url = parse_url($url);
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
if ($host == '') {
return $tld;
}
$host_components = explode('.', $host);
$tld_components = array_slice($host_components, -2);
$tld = implode('.', $tld_components);
return $tld;
}
function add(a, b) {
return a + b;
}
add(1, 2)
$files = glob('/var/www/uploads/*.txt');
sort($files);
foreach($files as $file) {
echo "$file size " . filesize($file) . "\n";
}
/<a\s+href\s*=\s*['"]?\s*(.*?)\s*['"]?\s*>(.*?)<\/a>/
function last_1000($array) {
return array_slice($array, -1000);
}
last_1000([0, 1, 2, 3, 4, 5, 6, 7, ...])
/^b/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2");
$output = curl_exec($ch);
curl_close($ch);
/[\d\D]/
function gzencode($data, $level = -1, $encoding_mode = FORCE_GZIP) {
return gzinflate(substr($data, 10, -8));
}
function removeFirstSymbol($string) {
return substr($string, 1);
}
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x;
if (confirm("Press a button!") == true) {
x = "You pressed OK!";
} else {
x = "You pressed Cancel!";
}
document.getElementById("demo").innerHTML = x;
}
</script>
/\w+[a-zA-Z]+\w+/g
function personal_hash(string $password, string $salt, int $iterations, int $length): string
{
return substr(hash('sha256', $salt . hash('whirlpool', $password) . $salt), 0, $length);
}
function Big(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
Big("hello")
function dates () {
const d = new Date();
const days = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
const dd = [];
for (let i = 1; i <= days; i++) {
dd.push(i);
}
return dd;
}
function push(array, item) {
array[array.length] = item;
return array.length;
}
foreach (glob("*.txt") as $filename) {
$newname = $filename . '.bak';
rename($filename, $newname);
}
function truncate(array $a, $b) {
return array_slice($a, $b);
}
echo truncate([1,2,3,4,5,6,7,8], 4);
function removePercentage(str){
return str.replace(/%/g, '');
}
removePercentage('100%')
function is_divisible_by_five($number)
{
return $number % 5 == 0;
}
function svg2png($string, $filename) {
$encoded = base64_encode($string);
$data = "data:image/svg+xml;base64,$encoded";
$image = new Imagick();
$image->readImageBlob($data);
$image->setImageFormat("png24");
$image->writeImage("$filename");
}
// parse csv
$parsed_data = array_map('str_getcsv', file('data.csv'));
echo '<pre>';
print_r($parsed_data);
echo '</pre>';
function find_percentage($total, $part) {
return ($part / $total) * 100;
}
function clearString(str){
return str.replace(/[^\d]/g, '');
}
function remove(element) {
element.remove();
}
remove(document.getElementById('myDiv'));
$str = 'Привет, Мир! #hashtag только буквы и цифры и пробелы';
$str = preg_replace("/[^a-zA-ZА-Яа-я0-9\s]/u", '', $str);
"team":"10932"
/^b\w+/
function largestOfFour(arr) {
return arr.map(Function.apply.bind(Math.max, null));
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
function is_password_valid($password) {
if (preg_match("/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)[a-zA-Z\d]{8,}$/",$password)) {
echo "password valid";
} else {
echo "password not valid";
}
}
is_password_valid("Password123");
function enMonth($day, $month, $year) {
$day = ($year % 4 == 0) ? $day: $day+1;
$days = [31, $day, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
$enMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
$d = 0;
for ($i = 0; $i < count($days); $i++) {
if ($month > $days[$i]) {
$d += $days[$i];
} else {
$d += $month;
break;
}
}
//echo $d . "<br>";
$m = 0;
for ($i = 0; $m < $d; $i++) {
$m += $days[$i];
}
/<a href="(.+?)">(.+?)<\/a>/
/<a.+?\/a>/g
function replace(s, a, b){
let result = ''
for(let i=0; i< s.length; i++){
if(s[i] == a){
s[i] = b
}
}
return result
}
function month_name_rus($month) {
$array = array(
'January' => 'Января',
'February' => 'Февраля',
'March' => 'Марта',
'April' => 'Апреля',
'May' => 'Мая',
'June' => 'Июня',
'July' => 'Июля',
'August' => 'Августа',
'September' => 'Сентября',
'October' => 'Октября',
'November' => 'Ноября',
'December' => 'Декабря'
);
return $array[$month];
}
function domain_age($domain) {
$domain = DateTime::createFromFormat('Y-m-d', substr($domain, -10));
return $domain->diff(new DateTime())->format('%y');
}
/:capital/g
function clock() {
console.log(new Date());
}
setInterval(clock, 1000);
function copy(text){
return text
}
copy("text")
function unix_time_today() {
return strtotime('today midnight');
}
function copy(text) {
return text
}
// or
var copy = function(text){
return text
}
<?php
function svgtojpg($svg) {
$svg = urlencode($svg)
return 'http://svg2jpg.com?svg=' . $svg
}
echo svgtojpg('<svg></svg>')
?>
html
<a href="https://www.google.com">google</a>
/<\/?p>/
var today = new Date();
var hourNow = today.getHours();
var greeting;
if (hourNow > 18) {
greeting = 'Good evening!';
} else if (hourNow > 12) {
greeting = 'Good afternoon!';
} else if (hourNow > 0) {
greeting = 'Good morning!';
} else {
greeting = 'Welcome!';
}
document.write('<h3>' + greeting + '</h3>');
function truncate($string, $length)
{
$suffix = '...';
return (strlen($string) > $length) ? substr($string, 0, $length - strlen($suffix)) . $suffix : $string;
}
echo truncate('В настоящее время в мире широко распространено использование стандартных контейнеров предоставляемых языком C++. Они полезны для обработки объектов, не связанных между
def replace_last_number(a):
a = str(a)
return int(a[:-1] + '0')
function get_domain($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : '';
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
return $regs['domain'];
}
return false;
}
get_domain('http://www.google.com/a/b/c/d/e.html')
function formatNumber(number) {
return number.toFixed(5)
}
formatNumber(1.2345)
function get_personal_hash(name) {
return name + ' ' + name
}
get_personal_hash('bob')
function hide_name($email) {
return substr($email, 0, 3). "...";
}
hide_name('johndoe@gmail.com')
function shuffleString($str){
$arr = str_split($str);
shuffle($arr);
return implode($arr);
}
shuffleString("hello");
/<a[^>]*>/
function each(list, callback) {
for (let i = 0; i < list.length; i++) {
callback(list[i], i, list);
}
}
each([1,2,3], (item, index, array) => console.log(item, index, array)) // 1 0 [1, 2, 3] 2 1 [1, 2, 3] 3 2 [1, 2, 3]
function Test() {
return 1 + 2;
}
$people = [
'John Doe',
'Jane Doe',
'Joe Bloggs',
'Sophie Doe',
'John Doe',
'Jane Doe',
'Joe Bloggs',
'Sophie Doe',
'John Doe',
'Jane Doe',
'Joe Bloggs',
'Sophie Doe'
];
function last10($array)
{
return array_slice($array, -10);
}
last10($people);
function fullname_ru($first_name, $last_name) {
$fullname = $first_name . ' ' . $last_name;
return $fullname;
}
echo fullname_ru('Иван', 'Иванов'); // Иван Иванов
function gzip_and_stream_archive($archive_file_path)
{
if (file_exists($archive_file_path)) {
if (function_exists('gzencode')) {
$archive_size = filesize($archive_file_path);
$fp = fopen($archive_file_path, 'r');
if ($fp) {
// send gzipped archive
header("Content-Encoding: gzip");
header("Content-Length: " . $archive_size);
header("Content-Disposition: attachment; filename=backup.tar.gz");
print(gzencode(fread($fp, $archive_size)));
fclose($fp);
unlink($archive_file_path);
return true;
}
} else {
// send unencoded archive
header("Content-Type: application/x-gzip");
header("Content-Length: " . filesize($archive_file_path));
header("
`
/[0-9a-z:]/
/<a.*?.*?</a>/g
function floatTo5Symbols (number) {
return Number.parseFloat(number).toFixed(5);
}
floatTo5Symbols (12.34567)
<?php
$month = array(
'01' => 'января',
'02' => 'февраля',
'03' => 'марта',
'04' => 'апреля',
'05' => 'мая',
'06' => 'июня',
'07' => 'июля',
'08' => 'августа',
'09' => 'сентября',
'10' => 'октября',
'11' => 'ноября',
'12' => 'декабря'
);
?>
function(str){
return str.replace(/[^\d]/g, "");
}
function array_slice_assoc(array &$array, $offset, $length = null, $preserve_keys = false) {
$array = array_slice($array, $offset, $length, $preserve_keys);
return $array;
}
$arr = array(
'a' => 1,
'b' => 2,
'c' => 3,
'd' => 4
);
$arr = array_slice_assoc($arr, 1);
print_r($arr);
/[^!]+/
function add($a, $b) {
return a + b;
}
return add(1, 2);
function gz($file) {
return gzcompress(file_get_contents($file), 9);
}
gz("file.txt")
substr("12345", 3)
const toFixed = (value, precision) => {
const power = Math.pow(10, precision || 0);
return String(Math.round(value * power) / power);
};
console.log(toFixed(0.123456789, 5)); // '0.12346'
console.log(toFixed(0.123456789, 2)); // '0.12'
console.log(toFixed(2.345, 2)); // '2.35'
console.log(toFixed(2.355, 2)); // '2.35'
function removeParent(element) {
element.parentNode.removeChild(element);
}
/h\w+/
function age($birthday)
{
$age = (time() - strtotime($birthday)) / 31556926;
return floor($age);
}
/\w/
/1\d{2}|[2-9]\d{2}|[1-9]\d{3,4}/
function month($month_number):
$month_dict = {
1: 'January',
2: 'February',
3: 'March',
4: 'April',
5: 'May',
6: 'June',
7: 'July',
8: 'August',
9: 'September',
10: 'October',
11: 'November',
12: 'December'
}
return $month_dict[$month_number]
month(1)
function add(a, b) {
return a + b;
}
add(1, 2);
function get_last_item($array) {
return array_pop($array);
}
function reverse_percent($percent) {
return (1 - ($percent / 100));
}
$reverse_percent = reverse_percent(20);
function onClick(e) {
Logger.log(e.values)
}
function age($now, $birth) {
return $now - $birth;
}
age(2020, 1994);
function rand(){
return "random";
}
rand()
<button id="button">Click me</button>
var button = document.getElementById("button");
function disableButton() {
button.disabled = true;
}
setTimeout(disableButton, 10);
function en(mounth) {
if(mounth == '1'){
return 'January'
}
if(mounth == '2'){
return 'February'
}
if(mounth == '3'){
return 'March'
}
if(mounth == '4'){
return 'April'
}
if(mounth == '5'){
return 'May'
}
if(mounth == '6'){
return 'June'
}
if(mounth == '7'){
return 'July'
}
if(mounth == '8'){
return 'August'
}
if(mounth == '9'){
return 'September'
}
if(mounth == '10'){
return 'October'
}
if(mounth == '11'){
return 'November'
}
if(mounth == '
const getUrl = (url) => {
const request = new Request(url, {
method: 'GET',
cache: 'default'
});
fetch(request).then(res => res.json()).then(res => console.log(res));
}
getUrl('https://api.github.com/users/jacky99')
function readFile(filename, content) {
fs.readFile(filename, function(err, data) {
if (err) throw err;
console.log('File saved!');
});
}
function writeFile(filename, content) {
fs.writeFile(filename, content, function(err) {
if (err) throw err;
console.log('File saved!');
});
}
function truncate(input, places) {
if(input >= Math.pow(10, places)) {
return input.toString().slice(0, -1 * places) + "." + input.toString().slice(-1 * places);
} else {
return input.toString();
}
}
function max(a, b) => a > b ? a : b
function getMonthName($a) {
$array = [
1 => 'январь',
2 => 'февраль',
3 => 'март',
4 => 'апрель',
5 => 'май',
6 => 'июнь',
7 => 'июль',
8 => 'август',
9 => 'сентябрь',
10 => 'октябрь',
11 => 'ноябрь',
12 => 'декабрь',
];
if (array_key_exists($a, $array)) {
return $array[$a];
}
return null;
}
getMonthName(1);
/1\d{2}|[2-9]\d{3}|[1-9]\d{4}/
$ip = "255.255.255.0";
$ip_array = explode(".", $ip);
echo $ip_array[0];
$_SERVER['REDIRECT_STATUS']
function add(a, b) {
return a + b;
}
add(1, 2)
<?php
$percent = 5 / 100;
$discount = $percent * $price;
$discounted_price = $price - $discount;
?>
function setTimezone0(targetDate) {
return targetDate - (7 * 60 * 60 * 1000) - 3600000;
}
if (text === 'hello') {
console.log('hello');
}
<?php
$str = 'abcdef';
$str = substr_replace($str, 'bob', -4, -1);
echo $str;
?>
function todayUTC() {
var date = new Date();
date.setHours(date.getHours() + 9);
return date.toISOString().slice(0, 10);
}
<?php
function fullname($month) {
switch ($month) {
case 1:
return "Январь";
break;
case 2:
return "Февраль";
break;
case 3:
return "Март";
break;
case 4:
return "Апрель";
break;
case 5:
return "Май";
break;
case 6:
return "Июнь";
break;
case 7:
return "Июль";
break;
case 8:
return "Август";
break;
case 9:
return "Сентябрь";
break;
case 10:
return "Октябрь";
break;
case 11:
return "Ноябрь";
var time = function() { console.log('hello world') }
function myFunction($name="Default") {
return "Hello World" . $name;
}
myFunction("John");
function chop_off(string, n) {
return string.substring(0, n);
}
chop_off("hello world", 5);
function get_tld($domain) {
if (preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", $domain, $matches))
return $matches['domain'];
return '';
}
<?php
function gzencode($data, $mode = 9, $encoding_mode = FORCE_GZIP) {
$flags = 0;
if ($mode != $mode) {
$flags += 1;
}
if ($encoding_mode == FORCE_GZIP) {
$flags += 2;
}
if (function_exists("gzencode")) {
return gzencode($data, $mode, $flags);
}
return $data;
}
?>
function unique(arr) {
var result = [];
for (var str of arr) {
if (!result.includes(str)) {
result.push(str);
}
}
return result;
}
var strings = ["кришна", "кришна", "харе", "харе",
"харе", "харе", "кришна", "кришна", ":-O"
];
alert( unique(strings) ); // кришна, харе, :-O
div{
width: calc(100% - 20px);
}
<?php
$svg = <<< EOT
...
...
...
EOT;
$svg = file_get_contents('https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_announcement_48px.svg');
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImageBlob($svg);
$im->setImageFormat("jpg");
$im->writeImage('image.jpg');
?>
$name = array('first' => 'Jack', 'last' => 'Bauer');
function get_last_key($arr){
end($arr);
return key($arr);
}
get_last_key($name);
javascript
/href='\S+'/
function get_xml(){
$xml_doc = new DOMDocument();
$xml_doc->load("http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=2de143494c0b295cca9337e1e96b00e0");
$xml_string = $xml_doc->saveXML();
$filename = "xml_" . time();
$gzfilename = $filename . ".gz";
$fp = fopen($gzfilename, "w");
fwrite($fp, $xml_string);
fclose($fp);
$fd = fopen ($gzfilename, "r");
header("Content-Type: application/x-gzip");
header("Content-Disposition: attachment; filename=\"".$gzfilename."\"");
fpassthru($fd);
unlink($gzfilename);
}
$gz = gzencode($string, 9);
$filename = 'compressed.gz';
header("Content-Encoding: gzip");
header("Content-Length: ".strlen($gz));
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: text/plain");
echo $gz;
<?php
$str = "12345678";
echo substr_replace($str, "0", -1);
?>
function f(n) {
return parseFloat(n.toFixed(5))
}
/([1-9][\d]{0,2}(,\d{3})+(\.\d+)?)|([1-9]\d*(\.\d+)?)/
function getDaysInMonth(month, year) {
return new Date(year, month, 0).getDate();
}
getDaysInMonth(1, 2020)
function stream_curl_gzencoded($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
<?php
function gzencode_and_stream_http_archive() {
function get_current_url() {
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$url = get_current_url();
header("Content-Type: application/x-gzip");
header("Content-Disposition: attachment; filename=web.archive");
$curl = curl_init();
curl_
$csv = '"1","2","3","4"';
$csv_data = str_getcsv($csv);
<?php
number_format(1.11, 2);
?>
function date_to_text(date) {
return date.toLocaleDateString(
"en-US",
{
year: "numeric",
month: "short",
day: "numeric"
}
);
}
function tar_gz($source, $destination)
{
if (extension_loaded('zlib')) {
if (is_file($source)) {
$file = basename($source);
$source = dirname($source);
} else {
$file = basename($destination);
$source = $source;
}
if (!file_exists("$destination/$file.gz")) {
$destination = dirname($destination);
if (!extension_loaded('zlib')) {
return false;
}
$archive = new PharData("$source/$file");
$archive->compress(Phar::GZ);
unset($archive);
rename("$source/$file.gz", "$destination/$file.gz");
return "$destination/$file.gz";
}
}
return false;
}
function add(a, b) {
return a + b
}
add(1, 2)
let x = 9.656;
console.log(x.toFixed(5));
// expected output: "9.65600"
def month(i):
months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
return months[i]
month(4)
function add(a, b) {
return a + b;
}
add(1, 2);
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
capitalize('hello') // Hello
function archive($archive_name, $file_name) {
$arch = gzencode($file_name, 9);
file_put_contents($archive_name, $arch);
return $archive_name;
}
archive('archive.gz', 'file.txt');
function cut_string($s) {
return $s.length > 5 ? substr($s, 0, 5) : $s;
}
cut_string('abcdefghijklm')
const str = "ПРИВЕТ ВСЕМ!"
const lower = str.toLowerCase();
alert(lower);
function random_float ($min,$max) {
return ($min+lcg_value()*(abs($max-$min)));
}
random_float(0,1)
function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function asyncPrint(value, ms) {
await timeout(ms);
console.log(value);
}
asyncPrint('hello world', 5000);
function tld($domain) {
$pieces = explode('.', $domain);
$tld = array_pop($pieces);
return $tld;
}
tld('www.example.com');
function setTimeZone(0) {
return 0
}
/languagesList current/
function getStatusCode($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE); // remove body
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $status;
}
function getRandom(): float
{
return random_float();
}
/^[a-zA-Z0-9]{6,15}$/
function get_domain_name($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : '';
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
return $regs['domain'];
}
return false;
}
function oddEven(a){
if( a % 2 == 0){
return "even";
}
else{
return "odd";
}
}
oddEven(3);
function getFloat(number, precision) {
if(precision === undefined) {
precision = 2;
}
return number.toFixed(precision);
}
getFloat(1.123456); // 1.12
getFloat(1.123456, 3); // 1.123
function hash_password($password){
$salt = "007";
$hash_password = md5($salt . $password);
return $hash_password;
}
function get_tdl($domain) {
return strstr($domain, '.');
}
get_tdl('www.google.com');
function get_last($array) {
return $array[count($array) - 1];
}
get_last(['a', 'b', 'c'])
$files = glob('*.txt');
foreach($files as $file) {
$newname = str_replace('txt', 'md', $file);
rename($file, $newname);
}
function percentOf($num, $percent, $round = null) {
if ($round === null) {
$round = 0;
}
return round($num * $percent / 100, $round);
}
var hh = 0;
var mm = 0;
var ss = 0;
var start = false;
var timerInterval = null;
function startTimer() {
if (start === false) {
start = true;
timerInterval = setInterval(function() {
ss++;
if (ss === 60) {
mm++;
ss = 0;
}
if (mm === 60) {
hh++;
mm = 0;
}
var newTime = (hh < 10 ? '0' + hh : hh) + ':' + (mm < 10 ? '0' + mm : mm) + ':' + (ss < 10 ? '0' + ss : ss);
document.querySelector('.timer').innerHTML = newTime;
}, 1000);
}
}
function stopTimer() {
if (start === true) {
start = false;
clearInterval(timerInterval);
}
}
function resetTimer() {
stopTimer();
hh
function percent(a, b):
return a + b/100
percent(100, 10)
random.random()
.container {
width: calc(100% - 10px);
height: calc(100% - 10px);
}
function hash(input):
return input
function max(a, b) {
return a > b ? a : b;
}
/(\d+\.\d+)|\d+/
<?php
function input($name) {
return "<input name='" . $name . "'>";
}
echo input('username');
// <input name='username'>
?>
function clock() {
var now = new Date();
var ctx = document.getElementById('clock').getContext('2d');
ctx.save();
ctx.clearRect(0,0,150,150);
ctx.translate(75,75);
ctx.scale(0.4,0.4);
ctx.rotate(-Math.PI/2);
ctx.strokeStyle = "black";
ctx.fillStyle = "white";
ctx.lineWidth = 8;
ctx.lineCap = "round";
// Hour marks
ctx.save();
for (var i=0;i<12;i++){
ctx.beginPath();
ctx.rotate(Math.PI/6);
ctx.moveTo(100,0);
ctx.lineTo(120,0);
ctx.stroke();
}
ctx.restore();
// Minute marks
ctx.save();
ctx.line
function generatePhrase($a, $b, $c) {
$phrase = "$a $b $c";
return $phrase;
}
$phrase = generatePhrase("nice", "to", "meet you");
echo $phrase;
'string'.replace(/^.../, 'foo');
var time = new Date().getHours()
if (time < 10) {
document.write("Good morning")
} else if (time < 20) {
document.write("Good day")
} else {
document.write("Good evening")
}
/1[0-9]{2}|2[0-4][0-9]|25[0-5]|[1-9]?[0-9]/
http_response_code(404);
function find_longest_word($a) {
$longest_word = '';
foreach($a as $word) {
if(strlen($word) > strlen($longest_word)) {
$longest_word = $word;
}
}
return $longest_word;
}
rand()
function hide_symbols($text) {
return substr($text, 5);
}
hide_symbols('Hello world'); // output: world
function random_float ($min,$max) {
return ($min+lcg_value()*(abs($max-$min)));
}
function getNextMonth(){
var today = new Date();
return today.getMonth() + 1;
}
getNextMonth()
/[0-9a-z:]/
function clock() {
return new Date().toLocaleString();
}
clock();
/[0-9]{2,}/
function gzencode_http_zip($gzdata){
$gzsize = strlen($gzdata);
$gzcrc = crc32($gzdata);
$gzdata = gzcompress($gzdata,9);
$gzdata = substr($gzdata,0,strlen($gzdata)-4);
$rawdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00".$gzdata."\x00\xff\xff".pack('V',$gzcrc).pack('V',$gzsize);
return $rawdata;
}
function get_status_code($url){
$str = file_get_contents($url);
if(strlen($str)>0){
preg_match('/http_code:(\d+)/', $str, $matches);
return $matches[1];
}
return false;
}
function percent( $number, $percent ) {
return $percent * $number / 100;
}
percent( 100, 10 );
$fruits = ['a' => 'apple', 'b' => 'banana'];
array_push($fruits, 'orange');
print_r($fruits);
function getURL(url) {
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
return xmlhttp.responseText
}
function change_message($message){
$new_message = substr_replace($message, 'Hello', 0, 5);
return $new_message;
}
change_message('Goodbye');
/href\s*=\s*"(.*?)"/
function getTDL($url){
return substr_replace(parse_url($url)["host"], ".", strrpos(parse_url($url)["host"], '.'), 1);
}
function percent($percent, $sum){
return $percent *$sum/100;
}
percent(10, 500);
function pack_gz($data) {
$gzdata = gzencode($data, 9);
return $gzdata;
}
$data = file_get_contents('sample.txt');
$gzdata = pack_gz($data);
rand(1, 100)
<?php
$domains = array('apple.com', 'google.com', 'microsoft.com');
if (in_array($_GET['domain'], $domains)) {
echo "found";
} else {
echo "not found";
}
?>
function ftp_put($source, $destination, $mode = FTP_ASCII, $context = null) {
return ftp_put($this->connection, $destination, $source, $mode, $context);
}
function ftp_put($server, $filepath, $remotepath, $username, $password) {
// add code here
}
ftp_put('ftp.example.com', '/local/filename', '/public_html/filename', 'username', 'password');
function tdl($domain) {
return 'https://' . $domain . '.tld'
}
tdl('google')
.container {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: green;
transition: 1s;
}
.container:hover {
border-radius: 0;
}
/<t\/>/
function domain_age($domain) {
// your code
}
function last1000()
{
$arr = array();
$len = count($arr);
for ($i = $len-1; $i > $len-1001; $i--) {
$arr[] = $arr[$i];
}
return $arr;
}
/languagesList\s+current/
function get_utc_datetime()
{
return new Date().toISOString().substr(0,19).replace('T',' ' );
}
console.log(get_utc_datetime());
/\d{4},\d{6}/
<?php
function filterByKey($array, $keyName) {
$result = [];
foreach ($array as $item) {
if (isset($item[$keyName])) {
$result[] = $item[$keyName];
}
}
return array_unique($result);
}
$array = [
['product_id' => 'xxxx', 'name' => 'iphone'],
['product_id' => 'yyyy', 'name' => 'samsung'],
['product_id' => 'xxxx', 'name' => 'iphone'],
];
$result = filterByKey($array, 'product_id');
print_r($result);
function fiveRound(num) {
return parseFloat(num.toFixed(5));
}
fiveRound(1.234567)
<?php
$number = trim(fgets(STDIN));
$arr = explode(' ', $number);
echo implode(' ', array_slice($arr, 1, -1));
?>
$max = function(...$arrays) {
return max(array_map('max', $arrays));
};
$max([1, 2, 3], [1, 1, 1], [1, 1, 1, 1]); // 4
function max(matrix) {
return matrix.reduce((max, row) => {
return Math.max(max, row.reduce((max, value) => Math.max(max, value), 0));
}, 0);
}
max([[1,2,3], [4,5,6], [7,8,9]]);
/href\s*=\s*(['"]?)([^'" >]+)\1/
function firstUpper(str) {
return str[0].toUpperCase() + str.slice(1);
}
function Add(a, b) {
return a + b;
}
Add(1, 2)
function copy(text) {
return text
}
copy("hello world!")
<?php
date_default_timezone_set("America/New_York");
echo date("U");
?>
var arr = [1, 2, 3];
function max(arr){
return Math.max.apply(null, arr);
}
max(arr);
function validLogin(login) {
return /^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$/.test(login);
}
validLogin('eee'); // true
validLogin('eee#'); // false
validLogin('eee@'); // false
validLogin('eee1'); // true
validLogin('eee1#'); // false
validLogin('eee1@'); // false
validLogin('eee1.'); // true
validLogin('eee1.e'); // true
validLogin('eee1.eee'); // true
validLogin('eee1.eee1'); // true
validLogin('eee1.eee1.'); // true
validLogin('eee1.eee1.e'); // true
validLogin('eee1.eee1.eee'); // false
validLogin('eee1.eee1.eee1'); // false
validLogin('eee1.eee1.eee1.'); // false
validLogin('eee
$gz_file = gzencode ( $file_contents , 9 , FORCE_GZIP ) ;
file_put_contents ( $gz_file_name , $gz_file ) ;
function round(value) {
return Number(Math.round(value+'e'+5)+'e-'+5);
}
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
capitalize('fooBar')
function getUsers(data, key) {
return data.map(function(user) {
return user[key];
});
}
def max_value(my_list):
max_ = my_list[0][0]
for i in range(len(my_list)):
for j in range(len(my_list[i])):
if my_list[i][j] > max_:
max_ = my_list[i][j]
return max_
max_value([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
<?php
function pack_to_gz($filename) {
$data = file_get_contents($filename);
return gzcompress($data, 9);
}
?>
function roundToFive(input) {
return Math.round(input * 100000) / 100000;
}
/\w+?(languagesList) \w+?(current)/
width:100px;
height:100px;
border:1px solid black;
border-radius:50%;
background:green;
transition:2s;
function gzencode($data, $level) {
// .....
}
$data = 'Compress me';
$gz = gzcompress($data, 9);
echo $gz;
public static function getRusMonths( $year, $type = false ) {
$months = array(
'01' => 'января',
'02' => 'февраля',
'03' => 'марта',
'04' => 'апреля',
'05' => 'мая',
'06' => 'июня',
'07' => 'июля',
'08' => 'августа',
'09' => 'сентября',
'10' => 'октября',
'11' => 'ноября',
'12' => 'декабря'
);
$result = array();
if ( $type ) {
foreach( $months as $key=>$value ) {
$result[$key] = self::getRusMonth(
def percent(num1, num2):
return num1 * num2 / 100
function FirstLetterToUpper(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
FirstLetterToUpper('some text')
function getMonthNumber(monthName) {
if (monthName === 'January') {
return 1;
} else if (monthName === 'February') {
return 2;
} else if (monthName === 'March') {
return 3;
} else if (monthName === 'April') {
return 4;
} else if (monthName === 'May') {
return 5;
} else if (monthName === 'June') {
return 6;
} else if (monthName === 'July') {
return 7;
} else if (monthName === 'August') {
return 8;
} else if (monthName === 'September') {
return 9;
} else if (monthName === 'October') {
return 10;
} else if (monthName === 'November') {
return 11;
} else if (monthName === 'December') {
return 12;
}
}
/team="(\d+)"/
Math.max.apply(null, [1,2,3])
<?php
function personal_hash($string){
$hash = null;
$key = "a1b2c3d4";
for ($i = 0; $i < strlen($string); ++$i) {
$hash .= $string[$i] . $key[$i];
}
return $hash;
}
?>
$(window).load(function(){
$("#svgid").change(function(){
$.ajax({
type: "POST",
url: "svgimg.php",
data: {data : $("#svgid").val() }
})
});
});
/\w/
max-width: 100px
function get_last($array)
{
return count($array) ? $array[count($array) - 1] : null;
}
function gz() {
return 'gz';
}
function getValue(elem){
console.log(elem.value)
}
def ru_month(month):
return {
'January': 'январь',
'February': 'февраль',
'March': 'март',
'April': 'апрель',
'May': 'май',
'June': 'июнь',
'July': 'июль',
'August': 'август',
'September': 'сентябрь',
'October': 'октябрь',
'November': 'ноябрь',
'December': 'декабрь'
}[month]
def fullname(first, last, month):
return f"{first} {last} {ru_month(month)}"
fullname('Peter', 'Parker', 'May')
function get_xml_archive($target)
{
$xml = get_remote_data($target);
$file_name = tempnam(sys_get_temp_dir(), 'xml');
file_put_contents($file_name, gzencode($xml));
return $file_name;
}
function removeNonNumbers(str) {
return str.replace(/\D/g,'');
}
function max(numbers) {
var currentMax = numbers[0];
for(var i = 0; i < numbers.length; i++) {
if (numbers[i] > currentMax) {
currentMax = numbers[i];
}
}
return currentMax;
}
max([1, 4, 2])
function bin2dec($str) {
$str_ary = str_split($str);
$result = 0;
foreach ($str_ary as $key => $value) {
$result += $value * pow(2, (count($str_ary) - 1 - $key));
}
return $result;
}
echo(bin2dec(110101));
function pack_to_gz($filename) {
$input = file_get_contents($filename);
$gzdata = gzencode($input, 9);
return $gzdata;
}
$gzdata = pack_to_gz("file.txt");
function uuid($personal=false){
if (!$personal) {
$uuid = random_bytes(16);
} else {
$uuid = md5(uniqid().$personal, true);
}
$uuid[6] = chr(ord($uuid[6]) & 0x0f | 0x40);
$uuid[8] = chr(ord($uuid[8]) & 0x3f | 0x80);
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($uuid), 4));
}
uuid('admin');
function cutTheArray($array, $start, $length = null) {
$count = count($array);
if($start < 0) {
$start = $count + $start;
}
if($length !== null) {
if($length < 0) {
$length = $count - $start + $length;
}
return array_slice($array, $start, $length);
} else {
return array_slice($array, $start);
}
}
cutTheArray([1, 2, 3, 4, 5, 6], 2, 1); // [3]
cutTheArray([1, 2, 3, 4, 5, 6], 0, 3); // [1, 2, 3]
cutTheArray([1, 2, 3, 4, 5, 6], -2); // [5, 6]
function getDate() {
const date = new Date();
return date.getFullYear() + '-' + date.getMonth() + '-' + date.getDay();
}
$time = time();
function add(a, b, callback) {
return callback(a + b)
}
add(1, 2, console.log) // 3
const str = 'some string';
const result = str.replace(/[^0-9.]+/g, '');
function replaceInString(str, index, replacement) {
return str.substr(0, index) + replacement+ str.substr(index + replacement.length);
}
const getDay = (date) => {
const days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
return days[date.getDay()]
}
getDay(new Date(2020, 10, 16))
$lines = file('php://stdin');
$last_lines = array_slice($lines, -100);
function pack($dir){
$dir = realpath($dir);
$phar = new PharData($dir.'.tar');
$phar->buildFromDirectory($dir);
$phar->compress(Phar::GZ);
header('Content-Type: application/x-gzip');
header('Content-Disposition: attachment; filename="'.pathinfo($dir.'.tar.gz', PATHINFO_BASENAME).'"');
echo file_get_contents($dir.'.tar.gz');
}
<?php
function xml_gz_archive() {
$api = new Api();
$xml = $api->getXml();
$gzfile = gzopen($xml, 'w9');
gzwrite($gzfile, $xml);
gzclose($gzfile);
return $gzfile;
}
function newDate(){
return new Date();
}
newDate();
<?php
function add($a, $b)
{
return $a + $b;
}
?>
<?php
$age = 18;
if ($age >= 18) {
echo "<p>You are old enough to drive!</p>";
} elseif ($age > 16) {
echo "<p>You can drive!</p>";
} else {
echo "<p>You are not old enough to drive...</p>";
}
function month($nom, $padezh)
{
$monat = array('Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь');
$monat_rod = array('Января', 'Февраля', 'Марта', 'Апреля', 'Мая', 'Июня', 'Июля', 'Августа', 'Сентября', 'Октября', 'Ноября', 'Дека
function pack_and_download($file){
$filename = $file->getClientOriginalName();
$tmpFile = tempnam(sys_get_temp_dir(), 'data');
$tmpFileHandle = fopen($tmpFile, 'w');
fwrite($tmpFileHandle, $file->get());
fclose($tmpFileHandle);
$outputFile = tempnam(sys_get_temp_dir(), 'data') . ".gz";
$fp = gzopen($outputFile, 'wb9');
gzwrite($fp, file_get_contents($tmpFile));
gzclose($fp);
$response = new Response(file_get_contents($outputFile), 200);
$response->header('Content-Type', 'application/x-gzip');
$response->header('Content-Disposition', 'attachment; filename=' . $filename . '.gz');
return $response;
}
function last5($str) {
if (strlen($str) > 5) {
return substr($str, -5);
} else {
return $str;
}
}
last5('123456')
/\blanguagesList\s+current\b/
function hide_ip($ip){
$arr = explode('.', $ip);
$arr[2] = $arr[3] = 'X';
return implode('.', $arr);
}
hide_ip('202.202.202.202')
// Button
<button>Click Me!</button>
// Javascript
var button = document.querySelector("button");
button.addEventListener("click", function(e)
{
button.style.background = "blue";
});
function fill(obj, value) {
for (var i = 0; i < obj.length; i++)
obj[i] = value;
}
var a = [1,2,3]
fill(a, 1)
function get_months($number, $case, $sex) {
$numbers = explode('-', $number);
$result = array();
foreach ($numbers as $number) {
$result[] = get_month($number, $case, $sex);
}
return implode('-', $result);
}
function get_month($number, $case, $sex) {
$months = array(
1 => array('январь', 'января', 'январе'),
2 => array('февраль', 'февраля', 'феврале'),
3 => array('март', 'марта', 'марте'),
4 => array('апрель', 'апреля', 'апреле'),
5 => array('май', 'мая',
/[a-z]/
function replacer($str) {
$str = str_replace('-', '/', $str);
return $str;
}
function getUrl(key) {
let url = window.location.href
let urlList = url.split('?')[1].split('&')
for (let i in urlList) {
if (urlList[i].split('=')[0] === key) {
return urlList[i].split('=')[1]
}
}
return undefined
}
/\d{10,}/
team="\d+"
function f(x) {
return Number(Math.round(x+'e5')+'e-5');
}
function stream_gzencode($data) {
$size = strlen($data);
$crc = crc32($data);
$data = gzencode($data, 9);
$data = substr($data, 0, -4);
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $data;
echo pack('V', $crc);
echo pack('V', $size);
}
stream_gzencode(file_get_contents('http://example.com/'));
function toNumber(a) {
return parseFloat(a)
}
toNumber('1.2')
/[^\d]+/
function percent($value, $percent) {
$res = $value * $percent / 100;
return $res;
}
function getMonthName($monthNumber) {
$months = array(
1 => 'января', 2 => 'февраля', 3 => 'марта',
4 => 'апреля', 5 => 'мая', 6 => 'июня',
7 => 'июля', 8 => 'августа', 9 => 'сентября',
10 => 'октября', 11 => 'ноября', 12 => 'декабря'
);
return $monthNumber > 0 && $monthNumber < 13
? $months[$monthNumber]
: null;
}
/<\s*\/\s*t\s*>/
var timeout = function(counter) {
if (counter > 0) {
setTimeout(function() {
console.log(counter);
timeout(counter - 1);
}, 1000);
}
};
timeout(5);
var obj = {name: "John", age: 30, city: "New York"};
var myJSON = JSON.stringify(obj);
localStorage.setItem("testJSON", myJSON);
/<div\s*class=".*"\s*>/g
function replace(str, a, b) {
return str.replace(a, b);
}
replace("Hello world", "world", "seattle")
preg_match('/(<\/p>)/', $text)
function replaceLast($str, $from, $to) {
$pos = strrpos($str, $from);
if($pos !== false) {
$str = substr_replace($str, $to, $pos, strlen($from));
}
return $str;
}
function cut_string($s, $length) {
return substr($s, 0, $length);
}
echo cut_string("Hello World", 5);
function percent($a, $b){
return round(($a - $b) / $b * 100)
}
percent(100, 120)
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function add(a, b){
return ((a * 100000 + b * 100000) / 100000);
}
add(1.1111, 2.2222)
$(document).ready(function() {
$(window).scroll(function() {
$('.header').hide();
});
});
function fiveDigits(x) {
return parseFloat(x).toFixed(5);
}
fiveDigits(3.14159)
function get_tld($domain){
$domain_tld = null;
if(preg_match("/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i", $domain, $matches)){
$domain_tld = $matches['domain'];
}
return $domain_tld;
}
function generate_hash(str) {
var hash = 0, i, chr;
if (str.length === 0) return hash;
for (i = 0; i < str.length; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}
function get_last_five($string) {
return substr($string, -5);
}
/\w+\d+@\w+\.\w+/
function pack_and_download($file){
// pack the file
$gzfile = gzopen($file.".gz", "w9");
gzwrite($gzfile, file_get_contents($file));
gzclose($gzfile);
// download the file
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'.gz"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file.".gz"));
ob_clean();
flush();
readfile($file.".gz");
unlink($file.".gz");
exit;
}
/^[a-zA-Z0-9]{6,}$/
function get_first_five_symbols($string) {
return substr($string, 0, 5);
}
get_first_five_symbols('Hello'); // 'Hello'
get_first_five_symbols('Hello World'); // 'Hello'
get_first_five_symbols('Hello World!'); // 'Hello'
function unique(arr) {
return Array.from(new Set(arr));
}
unique([1, 2, 3, 4, 4]);
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "John Doe\n";
fwrite($myfile, $txt);
$txt = "Jane Doe\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
function stream_gz_encode($data, $compressed_size) {
$size = strlen($data);
$crc = crc32($data);
$data = gzencode($data, 9);
$data = substr_replace($data, pack('V', $crc), -8, 4);
$data = substr_replace($data, pack('V', $size), -4, 4);
$compressed_size += strlen($data);
printf('%s%s%s%s%s',
substr($data, 0, 4),
pack('V', $crc),
pack('V', $size),
pack('v', strlen($data) - 12),
substr($data, -(strlen($data) - 12))
);
}
<?php
function pack_to_gz($file) {
$zip = new ZipArchive;
$filename = $file . ".gz";
//$zip->open($filename, ZipArchive::CREATE);
//$zip->addFile($file);
//$zip->close();
//header('Content-Type: application/zip');
//header('Content-disposition: attachment; filename=' . $filename);
//header('Content-Length: ' . filesize($filename));
//readfile($filename);
//return $filename;
}
pack_to_gz('/Users/danghong/Desktop/d-hong.com.zip');
?>
function precentOf($i, $p) {
return $i / 100 * $p;
}
precentOf(1000, 15) // 150
function timeoutCounter(seconds, callback) {
setTimeout(function() {
let time = seconds--
callback(time)
return timeoutCounter(seconds, callback)
}, 1000)
}
timeoutCounter(10, function(count) {
console.log(count)
})
function copyText(text){
return text
}
function hash($name)
{
return md5($name);
}
hash('Evan'); # '9cdfb43921eb76fbebe4895021cd24fb'
function copyText(text) {
// create textarea
var textarea = document.createElement("textarea");
// set textarea value
textarea.value = text;
// make textarea read only
textarea.readOnly = true;
// append to document body
document.body.appendChild(textarea);
// select text
textarea.select();
// copy text
document.execCommand("copy");
// remove textarea
document.body.removeChild(textarea);
}
/languagesList current/
$.ajax({
url: "",
type: "POST",
data: {
name: "page",
url: "page URL",
content: "page content"
}
});
Math.round(num * 100000) / 100000
function random_float($min, $max) {
return $min + mt_rand() / mt_getrandmax() * ($max - $min);
}
\D
php
/1\d{2}|[2-9]\d{3}|10000/
function time_online(start, end) {
return end - start
}
time_online(15, 12)
function math($x, $y) {
$result = $x - $y;
echo $result;
}
math(8, 4);
function summ($a, $b, $percent) {
return $a + $b + (($a + $b) / 100 * $percent);
}
$sum = summ(500, 600, 20);
function shuffle($str) {
$arr = explode(' ', $str);
shuffle($arr);
return implode(' ', $arr);
}
function randFloat($min, $max) {
return ($min + lcg_value() * (abs($max - $min)));
}
randFloat(1, 10);
$months = array(
'январь',
'февраль',
'март',
'апрель',
'май',
'июнь',
'июль',
'август',
'сентябрь',
'октябрь',
'ноябрь',
'декабрь'
);
function rusMonth($month) {
global $months;
$month = $months[$month - 1];
$last_letter = substr($month, -1); // последняя буква
switch ($last_letter) {
case "ь":
$month .= "я";
break;
case "й":
$month .= "я";
break;
default:
$
<\/p>
function getValue(id){
var value = document.getElementById(id).value;
return value;
}
/(?!javascript)(\w+[^\b])+(\.html)/g
function add(array, item) {
array.push(item);
}
let myArray = [];
add(myArray, 'Hello');
function toFixed(num, fixed) {
var re = new RegExp('^-?\\d+(?:.\\d{0,' + (fixed || -1) + '})?');
return num.toString().match(re)[0];
}
function hash_it($text)
{
return md5($text);
}
hash_it("test");
function percent_of($number, $percent)
{
return $number * $percent / 100;
}
/^[1-9]\d{2,3}$/
function add($a, $b) {
return $a + $b;
}
add(1, 2);
$arr = [
'a'=>1,
'b'=>2,
'c'=>3
];
echo array_search(max($arr), $arr)
function postData(url) {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.onload = function() {
var data = xhr.responseText;
resolve(data);
};
xhr.onerror = function() {
reject(Error(xhr.statusText));
};
xhr.send();
});
}
postData("/data.json")
.then(data => {
console.log(data);
})
.catch(error => {
console.error(error);
});
function push(&$array, $value) {
$array[] = $value;
}
<?php
$random = mt_rand(0, 100) / 100;
return $random;
?>
def domain_age(domain):
from datetime import datetime
from tld import get_tld
domain = get_tld(domain, as_object=True)
return int((datetime.now() - domain.creation_date).days)
domain_age('https://www.google.com')
let add = (a, b) => {
return (a + b).toFixed(5)
}
function dateNow() {
return new Date()
}
dateNow()
function uuid(){
return sprint_f("%04x%04x-%04x-%04x-%04x-%04x%04x%04x", mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
function add(a, b) {
return a + b
}
add(1, 2)
function uuid()
{
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
def percents(number, proc):
return number * proc / 100
percents(100, 10)
function month($m)
{
if ($m==1) return 'Январь';
if ($m==2) return 'Февраль';
if ($m==3) return 'Март';
if ($m==4) return 'Апрель';
if ($m==5) return 'Май';
if ($m==6) return 'Июнь';
if ($m==7) return 'Июль';
if ($m==8) return 'Август';
if ($m==9) return 'Сентябрь';
if ($m==10) return 'Октябрь';
if ($m==11) return 'Ноябрь';
if ($m==12) return 'Декабрь';
}
function max(arr) {
var max = arr[0][0];
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
if (max < arr[i][j]) {
max = arr[i][j];
}
}
}
return max;
}
function stream_gzencode($input) {
$size = strlen($input);
$crc = crc32($input);
$gzdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00".substr(gzcompress($input, 9), 0, -4).pack('V', $crc).pack('V', $size);
header('Content-Encoding: gzip');
header('Content-Length: '.strlen($gzdata));
header('Content-type: application/x-gzip');
die($gzdata);
}
function trim($str, $len){
return substr($str, 0, $len);
}
trim('hello world', 5)
function max(a, b) {
if (a > b) {
return a
} else {
return b
}
}
function findVolume(a, b) {
return a * b;
}
/[^\d]/g
function generatePhrase($word)
{
return "Hello " . $word;
}
echo generatePhrase("World");
/[^\s!@#$%^&*()+=`~<>?:"{}\[\]\\/|]*/
/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/
function gzarchive($data, $filename) {
$gzdata = gzencode($data, 9);
file_put_contents($filename, $gzdata);
}
function cut_string_at_end($string, $cut) {
return substr_replace($string, '', -$cut);
}
cut_string_at_end('hello', 0)
function getMonthName($monthNum) {
return date('F', mktime(0,0,0,$monthNum,1,2011));
}
getMonthName(5) # May
$months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
function fullNameMonth($position) {
global $months;
echo $months[$position - 1];
}
fullNameMonth(1);
var add = function(a, b) {
return a + b
}
add(1, 2)
function max(matrix) {
var max = matrix[0][0];
for (var i = 0; i < matrix.length; i++) {
for (var j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] > max) {
max = matrix[i][j];
}
}
}
return max;
}
function add(a, b) {
return a + b
}
add(1, 2)
/<t*\/>/g
function gzencode_stream($input, $level = -1, $mode = FORCE_GZIP) {
$mode = in_array($mode, array(FORCE_GZIP, FORCE_DEFLATE, FORCE_DEFLATE), TRUE) ? $mode : FORCE_GZIP;
$level = ($level = (int)$level) < 0 || $level > 9 ? -1 : $level;
if (function_exists('gzdeflate')) {
$mode = ($mode == FORCE_GZIP) ? FORCE_DEFLATE : $mode;
} elseif (function_exists('gzencode') && $mode == FORCE_GZIP) {
return gzencode($input, $level);
} elseif (function_exists('gzcompress') && $mode == FORCE_DEFLATE) {
return gzcompress($input, $level);
}
$flags = ($mode == FORCE_DEFLATE) ? FORCE_DEFLATE : 0
function svgToJpg($svgFile)
{
$svg = file_get_contents($svgFile);
$png = new Imagick();
$png->setBackgroundColor(new ImagickPixel('transparent'));
$png->setFormat("jpeg");
$png->readImageBlob($svg);
$png->setImageFormat("jpeg");
$png->writeImage('test.jpg');
$png->clear();
$png->destroy();
}
function dateToText(input) {
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var date = input.toString();
var year = date.slice(0, 4);
var month = date.slice(4, 6);
var day = date.slice(6, 8);
return months[month - 1] + " " + day + ", " + year;
}
dateToText(20180822)
$a = array_merge_recursive($a1, $a2);
/languagesList current/
function toFixed(n) {
return Number(n.toFixed(5))
}
toFixed(1.2345) // 1.23450
function getMonthName($month)
{
if($month == 1) return "Jan";
if($month == 2) return "Feb";
if($month == 3) return "Mar";
if($month == 4) return "Apr";
if($month == 5) return "May";
if($month == 6) return "Jun";
if($month == 7) return "Jul";
if($month == 8) return "Aug";
if($month == 9) return "Sep";
if($month == 10) return "Oct";
if($month == 11) return "Nov";
if($month == 12) return "Dec";
}
echo getMonthName(1); // Jan
function copyText() {
var copyText = document.getElementById("copyText");
copyText.select();
document.execCommand("copy");
alert("Copied your text: " + copyText.value);
}
function timeOnline(user) {
return Date.now() - user.signed_up_at;
}
function setTimeZone(a) {
return a+0
}
setTimeZone(1)
function add_percent_of_sum($sum, $percent) {
return $sum * (1 + $percent);
}
//
// usage: curl http://localhost/gzencode.php/foo/bar
//
// flush gzip buffer to stream
$gzip = function($data)
{
$flush = function()
{
global $gzip;
$data = gzgetc();
if ($data === false) {
return false;
}
echo $data;
$gzip->flush();
return true;
};
gzwrite($data);
return $flush();
};
// setup gzip
$gzip = gzopen('php://output', 'wb9');
// flush some data
$gzip('foo');
// close stream
gzclose($gzip);
function getDate() {
return new Date().toISOString().slice(0, 19).replace('T', ' ');
}
Time.zone = "UTC"
def get_tld(domain):
return domain.split(".")[-1]
get_tld("code.tutsplus.com")
function gzencode_and_save($archive_name, $data) {
$file_path = $archive_name . '.gz';
$fp = gzopen($file_path, 'w9');
gzwrite($fp, $data);
gzclose($fp);
return $file_path;
}
setTimeout(function(){console.log('hi')}, 1000);
function toString(num)
{
return num.toString();
}
function archive($dir) {
$archive = $dir.'.tar.gz';
$archive = new PharData($archive);
$archive->buildFromDirectory($dir);
return $dir.'.tar.gz';
}
function copyToBuffer(a, b) {
let buffer = [];
for (let i = a; i <= b; i++) {
buffer.push(i);
}
return buffer;
}
copyToBuffer(1, 10)
function html($tag, $content){
return "<$tag>$content</$tag>";
}
html('h1', 'Hello world');
window.setTimeout(function() {
//Put All Your Code Here it Will Execute After some delay Time
if (document.getElementById('time_up') != null)
document.getElementById('time_up').click();
}, 10000);
/^[a-zA-Z0-9_\.]+@[a-zA-Z]+\.[a-zA-Z]{2,4}$/
function randomNumber() {
return rand() / getrandmax();
}
randomNumber()
function find(id) {
return document.getElementById(id);
}
find('id')
function preg_match($pattern, $subject, $matches) {
if (preg_match($pattern, $subject, $matches)) {
return $matches;
}
return [];
}
function gzencode($data, $level = -1, $encoding_mode = FORCE_GZIP) {
// ...
}
php
/<\s*p[^>]*>(.*?)<\s*\/\s*p>/
function ajax(url, type){
var xhr = new XMLHttpRequest();
xhr.open(type || 'GET', url, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.send();
}
ajax('/posts')
ajax('/posts', 'POST')
function float_to_string($float) {
$float = strval($float);
$float = explode(".", $float);
if (count($float) == 1) {
$float[1] = "00";
}
if (count($float) > 1) {
$float[1] = substr($float[1], 0, 2);
}
$float = $float[0] . "." . $float[1];
return $float;
}
float_to_string(12.34567) // 12.34
/^[a-zA-Z][a-zA-Z0-9]{3,16}$/
function generate_sitemap()
{
//generate sitemap
$sitemap = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />');
//add some urls
$url = $sitemap->addChild('url');
$url->addChild('loc', 'http://www.url.com');
$url->addChild('lastmod', date('Y-m-d'));
$url->addChild('changefreq', 'daily');
$url->addChild('priority', '1.0');
//save to disk
$fp = fopen(__DIR__.'/sitemap.xml', 'wb');
fwrite($fp, $sitemap->asXML());
fclose($fp);
//return sitemap as a string
return $sitemap->asXML();
}
``
function percent($a, $b) {
return $a / 100 * $b;
}
percent(50, 100);
<?php
function reverse_percent($number, $percent)
{
$result = $number / (100 + $percent) * 100;
return $result;
}
?>
$arr = [1, 2, 3, 4, 5];
array_slice($arr, 1, 3)
function get_status_code($url) {
$headers = get_headers($url);
return substr($headers[0], 9, 3);
}
get_status_code('http://google.com')
function getMax($array1, $array2)
{
$maxArray = [];
$maxArray = $array1;
if (count($array1) < count($array2))
$maxArray = $array2;
return $maxArray;
}
def is_even(number):
return number % 2 == 0
foreach (glob("*.txt") as $filename) {
unlink($filename);
}
function addOne(num) {
return num + 1
}
function ($statistic, $site) {
return [
'name': $site,
'data': $.map($index, function ($i, $v) {
return $v;
})
]
}
/\d+/
function get_month_name($month_number, $case = 'nominative') {
$months = array(
'nominative' => array(1 => 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'),
'genitive' => array(1 => 'Января', 'Февраля', 'Марта', 'Апреля', 'Мая', 'Июня', 'Июля', 'Августа', 'Сентября', '
<?php
$assoc = ['a' => 'b', 'c' => 'd'];
// ???
$str = "Hello world";
$str_new = substr($str, 5);
echo $str_new;
// output: world
var list1 = [1, 2, 3];
var list2 = [4, 5, 6];
function concat(list1, list2) {
return list1.concat(list2);
}
console.log(concat(list1, list2));
/криптовалютный\s+счет/
function packToGz($archive_name, $data) {
$fp = gzopen($archive_name, "w9");
gzwrite($fp, $data);
gzclose($fp);
return $archive_name;
}
function increaseNumber($number, $percent) {
return $number * ($percent / 100 + 1);
}
<?php
function get_status_code($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
$status = explode(" ", $data);
return $status[1];
}
?>
$rand = rand(0, 100);
const validateLogin = login =>
typeof login === 'string' && login.length >= 4
srand(time());
rand(0, 99);
function fullname_month_ru($month_number) {
$month_number = intval($month_number);
$month_number = ($month_number == 0 ) ? date('n') : $month_number;
$month_name = array("", "Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь");
return $month_name[$month_number];
}
const add = (a, b) => {
return a + b;
};
add(1, 2);
Math.max.apply(Math, [1, 2, 3, 4, 5].map(function(e){
return e * e;
}));
$path = "/path/to/file";
$gz = gzencode(file_get_contents($path), 9);
<form action="">
<label for="">
Введите строку:
<input type="text" name="str" value="">
</label>
<button>Отправить</button>
</form>
<script>
let input = document.querySelector('input');
let form = document.querySelector('form');
form.addEventListener('submit', (e) => {
let value = input.value;
let patt = /\w+/;
if (patt.test(value)) {
alert('Все ок');
} else {
e.preventDefault(); // останавливаем отправку формы
input.style.border = '2px solid red';
alert('Введите строку');
}
function shuffle_string($string) {
$len = strlen($string);
for ($i = 0; $i < $len; $i++) {
$pos = rand(0, $len - 1);
$temp = $string[$i];
$string[$i] = $string[$pos];
$string[$pos] = $temp;
}
return $string;
}
<?php
function shuffle($str) {
$shuffled = "";
$l = strlen($str);
for ($i = 0; $i < $l; $i++) {
$ch = substr($str, $i, 1);
if ($ch == ' ')
continue;
$shuffled .= $ch;
}
$shuffled = str_shuffle($shuffled);
$i = 0;
$shuffled_str = '';
for ($j = 0; $j < $l; $j++) {
$ch = substr($str, $j, 1);
if ($ch == ' ')
$shuffled_str .= ' ';
else
$shuffled_str .= $shuffled[$i++];
}
return $shuffled_str;
}
echo shuffle("This is a test");
?>
function max(arr) {
let max = -Infinity;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (max < arr[i][j]) {
max = arr[i][j];
}
}
}
return max;
}
/^[a-zA-Z0-9- ]*$/
function get_percent($number, $percent) {
return $number * $percent / 100;
}
.container {
width: calc(100% - 20px);
height: calc(100% - 20px);
}
<?php
function get_status($code) {
switch ($code) {
case 400:
return "Bad Request";
case 403:
return "Forbidden";
case 404:
return "Not Found";
case 500:
return "Internal Server Error";
case 503:
return "Service Unavailable";
}
}
get_status(403);
?>
function month($month) {
$months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
return $months[$month];
}
month(1);
$arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
$last = array_slice($arr, -1000);
function splitStringBy5Char($string) {
$result = [];
$currentString = '';
for ($i = 0; $i < strlen($string); $i++) {
$currentString .= $string[$i];
if (strlen($currentString) >= 5) {
$result[] = $currentString;
$currentString = '';
}
}
if ($currentString) $result[] = $currentString;
return $result;
}
print_r(splitStringBy5Char('1234567890'));
function hash($password) {
return $password + 7;
}
echo hash('123'); // 130
/[\d\:\w]+/
function get_tdl($domain) {
$url = "https://www.whoisxmlapi.com/whoisserver/WhoisService?apiKey=at_n1RvT8WtFZzsE1fKiQ2k3qleoOiE3&domainName=" . $domain . "&outputFormat=json";
$data = file_get_contents($url);
return $data;
}
const add = (a, b) => a + b
[^0-9]
function base64_to_jpg($base64_string, $output_file)
{
$ifp = fopen($output_file, "wb");
fwrite($ifp, base64_decode($base64_string));
fclose($ifp);
return $output_file;
}
Math.max(1, 2, 3)
function percent($sum, $percents) {
return ($sum / 100) * $percents;
}
function getHtml() {
return '<h1>Hello world!</h1>';
}
echo getHtml();
var tenSeconds = 10;
var display = document.querySelector('#time');
startTimer(tenSeconds, display);
function preg_split_text_by_regex($text, $regex)
{
$result = preg_split($regex, $text);
return [
'before' => $result[0],
'after' => $result[1]
];
}
preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) : int
require_once('/path/to/gzencode.php');
function download_send_headers($filename) {
// disable caching
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
// force download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposition / encoding on response body
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
download_send_headers("data_export_" . date("Y-m-d") . ".csv");
echo gzencode($data);
die();
def sum_of_sum(sum, percent):
sum_percent = sum * percent / 100
return sum + sum_percent
sum_of_sum(100, 10)
function get_month($month) {
$nominative = array("Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь");
$accusative = array("Января", "Февраля", "Марта", "Апреля", "Мая", "Июня", "Июля", "Августа", "Сентября", "Октября", "Ноября", "Дека
.container {
width: 100px;
height: 100px;
border: 1px solid #000000;
}
function personal_hash($name, $age, $gender) {
return ($name + $age + $gender) / 2;
}
/\D/
var map = function(f, l) {
var ret = [];
for (var i = 0; i < l.length; i++) {
ret.push(f(l[i]));
}
return ret;
}
// example
map(function(x){return x*x;}, [1, 2, 3, 4, 5])
function replace(string, old, new) {
return string.replace(old, new);
}
function getCurrentMonth() {
return new Date().getMonth(); // 0 - Jan, 1 - Feb, ...
}
function save($filename, $contents) {
$file = gzencode($contents);
file_put_contents($filename, $file);
}
save("filename.gz", "ciao");
function add(a, b) {
return a + b;
}
console.log(add(1, 2))
function hello($name, $colour) {
return "<p>Hello, {$name}, I like {$colour}</p>";
}
echo hello('Frankie', 'red');
function pack_to_gz($content){
$gz = gzencode($content);
return $gz;
}
function keys(array) {
var keys = [];
for (var i in array) {
keys.push(i);
}
return keys;
}
function get_name_day(date){
var d = date.getDate()
var m = date.getMonth()
var y = date.getFullYear()
var name_day = name_day_data[d][m]
return name_day
}
const d = new Date()
get_name_day(d)
function get_xml_file($name) {
$url = 'http://' . $name . '.com/' . $name . '.xml.gz';
$content = file_get_contents($url);
$file = download_file($content, $name . '.xml.gz');
return $file;
}
function gz_compress($input) {
# code here
}
function get_tdl($url) {
// strip http:// and www.
$tld = preg_replace("/^(https?:\/\/)?(www\.)?/i", "", $url);
// strip everything else
$tld = preg_replace("/\/.*$/", "", $tld);
// extract and return tld
$tld = substr($tld, strrpos($tld, ".") + 1);
return $tld;
}
fuction month(num):
return num
month(0)
def max(a, b):
return a if a > b else b
max(1, 2)
/[1-9]\d{2,3}/
function get_http_response_code($theURL) {
$headers = get_headers($theURL);
return substr($headers[0], 9, 3);
}
get_http_response_code('http://www.example.com');
function change01($n):
$arr01 = str_split($n);
$arr1 = array();
foreach($arr01 as $num){
if($num==0){
$arr1[] = 1;
}else{
$arr1[] = 0;
}
}
$r = implode("", $arr1);
return $r;
change01("0100")
[а-яёА-ЯЁ]
<?php
use GuzzleHttp\Client;
$client = new Client();
$url = 'https://www.whoisxmlapi.com/whoisserver/DNSService?apiKey=at_O2QvL3qjzFwfI8O6W0YvY3hc9StL&domainName=google.com&type=_all';
$response = $client->request('GET', $url, [
'verify' => false
]);
$body = $response->getBody();
echo $body;
?>
def month_case(month):
if month = 1:
return 'января'
elif month = 2:
return 'февраля'
elif month = 3:
return 'марта'
elif month = 4:
return 'апреля'
elif month = 5:
return 'мая'
elif month = 6:
return 'июня'
elif month = 7:
return 'июля'
elif month = 8:
return 'августа'
elif month = 9:
return 'сентября'
elif month = 10:
return 'октября'
elif month = 11:
return 'ноября'
elif month = 12:
return 'декабря'
else:
return
var now = new Date();
now.getTime();
async add(a, b) {
return a + b;
}
await add(1, 2);
function get_month(num):
month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
return month[num-1]
get_month(1)
function handleEvent() {
if (Math.random() < 0.5) {
console.log('Hello World');
}
}
setTimeout(handleEvent, 10000);
function month_ru($month) {
$month = $month - 1;
$months = ['январь', 'февраль', 'март', 'апрель', 'май', 'июнь', 'июль', 'август', 'сентябрь', 'октябрь', 'ноябрь', 'декабрь'];
return $months[$month];
}
month_ru(4);
.
{
color: red;
}
function findMax($arr) {
$max = 0;
for ($i = 0; $i < count($arr); $i++) {
if ($arr[$i] > $max) {
$max = $arr[$i];
}
}
return $max;
}
$arr = [1, 2, 5, 8, 9];
echo findMax($arr); // 9
function getLastItem($array) {
return $array[count($array) - 1];
}
getLastItem([1, 2, 3]); // 3
function max(a)
{
var max = -Infinity;
for (var i = 0; i < a.length; i++)
if (!Array.isArray(a[i]))
{
if (a[i] > max)
max = a[i];
}
else
{
var t = max(a[i]);
if (t > max)
max = t;
}
return max;
}
max([[1, 2], [3]])
<?php
function gz_encode_save($path,$file){
$gz = gzencode(file_get_contents($file), 9);
$fp = fopen($path, "w");
fwrite($fp, $gz);
fclose($fp);
}
gz_encode_save('yourfile.gz','yourfile.txt');
?>
function number_format(number, decimals, dec_point, thousands_sep) {
// discuss at: http://phpjs.org/functions/number_format/
// original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// improved by: davook
// improved by: Brett Zamir (http://brett-zamir.me)
// improved by: Brett Zamir (http://brett-zamir.me)
// improved by: Theriault
// improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// bugfixed by: Michael White (http://getsprink.com)
// bugfixed by: Benjamin Lupton
// bugfixed by: Allan Jensen (http://www.winternet.no)
// bugfixed by: Howard Yeend
// bugfixed by: Diogo Resende
//
$filename = "sample.txt"; // the name of the .txt file which contains the base64 encoded image
$handle = fopen($filename, "r"); // file handler
$contents = fread($handle, filesize($filename)); // read into $contents
fclose($handle); // close file handler
$im = imagecreatefromstring(base64_decode($contents)); // imagecreatefromstring creates an image from the string you feed it
header('Content-Type: image/jpg'); // header is a function to send an HTTP header, in this case we set the Content-Type to image/jpg
imagejpeg($im); // imagejpeg is a function to create a JPG file from the image created by imagecreatefromstring
imagedestroy($im); // imagedestroy is a function to destroy the image, and reclaim the memory used by it
function cutString($string, $count) {
return substr($string, 0, strlen($string) - $count);
}
cutString('Привет, мир!', 4)
function percent(sum, percent) {
return sum + sum * percent / 100
}
percent: 100, 10
// => 110
function binarize($a) {
return ($a == 0) ? 0 : 1;
}
binarize(0);
binarize(1);
binarize(2);
binarize(3);
binarize(4);
$uuid = strtoupper(md5(uniqid(rand(), true)));
<?php
function persent($value, $persent, $round = 2) {
$result = $value * $persent / 100;
return round($result, $round);
}
echo persent(100, 10);
<?php
header_remove("X-Powered-By");
function time(hrs, mins) {
let totalMins = hrs * 60 + mins;
let totalDays = Math.floor(totalMins / (24*60));
let remainingMins = totalMins % (24*60);
let remainingHrs = Math.floor(remainingMins / 60);
return `${totalDays} day(s) and ${remainingHrs} hour(s)`;
}
time(10, 0)
let arr = ["a", "b"];
let newArr = arr.map(function (el) {
return "prefix_" + el;
});
function fullname($month) {
return date("F", strtotime("2001-$month-01"));
}
fullname(8);
function addAsync(a, b, callback) {
setTimeout(() => {
callback(a + b);
}, 1000)
}
addAsync(1, 2, (result) => {
console.log(result);
});
/[A-Z]\w{3,10}/
function max(array){
var max = array[0][0]
for(var i = 0; i < array.length; i++){
for(var j = 0; j < array[i].length; j++){
if(array[i][j] >= max){
max = array[i][j]
}
}
}
return max
}
strlower = (str) => {
return str.toLowerCase();
};
function getUrl(url, callback) {
//code
callback(err, res)
}
function do_every_half_hour() {
$time = time();
$minutes = date("i", $time);
$minutes_to_wait = (30 - $minutes % 30) * 60;
sleep($minutes_to_wait);
do_every_half_hour();
}
/[1-9]\d{2,4}/
[\w:]+
header('Content-Type: image/jpeg');
$imageData = base64_decode($_GET['data']);
echo $imageData;
function foo(){
return "bar";
}
def max(a, b):
return max(a, b)
max(1, 2)
/[1-9][0-9]{2,4}/
$months = [
1 => 'январь',
2 => 'февраль',
// ...
12 => 'декабрь'
];
function trim_last($str, $n) {
return substr($str, 0, -$n);
}
trim_last('abcdefghj', 2)
function click() {
document.getElementsByName('btnK')[0].click()
}
var arr = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
function max(arr) {
var max = arr[0][0];
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].length; j++) {
if (arr[i][j] > max) {
max = arr[i][j];
}
}
}
return max;
}
max(arr);
function get_tld($url) {
$parts = parse_url($url);
return $parts['host'];
}
(\b[13][a-zA-Z0-9]{26,33}\b)
/^[13][a-zA-Z0-9]{33,34}$/
$string = 'Hello world';
$string = substr_replace($string, '!!', -1);
echo $string;
/<a.*>/
/<a.*?>/
function max(arr) {
return Math.max(...arr)
}
max([1, 2, 3])
function get_pi() {
return 3.14;
}
get_pi()
$a = 12500;
$b = 100;
echo $a * $b / 100;
let arr = [1, 2, 3]
let max = arr[0]
for (let i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i]
}
}
function max_array($arr){
// とりあえず配列の最初の要素を一番大きい値とする
$max_number = $arr[0];
foreach($arr as $a){
//どうしたらいいかわからない・・・・
if($max_number < $a){
$max_number = $a;
}
}
return $max_number;
}
echo max_array(array(1,2,3,4,5,6,7,8,9,10));
/^\w{3,16}$/
def pack_to_gz(file):
f_in = open(file, 'rb')
f_out = gzip.open('file.gz', 'wb')
f_out.writelines(f_in)
f_out.close()
f_in.close()
return f_out
preg_match('/languagesList current/', $useragent);
function getXmlGzArchive()
{
$xml = simplexml_load_file('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml');
$xml = $xml->xpath('//Cube[@currency][@rate]');
$archive = [];
foreach ($xml as $node) {
$archive[(string)$node['time']][(string)$node['currency']] = (float)$node['rate'];
}
return $archive;
}
function gz_archive($file_path, $output_file, $level = 5) {
$buffer = '';
$gz = gzopen($output_file, 'wb' . $level);
$file = fopen($file_path, 'rb');
while (!feof($file)) {
$buffer = fread($file, 10240);
gzwrite($gz, $buffer);
}
gzclose($gz);
fclose($file);
}
/languagesList current/
function hide_ip($ip) {
$array = explode('.', $ip);
$array[2] = 'XXX';
$array[3] = 'XXX';
return implode('.', $array);
}
/languagesList current/
function percent_sum($sum, $percent) {
$sum += $sum * $percent / 100;
return $sum;
}
echo percent_sum(1000, 10); // 1100
function get_xml_archive() {
return bzcompress(xml_encode($data));
}
function isMatchAtoZ(inputStr){
return /[a-z]/.test(inputStr);
}
isMatchAtoZ('test');
function findMax(arr) {
if (arr.length === 0) return 0;
var max = arr[0];
for (var i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
return max;
}
findMax([1, 2, 3]);
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
];
console.log(months);
$ar1 = [ 1, 2, 3];
$ar2 = ["a", "b", "c"];
$ar3 = array_merge($ar1, $ar2);
function what_percent(a, b) {
return (b - a) / a * 100
}
what_percent(12, 15)
function getMonthNumber(month){
month = month.toLowerCase();
let months = {
"march": 3,
"april": 4,
"may": 5,
"june": 6,
"july": 7,
"august": 8,
"september": 9,
"october": 10,
"november": 11,
"december": 12,
"january": 1,
"february": 2
}
return months[month];
}
getMonthNumber("january")
"hello world".toUpperCase()
/<div.*?>/
function get_TDL_with_domain(domain):
tdl_list = []
#get tdl list
return tdl_list
Generate
More than just a code generator. A tool that helps you with a wide range of tasks. All in one place.
Function from Description
Text Description to SQL Command
Translate Languages
Generate HTML from Description
Code to Explanation
Fix invalid Code
Get Test for Code
Class from Description
Regex from Description
Regex to Explanation
Git Command from Description
Linux Command
Function from Docstring
Add typing to code
Get Language from Code
Time complexity
CSS from Description
Meta Tags from Description
− sponsored −