Skip to content

Instantly share code, notes, and snippets.

View sonichandni's full-sized avatar
💻
Focusing

Chandni Soni sonichandni

💻
Focusing
View GitHub Profile
@sonichandni
sonichandni / Laravel get store and get file from url
Created February 20, 2024 10:29
Laravel get store and get file from url
// Put file content
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $url);
$contents = $response->getBody()->getContents();
$fileName = $id . '_' . time() . '.pdf';
$path = 'public/bol/' . $fileName;
Storage::put($path, $contents);
@sonichandni
sonichandni / index.php
Last active December 22, 2023 10:53
get unique pairs which have sum of targeted values
<?php
class UniquePairs {
public function getdata($elements, $target) {
$i = 0;
$response = [];
foreach($elements as $element1) {
$j = 0;
foreach($elements as $element2) {
$result = [];
@sonichandni
sonichandni / test.php
Created May 3, 2023 12:58
Download user logo from user mobile number csv
public function test() {
$csv = \File::get(storage_path().'/app/public/mobile_data_id.csv');
$rows = str_getcsv($csv, "\n");
// Loop through each row
foreach ($rows as $mobileNumber) {
// Find user ID based on mobile number
$userId = \DB::table('client')->where('mobile', $mobileNumber)->value('id');
// Fetch logo image based on user ID TestLogoDir
// For php
public function createSlug($str) {
$str = trim($str);
$str = strtolower($str);
$from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
$to = "aaaaeeeeiiiioooouuuunc------";
$str = strtr($str, $from, $to);
@sonichandni
sonichandni / test.php
Last active May 4, 2023 13:21
date wise data
use Carbon\Carbon;
use DB;
// For today
$activationKeyCount['today'] = KeyBatchGroupKeys::select('id')->whereDate('d_activation_date', Carbon::today())->count();
// For yesterday
$activationKeyCount['yesterday'] = KeyBatchGroupKeys::select('id')->whereDate('d_activation_date', Carbon::yesterday())->count();
@sonichandni
sonichandni / file.php
Created January 24, 2023 12:41
php array group by with key value
// Input
$data = array(
array("name" => "John", "age" => 25),
array("name" => "Jane", "age" => 22),
array("name" => "Bob", "age" => 25),
array("name" => "Sara", "age" => 22)
);
$groupedData = array_reduce($data, function($result, $item) {
$result[$item['age']][] = $item;
@sonichandni
sonichandni / file.js
Created January 18, 2023 09:01
scroll div
function scroll_screen(){
if ($('.error-color')) {
// old code for full screen scrolling
// var content_class = "callon_content";
// $('.'+content_class).animate({
// scrollTop: $('.error-color').offset().top
// }, 2000);
// new code to scroll inside middle div
let errorElement = document.getElementsByClassName('error-color')[0];
<?php
function groupByOwners(array $files) : array {
$data = [];
foreach($files as $key => $val) {
$data[$val][] = $key;
}
return $data;
}
@sonichandni
sonichandni / welcome.blade.php
Created April 18, 2022 12:08
print php and laravel version in laravel blade file
Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }})
// find sub string
const string = "foo";
const substring = "oo";
console.log(string.includes(substring)); // true
// replace string
let text = "Visit Microsoft!";
let result = text.replace("Microsoft", "W3Schools");
//regex for height