Skip to content

Instantly share code, notes, and snippets.

@uchm4n
uchm4n / Tinker.sh
Created October 17, 2021 19:51
you can: tinker 'User::first()'
function tinker()
{
if [ -z "$1" ]
then
php artisan tinker
else
php artisan tinker --execute="dd($1);"
fi
}
function StalinSort(array) {
if (!Array.isArray(array)) throw new TypeError('Argument must be an Array!');
return array.reduce((prev, next) =>
!prev.length ||
next >= prev[prev.length - 1] ?
[...prev, next] :
prev
, []);
}
@uchm4n
uchm4n / data_get.php
Created September 6, 2021 22:56
Get Collection data like you would with data_get() helper
<?php
// Register collection macros in the boot method of a app service provider
// app/Providers/AppServiceProvider.php
// usage: collect([...])->get()->data_get('key.someData.0.email','Default')
Collection::macro('data_get', function ($key, $default = '') {
return $this->map(function ($value) use ($key, $default) {
return data_get($value, $key, $default);
});
});

წესები

  1. იყავით თავაზიაები და პოზიტიურები მოდით, ყველას პატივისცემით მოვექცეთ. ჯანმრთელი დებატები ბუნებრივია, მაგრამ სიკეთე საჭიროა. ნუ იქნებით ის ტოქსიკური პიროვნება რომელისათვის ყველა და ყველაფერი არ ვარგა. აქ იმისთვის შევიკრიბეთ რომ, ერთმანეთი გავაუმჯობესოთ და არა დავამციროთ.
  2. Off Topic არ ჩამოშორდეთ მთვარ თემას.
  3. თუ გსურთ ლინკის ან ვიდეო მასალის ან რაიმე საინტერესო ინფორმაციის გაზიარება არ მოგერიდოთ, მთავარია თემატური და ინფორმაციული იყოს. სასურველია თუ მცირე განმარტებას გაუკეთებთ თუ რისთვის აშეარებთ ამა თუ იმ რესურს.
  4. თუ ვინმე არღვევს წესებს, ზრდილობიანად და თავაზიანად მიუთითეთ ამაზე.
@uchm4n
uchm4n / NestedCollection.php
Last active February 19, 2020 06:01
Simplify your nested Laravel collection with pluck function or using crossJoin and eachSpread
<?php
$customers = collect([]); // some nested Laravel collection
// Instead of manually creating this monstrous nested loop...
$customers->each(function ($customer) {
$customer->orders->each(function ($order) {
$order->payments->each(function ($payment) {
//doWork($payment);
});
@uchm4n
uchm4n / CiscoAnyConnect.scpt
Last active September 26, 2018 20:33
Automatically fill Cisco AnyConnect credentials on mac
-- automatically fill Cisco AnyConnect credentials on mac
set targetApp to "Cisco AnyConnect Secure Mobility Client"
set vpnName to "yourVPNServer.com"
set pass to "YOURPASSWORD"
set loginWindowTitle to "Cisco AnyConnect | " & vpnName
tell application targetApp
activate
end tell
repeat until application targetApp is running
-- Weigh rows against eachother based on different conditions,
-- ordering the results based on their given weights so that
-- more precise matches will show higher up in the results.
-- In this example, an exact match will show up at the top
-- of the results, a match at the beginning of the string
-- will show next, and a match anywhere will show last.
set @query = 'Liam';
@uchm4n
uchm4n / bashrc.sh
Created August 8, 2018 11:27
Colorful prompt with git branch names
#colorful prompt with git branch names
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
@uchm4n
uchm4n / reverse-ssh-tunnel
Created January 9, 2018 14:32
Setup Service on Ubuntu to make reverse ssh tunnel on remote server
# Ubuntu 15.04+
[Unit]
Description=Setup a secure tunnel to server
Wants=network-online.target
After=network-online.target
[Service]
User=admin
Environment="LOCAL_ADDR=localhost"
@uchm4n
uchm4n / MessageOfTheDay
Last active October 25, 2017 09:08
This is valid for Ubuntu servers
#! /usr/bin/env bash
# Basic info
IP=`hostname -I | awk '{print $1}'`
HOSTNAME=`uname -n`
#ROOT=`df -Ph | grep xvda1 | awk '{print $4}' | tr -d '\n'`
ROOT=`df -Ph | grep vda1 | awk 'NR==1{print $4}' | tr -d '\n'`
# System load
MEMORY1=`free -t -m | grep Total | awk '{print $3" MB";}'`