Skip to content

Instantly share code, notes, and snippets.

View ishida83's full-sized avatar
🌌

ishida ishida83

🌌
View GitHub Profile
@ishida83
ishida83 / LICENSE
Created January 22, 2020 08:25 — forked from kalebdf/LICENSE
Export Table Data to CSV using Javascript
MIT License
Copyright (c) 2015 Kaleb Fulgham
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@ishida83
ishida83 / react-router-login.js
Last active August 13, 2019 08:23
react-router-login
export default (store) => {
const requireLogin = (nextState, replace, cb) => {
const { auth: { user } } = store.getState();
if (!user) {
// oops, not logged in, so can't be here!
replace('/login?returnUrl=' +
encodeURIComponent(nextState.location.pathname + nextState.location.search));
}
cb();
};
@ishida83
ishida83 / dezip.js
Created July 17, 2019 07:00 — forked from miguelmota/dezip.js
Uncompress gzip response body in Node.js
var request = require('request');
var zlib = require('zlib');
request(url, {encoding: null}, function(err, response, body){
if(response.headers['content-encoding'] == 'gzip'){
zlib.gunzip(body, function(err, dezipped) {
callback(dezipped.toString());
});
} else {
callback(body);
@ishida83
ishida83 / app.js
Created May 16, 2019 14:05 — forked from joshnuss/app.js
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./permission"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@ishida83
ishida83 / FunIntro.js
Created January 1, 2019 07:02 — forked from GantMan/FunIntro.js
Having fun with Infinite Red logo and React Native animations
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
@ishida83
ishida83 / app.js
Created December 3, 2018 03:42 — forked from davidkpiano/app.js
Simple way to namespace React components
import React from 'react';
import * as My from './components/my-components.js';
export default class App extends React.Component {
render() {
return (
<div>
<My.Foo />
<My.Bar />
@ishida83
ishida83 / React-Native-WebView-Cookies.js
Created November 4, 2018 06:57 — forked from xxxxlr/React-Native-WebView-Cookies.js
React Native Trick: Get Cookies of WebView without using any native modules such as react-native-cookies. Might be helpful for getting JWT while making OAuth2 πŸ‘½
// @flow
import React, { Component } from 'react';
import {
WebView,
} from 'react-native';
class LoginScreen extends Component {
state = {
cookies : {},
@ishida83
ishida83 / gist:5db1bab35219386fb0200c27b5d3ec89
Created August 24, 2018 00:37 — forked from deandob/gist:8943268
Streaming MP4 to HTML5 clients
--------------- FFMPEG command line
ffmpeg = child_process.spawn("ffmpeg", [
"-i", rtsp , "-vcodec", "copy", "-f", "mp4", "-f", "segment", "-segment_time", recSeg, "-segment_wrap", 2, "-map", "0", "-segment_format", "mp4", "-reset_timestamps", "1", "-y", "plugins/security/videos/" + camName + "/rec-%01d.mp4"
], {detached: false});
---------------- Node.JS streamer
// Stream mp4 video file based on URL request from client player. Accept request for partial streams
// Code attribution: https://github.com/meloncholy/vid-streamer/blob/master/index.js (MIT license)
var recStream = function (req, resp) {
var stream;
@ishida83
ishida83 / App.js
Created August 9, 2018 04:43 — forked from madcoda/App.js
React-router v4 multi layout
import React, { Component } from 'react'
import { BrowserRouter as Router, Route, Link, Match, Redirect, Switch } from 'react-router-dom'
import OverviewPage from './page/OverviewPage'
import AccountPage from './page/AccountPage'
/*
Layouts, inline define here for demo purpose
you may want to define in another file instead
*/
@ishida83
ishida83 / react-router-queyry-utils.js
Created August 7, 2018 09:59 — forked from DimitryDushkin/react-router-queyry-utils.js
React router utility functions to add and remove queries
import { browserHistory } from 'react-router';
/**
* @param {Object} query
*/
export const addQuery = (query) => {
const location = Object.assign({}, browserHistory.getCurrentLocation());
Object.assign(location.query, query);
browserHistory.push(location);
};