Skip to content

Instantly share code, notes, and snippets.

View sahilkashyap64's full-sized avatar
🎯
Focusing

Sahil Kashyap sahilkashyap64

🎯
Focusing
View GitHub Profile
//A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
//For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation 100000 and has no binary gaps.
//solution 1
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
return Math.max(0,...(N >>> 0)
.toString(2)
@sahilkashyap64
sahilkashyap64 / Attendance collection
Last active March 21, 2020 19:19
Attendance collection. It has a teacher and his details and date, teacher has a class which contains his student details and attendance status
{
"_id": {
"$oid": "5e68c7eaa0887971ea6ef54c"
},
"professorclass": [
{
"_id": {
"$oid": "5e678d257cd5a55f2188f02f"
},
"attendance_status": "SES",
@sahilkashyap64
sahilkashyap64 / CountTheStudentMongodb
Created March 21, 2020 19:35
Find the number of object present in array of mongoDB
const Allstudentsaag = await Attendance.aggregate(
[ { $match : { "subject" : "chem" } } ,
{ $project : { _id: 0,email:1, professorclass : 1 ,
numberofstudent: { $cond: { if: { $isArray: "$professorclass" },
then: { $size: "$professorclass" }, else: "NA"} }}},]);
//In attendance collection Find the subject=chem ,only show email and professorclass field
if professorclass is an array then show the size of the array if it's empty so N/A.
Show the size in a fieldname called numberofstudent
@sahilkashyap64
sahilkashyap64 / .env
Created March 24, 2020 07:28
Login with MERN Stack, JWT
//.env
JWT_SECRET={{mysecret}}
@sahilkashyap64
sahilkashyap64 / TurfController.php
Created September 5, 2020 19:09
turf.js to php code
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Zipcode;
use Illuminate\Support\Facades\DB;
class TurfController extends Controller
{
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="https://s3.amazonaws.com/cdn.keyos.com/html5/videojs/7.5.4/video-js.min.css" rel="stylesheet">
@sahilkashyap64
sahilkashyap64 / Figma-urdu.txt
Created March 21, 2021 12:21
How to use urdu in figma
Choose text box and type "Amiri" in the font section.
If you want to know if urdu font is available in the google fonts or not, copy choti ye "ی"
And look for if the fonts come up, sometimefont won'tshow, just click on the font name and go toglyph section and see if font exist there
@sahilkashyap64
sahilkashyap64 / SomeController.php
Last active June 26, 2024 12:04
Select2 with laravel pagination
public function getdataforselect2(Request $request){
if ($request->ajax()) {
$term = trim($request->term);
$posts = DB::table('channels')->select('id','name as text')
->where('name', 'LIKE', '%' . $term. '%')
->orderBy('name', 'asc')->simplePaginate(10);
$morePages=true;
@sahilkashyap64
sahilkashyap64 / DemoController.php
Created June 9, 2021 08:15
Laravel Use gzencode compression in rest api
public function channelDaysSchedule() {
$record= DB::table('gracenote'); //use select to limit data
$reco=$record->get();
$response = [
'success' => true,
'date'=>date("Y-m-d"),
// 'count' => $reco->count(),
'data' => $reco,
'message' => 'Schedule data for 3 days found',
@sahilkashyap64
sahilkashyap64 / window-controller.js
Created July 10, 2021 06:10 — forked from neilj/window-controller.js
Cross-tab window controller
function WindowController () {
this.id = Math.random();
this.isMaster = false;
this.others = {};
window.addEventListener( 'storage', this, false );
window.addEventListener( 'unload', this, false );
this.broadcast( 'hello' );