Skip to content

Instantly share code, notes, and snippets.

@hongdonghyun
hongdonghyun / eximbay.py
Last active April 11, 2020 10:16
eximbay
class Eximbay():
def __init__(self, secret_key, mid, mod="TEST"):
self.secret_key = secret_key
self.mid = mid
if mod == "REAL": # real
self.url = "https://secureapi.eximbay.com/Gateway/BasicProcessor.krp"
else:
self.url = "https://secureapi.test.eximbay.com/Gateway/BasicProcessor.krp"
@yongdamsh
yongdamsh / useWindowSize.js
Last active August 30, 2020 13:33
React custom hook to subscribe resize event
import { useReducer } from 'react';
import debounce from 'lodash/debounce';
function windowSizeReducer(state, action) {
if (action.type === 'resize') {
return action.width;
}
return state;
}
@yongdamsh
yongdamsh / useElemenetVisibility.js
Created June 7, 2019 08:28
React custom hook based on intersectionObserver
import 'intersection-observer';
import { useCallback, useState, useEffect, useRef } from 'react';
const defaultEntry = {
isIntersecting: false,
intersectionRatio: 0
};
const defaultOptions = {};
function useElementVisibility(options = defaultOptions) {
import React, { useEffect, useRef } from "react";
import ReactDOM from "react-dom";
import "./styles.css";
// Custom hook
function useLazyImageObserver(target) {
useEffect(() => {
if (!target.current) {
return;
@bregenspan
bregenspan / diveTo.js
Last active December 17, 2020 02:17
Recursively dive() to deeply-wrapped components via Enzyme
import merge from 'lodash/merge';
/**
* Given an Enzyme ShallowWrapper and component identifier, dives() down until the
* specified component is the root component.
*
* @param { Enzyme.ShallowWrapper } shallowWrapper - wrapper to dive into
* @param { string } name of component to dive for (should match constructor name).
* @param { object= } options to pass to dive()
*/
@fousa
fousa / FairPlayer.swift
Last active June 1, 2023 12:28
Integrate HLS with FairPlay.
class FairPlayer: AVPlayer {
private let queue = DispatchQueue(label: "com.icapps.fairplay.queue")
func play(asset: AVURLAsset) {
// Set the resource loader delegate to this class. The `resourceLoader`'s delegate will be
// triggered when FairPlay handling is required.
asset.resourceLoader.setDelegate(self, queue: queue)
// Load the asset in the player.
# Usage:
# ========
# FirebaseAuth::Auth.verify_id_token(your_id_token)
#
# The method call follows the same API of the Node.js, JAVA and Python SDKs.
# See https://firebase.google.com/docs/auth/admin/verify-id-tokens#verify_id_tokens_using_the_firebase_admin_sdk
# Dependencies:
# ---------------
# gem 'activesupport'
@jace
jace / denoise.sh
Last active October 11, 2023 10:17
Remove noise from video using sox and ffmpeg
# 1. extract audio from all videos (assuming .mp4 videos).
for FILE in *.mp4; do ffmpeg -i $FILE ${FILE%%.mp4}.wav; done
# 2. use the first second of the first audio file as the noise sample.
sox `ls *.wav | head -1` -n trim 0 1 noiseprof noise.prof
# Replace with a specific noise sample file if the first second doesn't work for you:
# sox noise.wav -n noiseprof noise.prof
# 3. clean the audio with noise reduction and normalise filters.
@jarretmoses
jarretmoses / React Native Clear Cache
Last active July 17, 2024 15:14
Clearing the Cache of your React Native Project
RN < 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
RN >= 0.50 - watchman watch-del-all && rm -rf $TMPDIR/react-native-packager-cache-* && rm -rf $TMPDIR/metro-bundler-cache-* && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache
RN >= 0.63 - watchman watch-del-all && rm -rf node_modules && npm install && rm -rf /tmp/metro-* && npm run start --reset-cache
npm >= 5 - watchman watch-del-all && rm -rf $TMPDIR/react-* && rm -rf node_modules/ && npm cache verify && npm install && npm start -- --reset-cache
Windows - del %appdata%\Temp\react-native-* & cd android & gradlew clean & cd .. & del node_modules/ & npm cache clean --force & npm install & npm start -- --reset-cache
@TakahikoKawasaki
TakahikoKawasaki / sinatra+thin+ssl.rb
Last active October 19, 2023 14:38
Sinatra + Thin + SSL
#!/usr/bin/env ruby
#
# This code snippet shows how to enable SSL in Sinatra+Thin.
#
require 'sinatra'
require 'thin'
class MyThinBackend < ::Thin::Backends::TcpServer
def initialize(host, port, options)