Skip to content

Instantly share code, notes, and snippets.

View victory-sokolov's full-sized avatar
🎯
Focusing

Viktor Sokolov victory-sokolov

🎯
Focusing
View GitHub Profile
@victory-sokolov
victory-sokolov / JavaScript Tips
Last active December 11, 2022 21:10
JavaScript Cheat Sheet
//Reverse String
function reverse(s){
return s.split("").reverse().join("");
}
/* Method 1 */
.a {
width: 200px;
height: 200px;
background-color: black;
color: #fff;
display:flex;
justify-content:center;
flex-direction:column;
using namespace System::Runtime::InteropServices;
char * and_SysStringToChar(System::String^ string)
{
return (char*)(void*)Marshal::StringToHGlobalAnsi(string);
}
String^ s = textBox1->Text;
char* str = and_SysStringToChar(s);
@victory-sokolov
victory-sokolov / dataToChar.c
Last active November 23, 2023 14:44
Convert Date to char array
char buff[100];
if(ptm->tm_mon < 10){
if(ptm->tm_mday < 10){
sprintf(buff,"%u-0%u-0%u",(unsigned)ptm->tm_year,(unsigned)ptm->tm_mon,(unsigned)ptm->tm_mday);
}else{
sprintf(buff,"%u-0%u%u",(unsigned)ptm->tm_year,(unsigned)ptm->tm_mon,(unsigned)ptm->tm_mday);
}
}else{
if(ptm->tm_mday < 10){
sprintf(buff,"%u-%u-0%u",(unsigned)ptm->tm_year,(unsigned)ptm->tm_mon,(unsigned)ptm->tm_mday);
@victory-sokolov
victory-sokolov / scroll-indicator.html
Last active November 23, 2023 14:43
Scroll indicator design
<!DOCTYPE html>
<html>
<head><head>
<body>
<header class="scroller"></header>
<main>
content must be longer than 100vh
</main>
@victory-sokolov
victory-sokolov / shorten_url.py
Last active November 23, 2023 14:42
Shorten Url with tinyurl
from urllib.request import urlopen
url = "https://facebook.com"
data = urlopen("http://tinyurl.com/api-create.php?url="+url)
shorten_url = data.readlines()[0].decode()
print(shorten_url)
@victory-sokolov
victory-sokolov / word_count.php
Last active November 23, 2023 14:42
PHP count words in string
<?php
function wordCount() {
$description = "Hello there";
$string = preg_replace('/\s+/', ' ', trim($description));
$words = explode(" ", $string);
return count($words);
}
@victory-sokolov
victory-sokolov / css_shortcuts.css
Created December 4, 2018 11:31
Some css shortcuts
// disallow select content on the page
.no-select {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@victory-sokolov
victory-sokolov / getIP.php
Last active November 23, 2023 14:41
Get user IP Address
<?php
function getIP()
{
if ($_SERVER['HTTP_CLIENT_IP'])
$visitorIP[] = $_SERVER['HTTP_CLIENT_IP'];
if ($_SERVER['HTTP_X_FORWARDED'])
$visitorIP[] = $_SERVER['HTTP_X_FORWARDED'];
if ($_SERVER['HTTP_X_FORWARDED_FOR'])
$visitorIP[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
@victory-sokolov
victory-sokolov / getPageLanguage.php
Last active November 23, 2023 14:41
PHP Function that returns page language
<?php
function getLang(array $request, $default)
{
return
!empty($request['get']['lang']) ? $request['get']['lang'] :
(!empty($request['cookie']['lang']) ? $request['cookie']['lang'] :
(!empty($request['session']['lang']) ? $request['session']['lang'] :
(!empty($request['server']['HTTP_ACCEPT_LANGUAGE']) ? substr($request['server']['HTTP_ACCEPT_LANGUAGE'], 0, 2) : $default)));
}