Skip to content

Instantly share code, notes, and snippets.

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

Anthony Cyrille ancyrweb

🏠
Working from home
View GitHub Profile
@ancyrweb
ancyrweb / normalize.js
Created January 21, 2017 11:37
Normalize deeply
import * as normalizr from 'normalizr';
/**
* Given an object where keys are IDs
* Return all the objects and an array of unique IDs
*
* @param object
* @returns {{entities: {}, result: Array}}
*/
export const shallowNormalize = (object) => {
@ancyrweb
ancyrweb / extractBits.js
Created September 14, 2017 10:18
extractBits
/**
* Extracts bits out of the decimal num from msb to lsb
*
* @param num
* @param msb the most significant bit
* @param lsb the least significant bit
* @returns {number}
*/
function extractBits(num, msb, lsb) {
msb = msb || 0;
@ancyrweb
ancyrweb / slugify.js
Created December 14, 2017 12:23
Slugify inspired by another gist
function slugify(text) {
return text.toString().toLowerCase()
.replace(/\s+/g, '-')
.replace(/[éèëê]/g, "e")
.replace(/[iïî]/g, "i")
.replace(/[àâ]/g, "a")
.replace(/[oôö]/g, "o")
.replace(/[^\w\-]+/g, '')
.replace(/\-\-+/g, '-')
.replace(/^-+/, '')
<?php
/**
* See http://sylvana.net/jpegcrop/exif_orientation.html
*/
function fixOrientation(Imagick $image) {
$orientation = $image->getImageOrientation();
switch($orientation) {
case 2:
$image->flipImage();
break;
@ancyrweb
ancyrweb / carousel.html
Created May 17, 2018 14:35
Home-made simple carousel
@ancyrweb
ancyrweb / types.ts
Last active April 9, 2019 17:59
TypeScript basic types
export type OrNull<T> = T | null;
export type OrUndefined<T> = T | undefined;
export type Maybe<T> = OrNull<OrUndefined<T>>;
export type StringMap<V> = {[key: string]: V}
/**
* Middleware that allow to dispatch an array of actions, resulting in a single render
* @param next
* @returns {Function}
*/
export default function reduxBatchMiddleware(next: any) {
let nextListeners: any = [];
let currentListeners: any;
function ensureCanMutateNextListeners() {
@ancyrweb
ancyrweb / 32.asm
Created June 8, 2019 15:15 — forked from FiloSottile/32.asm
NASM Hello World for x86 and x86_64 Intel Mac OS X (get yourself an updated nasm with brew)
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
global start
section .text
start:
push dword msg.len
push dword msg
push dword 1
mov eax, 4
@ancyrweb
ancyrweb / Scene.js
Last active April 2, 2020 08:09
Scene.js using modals, the tutorial way
import React from 'react';
import {
StyleSheet,
TouchableOpacity,
View,
Text,
} from 'react-native';
import { useDeleteModal } from "./DeleteModal";
const styles = StyleSheet.create({
@ancyrweb
ancyrweb / DeleteModal.js
Created April 2, 2020 08:16
The DeleteModal Context
import React from 'react';
import {
StyleSheet,
View,
Text,
} from 'react-native';
import Modal from "react-native-modal";
const styles = StyleSheet.create({
modal: {