Skip to content

Instantly share code, notes, and snippets.

View gonaumov's full-sized avatar
💭
a status

George Naumov gonaumov

💭
a status
View GitHub Profile
@gonaumov
gonaumov / destructing-in-php.txt
Created August 20, 2019 17:52
Since PHP 7.1 we can destruct array in JavaScript style. :)
georginaumov@virtualbox:~/Documents$ php -a
Interactive mode enabled
php > ['first' => $first, 'second' => $second] = ['first' => 'Tom', 'second' => 'Jerry'];
php > var_dump([$first, $second]);
array(2) {
[0]=>
string(3) "Tom"
[1]=>
string(5) "Jerry"
@gonaumov
gonaumov / ssf.kt
Created October 16, 2019 16:10
Single expression function
fun getGreeting(): String = "Hello Kotlin"
@gonaumov
gonaumov / Main.kt
Created October 19, 2019 14:22
Main.kt
/**
* In this example, `val` denotes a declaration of a read-only local variable,
* that is assigned an pattern matching expression.
* See http://kotlinlang.org/docs/reference/control-flow.html#when-expression
*/
fun main(args: Array<String>) {
val language = if (args.size == 0) "EN" else args[0]
println(when (language) {
"EN" -> "Hello!"
const getLastImport = (input) => {
const [,lastImport] = /(import\s+\w+)(?:(?!import\s+\w+).)*$/.exec(input) || [,false];
return lastImport;
}
/**
* You can edit, run, and share this code.
* play.kotlinlang.org
*/
data class MyResponse(
val bigger: Int,
val lower: Int
)
fun main() {
// here never.created is Data
// formatter is SimpleDateFormat("y-M-d H:m:s")
// with timeZone = TimeZone.getTimeZone("UTC")
// The problem is that this comparison
// working properly on UTC+0
// When I set timeZone = TimeZone.getDefault()
// it starts to work on every other timezone
// instead UTC. The question is how to fix
// that in shortest way? Maybe to calculate
// current timezone offset and just to
val calculatedTimezoneOffset = TimeZone.getDefault().let {
// The problem is
// TimeZone.getTimeZone("UK").inDaylightTime(Date())
// is false every time. If this is true everything pass.
val offset = if(TimeZone.getTimeZone("UK").inDaylightTime(Date()))
it.getOffset(System.currentTimeMillis()) + 3600000 // -> this is the one hour of daily saving time.
else
it.getOffset(System.currentTimeMillis())
offset
}
/**
* Мисля, че това, което искаш да постигнеш е това:
***/
console.log(/^[\u0410-\u044FA-Z0-9\\'\\/@#\\.\\*:]+$/i.test("test1"));
// true
console.log(/^[\u0410-\u044FA-Z0-9\\'\\/@#\\.\\*:]+$/i.test("кирилица1"));
// true
console.log(/^[\u0410-\u044FA-Z0-9\\'\\/@#\\.\\*:]+$/i.test("111111"));
// true
/**
(function() {
var css = ["* {",
"-webkit-touch-callout: default !important;",
"-webkit-user-select: auto !important;",
"-khtml-user-select: auto !important;",
"-moz-user-select: auto !important;",
"-ms-user-select: auto !important;",
"user-select: auto !important;",
"cursor: auto !important;",
"-webkit-tap-highlight-color: black !important;",
<!--
Just an idea. You don't need any event listeners,
id's and etc. Try this. If it works for you this
is the cleanest solution.
-->
<div style="display: none;">
[
{"id": 1},
{"id": 2}
]