Skip to content

Instantly share code, notes, and snippets.

View bouiboui's full-sized avatar
🌍
cod3.net

Julien bouiboui

🌍
cod3.net
View GitHub Profile
@bouiboui
bouiboui / json2yamldesc.php
Created September 13, 2017 10:20
Creates a YAML description from a JSON payload (replace $data by your JSON payload)
<?php
function formatLine(array $items, $indent)
{
$spaces = '';
while ($indent--) {
$spaces .= ' ';
}
return PHP_EOL .
implode(PHP_EOL,
const FB = require('fb');
FB.setAccessToken(process.env.FB_ACCESS_TOKEN);
async function fetchNextLikes(after) {
const url = 'me/likes?limit=100' + (after ? '&after=' + after : '');
const response = await FB.api(url);
return [
response.data.map(like => like.name),
response.paging && response.paging.cursors.after
const scrapeIt = require('scrape-it');
const fetchAmazonSearchResults = async query => {
const {data} = await scrapeIt(process.env.AMAZON_SEARCH_URL + query, {
results: {
listItem: '.s-result-item',
data: {
image: {
selector: '.s-image',
require('dotenv').load();
const db = require('../lib/db');
const md5 = require('../lib/md5');
const fetchAmazonSearchResults = require('../lib/fetch-amazon-search-results');
const amazon = {
updateSearchResults: async query => {
require('dotenv').load();
const db = require('../lib/db');
const fetchFacebookLikes = require('../lib/fetch-facebook-likes');
const facebook = {
updateLikes: async () => {
console.log('Fetching Facebook likes');
@bouiboui
bouiboui / FlagContextProvider.tsx
Last active January 27, 2020 09:27
React + Typescript Context Provider with children autocompletion
import React, { ReactElement, ReactNode, useState } from 'react'
export interface IFlagContext {
userEmail: string | null
sendEmail: boolean
changeUserEmail: (email: string) => void
}
const FlagContext = React.createContext<IFlagContext | null>(null)
@bouiboui
bouiboui / removeduplicateframes.sh
Created February 18, 2020 17:31 — forked from danielmahal/removeduplicateframes.sh
Remove duplicate frames from video with ffmpeg and mpdecimate
ffmpeg -i input.mov -vf mpdecimate,setpts=N/FRAME_RATE/TB output.mov
@bouiboui
bouiboui / html-attributes-to-css-props.js
Created February 17, 2021 10:41
Useful to convert HTML attributes to CSS (to convert from chakra to styled components, for example)
// yarn add posthtml-parser
import parser from 'posthtml-parser'
// Paste your HTML component here
const html = `
<Box
fontSize="12px"
lineHeight="16px"
textAlign="right"
/>
@bouiboui
bouiboui / htmlToAST.ts
Created March 19, 2021 09:16 — forked from halfnibble/htmlToAST.js
GraphCMS HTML to RichTextAST (TypeScript version)
import {jsx} from "slate-hyperscript";
import {JSDOM} from "jsdom";
const DOMParser = new JSDOM().window.DOMParser
const htmlToAST = (html: string) => {
const parsed = new DOMParser().parseFromString(html, 'text/html')
return deserialize(parsed.body)
}
@bouiboui
bouiboui / amp.d.ts
Created July 11, 2022 06:06
Google Accelerated Mobile Pages (AMP) Typescript Definitions (not perfect but good-enough for me)
import * as React from "react";
declare global {
namespace JSX {
interface IntrinsicElements {
"amp-3d-gltf": React.DetailedHTMLProps<
{
alpha?: "false" | "true";
antialiasing?: "false" | "true";
autorotate?: "false" | "true";