Skip to content

Instantly share code, notes, and snippets.

View Linrstudio's full-sized avatar
🌴
On vacation

xyz Linrstudio

🌴
On vacation
View GitHub Profile
@andywer
andywer / to-comment.md
Last active June 19, 2019 02:24
Double colon types in JS 🚀

Source

// test-code.js

add :: (number, number) => number

function add (x, y) {
  return x + y
}
@miquels
miquels / object-fit-css.md
Last active June 19, 2024 20:28
object-fit equivalents in pure css

object-fit equivalents in pure css

HTML

<div class="container">
  <img src="http://thetvdb.com/banners/fanart/original/78804-61.jpg">
</div>

Object-fit:contain

function commonPrefixLen(names, sep) {
const sc = sep.charCodeAt(0);
for (let pos = 0; ; pos++) {
for (let i = 0; i < names.length; i++) {
let c = names[i].charCodeAt(pos)
if (c && c == names[0].charCodeAt(pos)) {
continue;
}
while (pos > 0 && names[0].charCodeAt(--pos) != sc) {}
return pos;
@rsms
rsms / serve.sh
Created January 9, 2017 22:19
Script for quickly and securely serving HTTP locally (bound to localhost, optionally running HTTP/2)
#!/bin/sh
set -e
cd "$(dirname "$0")"
if [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ] || [ "$1" = "" ]; then
echo "Usage: $0 <port> [h2]" >&2
echo " h2 Serve over HTTP/2 with TLS using caddy" >&2
exit 1
fi
@rsms
rsms / grab-twitter-emojis.js
Created December 8, 2016 18:28
Download all Twitter Emojis as SVG
"use strict";
const fs = require('fs');
const https = require('https');
const outdir = __dirname + '/svg';
function DownloadSVG(codepoint) {
return new Promise((resolve, reject) => {
let cpstr = codepoint.toString(16).toLowerCase();
@kastermester
kastermester / es-preset.js
Created October 25, 2016 11:51
Webpack hot reloading of relay schemas
// loaction: loaders/es-preset.js
// This file is a combination of the following babel presets:
// es2015, react, stage-0.
// Difference is that the es2015-template-literals is taken out. Of the es2015 preset.
// This allows us to run relay transformations on the code afterwards (which will then transform any remaining template literals).
module.exports = preset({});
function preset(context, opts) {
var moduleTypes = ["commonjs", "amd", "umd", "systemjs"];
var loose = false;
@rsms
rsms / IconStore.h
Created October 4, 2016 00:31
QuickLook icon generation
#pragma once
#include <Foundation/Foundation.h>
#include "common.h"
@interface IconRequest : NSObject
@property (readonly) BOOL canceled;
@property (readonly) CGImageRef image; // null if canceled or failed
- (void)cancel;
@end
@rsms
rsms / gif
Created September 27, 2016 21:51
Convert a video to GIF
#!/bin/bash
set -e
if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "-help" ] || [ "$1" = "--help" ]; then
echo "usage: ${0##*/} <video-input-file> [<gif-output-file>]" >&2
echo " if <gif-output-file> is not provided, <video-input-file> with" >&2
echo " filename extension replaced by \".gif\" is used" >&2
exit 1
fi
@iammerrick
iammerrick / PinchZoomPan.js
Last active April 22, 2024 02:54
React Pinch + Zoom + Pan
import React from 'react';
const MIN_SCALE = 1;
const MAX_SCALE = 4;
const SETTLE_RANGE = 0.001;
const ADDITIONAL_LIMIT = 0.2;
const DOUBLE_TAP_THRESHOLD = 300;
const ANIMATION_SPEED = 0.04;
const RESET_ANIMATION_SPEED = 0.08;
const INITIAL_X = 0;
@gskema
gskema / color-gradient.js
Last active March 2, 2024 22:14
Generate gradient color from 2 or 3 colors using JavaScript. Example: https://jsfiddle.net/e18g5f3L/
/**
* You may use this function with both 2 or 3 interval colors for your gradient.
* For example, you want to have a gradient between Bootstrap's danger-warning-success colors.
*/
function colorGradient(fadeFraction, rgbColor1, rgbColor2, rgbColor3) {
var color1 = rgbColor1;
var color2 = rgbColor2;
var fade = fadeFraction;
// Do we have 3 colors for the gradient? Need to adjust the params.