Skip to content

Instantly share code, notes, and snippets.

View bantya's full-sized avatar
🎯
Focussing

Rahul Thakare bantya

🎯
Focussing
  • http://127.0.0.1:4200
  • http://127.0.0.1:8080
  • 06:01 (UTC +05:30)
  • X @rkkth
View GitHub Profile
@bantya
bantya / sumTimes.php
Last active December 20, 2018 19:30 — forked from robozavri/php count sum times
php count sum times
print_r(sum_the_time('01:20:22', '02:10:00')); // this will give you a result: 03:30:22
// Credit: https://gist.github.com/robozavri/c7206d8f5d1efe0fa91563db4deebbcd
function sum_the_time($time1, $time2)
{
$times = [$time1, $time2];
$seconds = 0;
foreach ($times as $time) {
list($hour, $minute, $second) = explode(':', $time);
@bantya
bantya / main.js
Last active November 25, 2018 10:38
XD: app.js and manifest.json file
function commandFunction(selection) {
// The body of this function is added later
}
module.exports.commands = {
"COMMAND_NAME": commandFunction
};
@bantya
bantya / base64ArrayBuffer.js
Created October 16, 2018 20:25 — forked from jonleighton/base64ArrayBuffer.js
Encode an ArrayBuffer as a base64 string
// Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then
// use window.btoa' step. According to my tests, this appears to be a faster approach:
// http://jsperf.com/encoding-xhr-image-data/5
/*
MIT LICENSE
Copyright 2011 Jon Leighton
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@bantya
bantya / EscapeEquences.ts
Created October 11, 2018 05:22
Escape sequences
/**
* Copyright (c) 2017 The xterm.js authors. All rights reserved.
* See = https://github.com/xtermjs/xterm.js/blob/0e45909c7e79c83452493d2cd46d99c0a0bb585f/src/common/data/EscapeSequences.ts
* @license MIT
*/
/**
* C0 control codes
* See = https://en.wikipedia.org/wiki/C0_and_C1_control_codes
*/
@bantya
bantya / guide.md
Created September 14, 2018 14:12 — forked from fyrebase/guide.md
Setup individual pools for PHP-FPM and NGINX - http://www.binarytides.com/php-fpm-separate-user-uid-linux/

Php-FPM

Php fpm is the new way to setup php to run with your webserver. Php-fpm is a fastcgi process manager for php that is totally separate from the webserver. The webserver communicates with fpm through a socket and passes the name of the script to execute. So fpm can run with any web server that is fastcgi compatible.

I recently moved from my old shared hosting to linode. Linode provides linux vps hosting at economic prices. However the servers are totally unmanaged are just raw linux machines that have shell access. So through the shell you have to setup everything including the web server, php and the web files.

So this time I decided to go with the combination of nginx and php-fpm. I had multiple sites to setup on this new webserver. Nginx deals with these through separate server blocks (aka vhost in apache). However there was another thing needed. Php on each site should run with its own user and not the nginx common user named www-data.

Running each site with its own uid/gid is more secure and

@bantya
bantya / fetch-client.js
Created September 12, 2018 13:24 — forked from bryanrsmith/fetch-client.js
A thin wrapper library around the fetch API to provide application-wide HTTP client configuration
export class HttpClient {
constructor(defaults) {
this.defaults = defaults;
this.interceptors = [];
this.activeRequestCount = 0;
this.isRequesting = false;
}
addInterceptor(interceptor) {
this.interceptors.push(interceptor);
@bantya
bantya / USAGE
Last active June 5, 2024 19:45
Convert sublime snippets to vscode.
php snippets.php [SNIPPETS_DIRECTORY]
e.g. php snippets.php vue
SNIPPETS_DIRECTORY: Assuming that the snippets are categorized in directories (preferably by languages) and snippet directories and the script have the same parent directory.
e.g.
/snippets
|
+--- snippets.php
|
+--- /php
@bantya
bantya / php-webscraping.md
Created July 22, 2018 15:23 — forked from anchetaWern/php-webscraping.md
web scraping in php

Have you ever wanted to get a specific data from another website but there's no API available for it? That's where Web Scraping comes in, if the data is not made available by the website we can just scrape it from the website itself.

But before we dive in let us first define what web scraping is. According to Wikipedia:

{% blockquote %} Web scraping (web harvesting or web data extraction) is a computer software technique of extracting information from websites. Usually, such software programs simulate human exploration of the World Wide Web by either implementing low-level Hypertext Transfer Protocol (HTTP), or embedding a fully-fledged web browser, such as Internet Explorer or Mozilla Firefox. {% endblockquote %}

@bantya
bantya / README.md
Created May 30, 2018 14:10 — forked from Ocramius/README.md
`__invoke` vs `function` vs `Closure`
@bantya
bantya / get_all_columns_except.php
Created May 24, 2018 18:56
PHP: Get all the columns except the defined ones from a table using MySQL
<?php
$create = $pdo->query('show create table users')->fetch(\PDO::FETCH_ASSOC);
$create = $create['Create Table'];
preg_match_all('/^\s+`([^`]+)/m', $create, $matches);
$matches = $matches[1];
$matches = array_diff($matches, $except);