Skip to content

Instantly share code, notes, and snippets.

View manekinekko's full-sized avatar
:octocat:
Check me out on Twitter @manekinekko

Wassim Chegham manekinekko

:octocat:
Check me out on Twitter @manekinekko
View GitHub Profile
@manekinekko
manekinekko / index.spec.ts
Created April 21, 2024 13:11
Mocking node:child_process.spawn() using Jest + TypeScript
import { Readable } from "stream";
const mockSpawn = jest.fn(() => {
return {
stdout: new Readable({
read() {
this.push("stout data"); // write mock data to stdout
this.push(null); // end stream
},
}),
@manekinekko
manekinekko / regex-es6-imports.js
Last active February 1, 2024 16:05
A regular Expression to parse ECMAScript6 import syntax
let regex = `import
(?:
["'\s]*
([\w*{}\n, ]+)
from\s*
)?
["'\s]*
([@\w/_-]+)
["'\s]*
;?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Untitled benchmark</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@manekinekko
manekinekko / deploy-cloud-function-from-repo.md
Last active August 24, 2023 16:39
gcloud.tips: deploy cloud function from a Google Cloud Repository

Deploy a Cloud Function from a repository

Google Cloud Functions allows you to deploy small logical units of code (i.e. functions). While it is already possible to deploy these functions from a Google Cloud Storage bucket or directly from the inline editor (e.g. for prototyping purposes), did you know that you can take advantage of the Google Cloud Repository to host the Cloud Functions source code and automate these deployments? You could for instance trigger a new deploy after each git push. Let's see how.

We'll assume you already have a working Google Cloud Repository (how to setup a Cloud Repository) with the following configuration:

  • projectID: project-123
  • repository name: default
  • default branch: master
  • function name: function-123
@manekinekko
manekinekko / zonejs-flags.ts
Created February 3, 2021 09:37
Reduce overhead introduced by the Zone.js
// Reduce overhead introduced by the Zone.js:
// by Wassim Chegham (@manekinekko)
// Instructions:
// 1. Add this config in a different file, eg. zone-flags.ts
// 2. make sure to check that your app is not relying on an API before disabling it!!!
// 3. import ./zone-flags.ts in polyfills.ts
// Not needed for morst of Angular apps
(window as any).__Zone_disable_requestAnimationFrame = true;
@manekinekko
manekinekko / open-in-cloud-shell.md
Last active December 29, 2022 17:19
gcloud.tips: use the Google Cloud Shell to clone and edit a github repository

Open a github repository in the Cloud Shell

The Google Cloud Shell gives you a handy and quick Shell access to your Cloud instance. One thing you may not know is that you can use the Cloud Shell to clone and edit a Github project. Let's see how.

The trick here is to just call the following URL: https://console.cloud.google.com/cloudshell/open with the following parameters:

  1. git_repo: this is the URL to your github repository
  2. open_in_editor: this would be the file you want to open in the editor
  3. page=editor: this tells the cloud shell to open the code editor
@manekinekko
manekinekko / binary-plist-parser.service.ts
Last active October 21, 2022 09:40
Apple's Binary Property List (bplist) parser in #JavaScript for the browser.
// const Buffer = require('buffer/').Buffer;
import { Injectable } from '@angular/core';
// Ported to browser from https://githuBuffer.com/joeferner/node-bplist-parser/blob/master/bplistParser.js
// Inspired by http://code.google.com/p/plist/source/browse/trunk/src/com/dd/plist/BinaryPropertyListParser.java
const bigInt = require('big-integer');
const Buffer = require('bops');
export const maxObjectSize = 100 * 1000 * 1000; // 100Meg
export const maxObjectCount = 32768;
@manekinekko
manekinekko / 0-twig-and-angular2-integration.md
Last active July 22, 2021 17:21
Use a Twig template with Angular2 components

This is an attempt to add Twig templating support to Angular 2 (WIP)

@manekinekko
manekinekko / digital-covid-certificate-fr-decoder.txt
Last active July 21, 2021 10:14
An attempt to decode the Digital Covid Certificate (signed with the FR public key - Tous Anti Covid) - For Educational Purposes Only
Code was moved to https://github.com/manekinekko/digital-covid-certificate-decoder
@manekinekko
manekinekko / swa-arm.json
Created April 14, 2021 08:45
Sample SWA deployment template
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
},
"location": {
"type": "string"
},