Skip to content

Instantly share code, notes, and snippets.

View vinaydotblog's full-sized avatar
🏠
Working from home

Vinay Aggarwal vinaydotblog

🏠
Working from home
View GitHub Profile
@vinaydotblog
vinaydotblog / composelist.sh
Created June 28, 2018 16:29 — forked from mortenson/composelist.sh
List all Docker Compose projects currently running
#!/bin/bash
docker ps --filter "label=com.docker.compose.project" -q | xargs docker inspect --format='{{index .Config.Labels "com.docker.compose.project"}}'| uniq
@vinaydotblog
vinaydotblog / bookmarklet-speech-input.js
Last active February 24, 2018 07:40
A bookmarklet to input text using speech to document's active element.
(function(Recognition,c){
var recognition = new Recognition;
recognition.lang = 'en-US';
recognition.interimResults = false;
recognition.maxAlternatives = 5;
recognition.start();
c.log('listening now');
function triggerEvent(elem, Event, type) {
var event = new Event(type, {'bubbles': true, 'cancelable': true });
@vinaydotblog
vinaydotblog / php-server.sh
Created November 18, 2017 17:49
PHP Local Server
## Usage Example: serv home.html 5050
## 2nd and 3rd arguments are optional
serv() {
open -a "Google Chrome" http://localhost:${2:-2020}/${1:-}
/usr/bin/php -S localhost:${2:-2020} -t .
}
@vinaydotblog
vinaydotblog / composer.json
Created July 23, 2017 11:24 — forked from andyshinn/composer.json
Docker Compose PHP Composer Example
{
"require": {
"mfacenet/hello-world": "v1.*"
}
}
@vinaydotblog
vinaydotblog / laravel_query_log.php
Created June 5, 2017 10:32
Clean query log for laravel
<?php
DB::listen(function ($sql) {
$log = vsprintf('[SQL] - ' . str_replace('?', '"%s"', $sql->sql), $sql->bindings);
if( App::runningInConsole() ) {
print($log);
} else {
\Log::info($log);
}
function fp(num)
{
// Typecast the user input
num = parseInt(num) || 0;
// Don't accept if length is 1
if( num < 10 ){
throw new Error('You must pass a number of at least two digits');
}
@vinaydotblog
vinaydotblog / digits2image.js
Created October 1, 2016 22:49
Flat digits array to image
<canvas id="can" width="800" height="800"></canvas>
<script>
var lol = [0.0, 0.0, 0.0, 0.0, 11.0, 12.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 15.0, 14.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 16.0, 11.0, 0.0, 0.0, 0.0, 0.0, 9.0, 16.0, 16.0, 10.0, 0.0, 0.0, 0.0, 4.0, 16.0, 12.0, 16.0, 12.0, 0.0, 0.0, 0.0, 3.0, 10.0, 3.0, 16.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 16.0, 14.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 11.0, 0.0, 0.0];
var img = [];
while( lol.length ){ img.push( lol.splice(0,8) ) }
var can = document.querySelector('#can');
@vinaydotblog
vinaydotblog / dump_scopes.py
Created September 17, 2016 21:10 — forked from sessa/dump_scopes.py
Dump scopes used by a TextMate grammar
#!/usr/bin/env python
import plistlib
class Grammar(object):
def __init__(self, grammar):
self._grammar = grammar
self.names = []
self.includes = []
<?php
$d1 = new DateTime('2016-04-12');
$d2 = new DateTime('2016-04-16');
$ar = [
['name' => 'vinay', 'date' => new DateTime('2016-04-05')],
['name' => 'vinay', 'date' => new DateTime('2016-04-12')],
@vinaydotblog
vinaydotblog / latlng_to_city.js
Last active November 18, 2017 16:34
Gives back City Name based on given latitude/longitude values.
/*
* Pass it your string of latlong and it'll return a promise to come back with the locality, city.
*
* getCity('12.9715987,77.5945627').done(function(cityName){
* $elem.val( cityName )
* });
*
* Info: jQuery is required for $.Deferred() and $.getJSON to work!
* Regardless of everything modify it as per your convenience :)
*/