Skip to content

Instantly share code, notes, and snippets.

View lansana's full-sized avatar

Lansana Camara lansana

View GitHub Profile
// Found on some article, forgot which. It visualizes mandelbrot set.
// TODO: make faster
<!DOCTYPE html>
<html>
<body>
<script>
(() => {
// Create Canvas
const myCanvas = document.createElement('canvas');
package middleware
import (
"net/http"
"strconv"
"time"
"core/http/jsonapi"
"core/http/router"
"domain"
@lansana
lansana / batch.ts
Created March 30, 2018 17:16
Batch push items into a list
batch(items: any[], count: number, interval: number, iteratee: (item: any, index: number) => void) {
const len = items ? items.length : 0;
// If the count is gte the total amount, just loop through and add
// them all and don't bother batching.
if (count >= len) {
for (let i = 0; i < len; i++) {
iteratee(items[i], i);
}
package hmac
import (
"crypto/sha256"
"crypto/sha512"
"testing"
)
func TestValidateCustomHashSuccess(t *testing.T) {
key := []byte("123456")
package hmac
import (
"crypto/hmac"
"crypto/sha256"
"crypto/sha512"
"encoding/base64"
"encoding/hex"
"hash"
)
@lansana
lansana / replace-line.sh
Created August 18, 2017 11:41
Bash script to find/replace a line in a file
#!/usr/bin/env bash
######################################################################################
# USAGE: bash bash/replace-line.sh "replace this line" "to this line" in-this-file.txt
######################################################################################
function escapeSlashes {
sed 's/\//\\\//g'
}
@lansana
lansana / infinite-scroll.directive.ts
Last active April 11, 2022 09:02
This is an Angular 2 infinite scroll directive. It is simple, easy to use and very CPU-efficient.
// USAGE:
//
// When you attach the infiniteScroll directive to an element, it will emit the infiniteScrollAction
// @Output() event every time the user has scrolled to the bottom of the element. Your loadMoreArticles
// function can make an HTTP call and append the results to the articles list, for example. In doing this,
// you effectively increase the height of the element and thus begin the process of the infiniteScroll directive
// again, over and over until the element height stops increasing.
//
// <div class="container" infiniteScroll (infiniteScrollAction)="loadMoreArticles()">
// <div class="article" *ngFor="let article of articles">
@lansana
lansana / json-decorator.ts
Last active May 17, 2017 23:30
TypeScript JSON decorator to turn convert ES6 class properties from camelCaseLikeThis to snake_case_like_this to be used as an HTTP request JSON object.
function JSON<T extends {new(...args: any[]): {}}>(ctor: T) {
function toSnakeCase(prop: string): string {
return prop.replace(/[A-Z]/g, (prop: string): string => {
return `_${prop.toLowerCase()}`;
});
}
return class extends ctor {
constructor(...args: any[]) {
let cfg = args.shift();
@lansana
lansana / fn.js
Last active September 26, 2017 19:06
A functional JavaScript library in ES6. Composition, currying, polyfills and performance.
/**
* A functional JavaScript library -- composition, currying, polyfills and performance.
*
* Copyright Lansana Camara, 2016
* @license MIT
*/