Skip to content

Instantly share code, notes, and snippets.

View paambaati's full-sized avatar
🏠

GP paambaati

🏠
View GitHub Profile
@paambaati
paambaati / map2json.js
Last active January 16, 2019 07:36
JSON stringifier that handles ES6 Maps
// Optional: If any dependency is overriding Map's toJSON function,
// you might want to reset it.
// Why? See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior
delete Map.prototype.toJSON;
function customStringifier(key, value) {
if (value instanceof Map) {
// Convert Maps to JSON objects.
let obj = Object.create(null);
for (let [k, v] of value) {
@paambaati
paambaati / index.d.ts
Created January 7, 2019 10:57
Type definitions for chrome-remote-interface
// Type definitions for chrome-remote-interface 0.26.1
// Project: https://github.com/cyrus-and/chrome-remote-interface
// Definitions by: GP <https://github.com/paambaati>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = CDP;
declare function CDP(options?: CDP.ChromeRemoteInterfaceOptions): CDP.CDP;
declare namespace CDP {
@paambaati
paambaati / got.js
Last active March 1, 2023 00:18
Got with HTTP2 support (ALPN negotiation) + Connect settings overrides
const {extend: gotExtend} = require('got');
const http2 = require('http2-wrapper');
const resolveALPN = require('resolve-alpn');
// Taken from https://github.com/nodejs/node/blob/d4c91f28148af8a6c1a95392e5c88cb93d4b61c6/lib/_http_agent.js
//
// throws
// tls.connect({host: 'httpbin.org', port: 443});
//
// doesn't throw
@paambaati
paambaati / PDFtoHTML.scala
Created December 19, 2018 11:03
Extracting HTML from PDFs
package me
import java.io.{File, FileInputStream}
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.tools.PDFText2HTML
object PDFtoHTML {
def main(args: Array[String]): Unit = {
val stream = new FileInputStream(new File("/Users/me/Downloads/example.pdf"))
@paambaati
paambaati / getNearest.js
Created October 22, 2015 04:10
Applying a filter on .getNearest() using RethinkDB and Thinky
const userId = '2ff8902e-97f0-431a-a51c-900a57532967';
const location = r.point(-20, 39);
const queryOptions = {index: 'location'};
// Getting nearest list of users, while also excluding `userId`.
UserModel.getNearest(location, queryOptions)
.filter(r.row('doc')('id').ne(userId))
.run();
@paambaati
paambaati / tasker_airtel.xml
Created June 15, 2015 08:58
Tasker task to get a notification of your Airtel broadband usage
<TaskerData sr="" dvi="1" tv="4.7u1m">
<Task sr="task5">
<cdate>1414934667539</cdate>
<edate>1434358392316</edate>
<id>5</id>
<nme>Check Airtel Broadband Usage</nme>
<pri>10</pri>
<Action sr="act0" ve="7">
<code>118</code>
<Str sr="arg0" ve="3">http://122.160.230.125:8080</Str>
@paambaati
paambaati / launch.js
Last active May 5, 2022 05:35
Debug mocha tests using Visual Studio Code
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Run app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
@paambaati
paambaati / myproject.conf
Created February 20, 2015 15:47
Sample nginx config with redirection issue
upstream myproject_upstream {
server 127.0.0.1:3000;
}
server {
listen 80;
root /Users/myusername/Projects/myproject/static;
server_name servername.com;
@paambaati
paambaati / mongo_add_admin.js
Created May 17, 2014 05:20
Add an administrator account to MongoDB instance
db.createUser(
{
user: "admin_username",
pwd: "admin_password",
roles:
[
{
role: "userAdminAnyDatabase",
db: "admin"
}
@paambaati
paambaati / upload_demo_html.html
Last active March 28, 2021 14:55
Uploading files using NodeJS and Express 4
<html>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="text" name="title">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
</body>
</html>