Skip to content

Instantly share code, notes, and snippets.

@mjunaidi
mjunaidi / gist:f6615cec7f6d006642aa7ee6cb9b89a0
Created December 7, 2020 12:53 — forked from nazoking/gist:2822127
get image mime type from base64
function guessImageMime(data){
if(data.charAt(0)=='/'){
return "image/jpeg";
}else if(data.charAt(0)=='R'){
return "image/gif";
}else if(data.charAt(0)=='i'){
return "image/png";
}
}
@mjunaidi
mjunaidi / WebViewBridge.js
Created September 19, 2019 07:57 — forked from blankg/WebViewBridge.js
For RN >= 0.57 please look at https://github.com/blankg/rn-webview-bridge-sample-new/blob/master/resources/index.html. Provides a sample implementation for sending and receiving messages to and from the React-Native WebView (using postMessage/onMessage WebView API).
/**
* Created by Guy Blank on 3/9/17.
*
* This is a sample provides an API to send & receive messages to and from the React-Native WebView (using postMessage/onMessage WebView API).
* A sample project that uses the bridge is available here https://github.com/blankg/rn-webview-bridge-sample
*
* webViewBridge.send('functionToInvoke', {mydata: 'test'}, function(){console.log('success')},function(){console.log('error')});
*
* The API is designed to be similar to the Cordova exec API so migration to it should be almost seamless.
* The API also provides solution to a React-Native WebView bug in iOS which causes sending consecutive postMessage calls to override each other.
@mjunaidi
mjunaidi / extract_rtf.py
Created March 30, 2019 04:34
Function to extract text in RTF files.
# -*- coding: utf-8 -*-
"""
Extract text in RTF Files. Refactored to use with Python 3.x
Source:
http://stackoverflow.com/a/188877
Code created by Markus Jarderot: http://mizardx.blogspot.com
"""
@mjunaidi
mjunaidi / rssFeed.js
Created December 23, 2018 13:15 — forked from PhilipFlyvholm/rssFeed.js
Example of RSS feed as JSON in React Native
import React from 'react';
import {StyleSheet, View, Text} from 'react-native';
export class RSSFeed extends React.Component{
constructor(props) {
super(props);
this.state = {
rss: []
};
@mjunaidi
mjunaidi / msconvert.js
Created September 15, 2018 02:34 — forked from Erichain/msconvert.js
JavaScript: Convert milliseconds to object with days, hours, minutes, and seconds
function convertMS( milliseconds ) {
var day, hour, minute, seconds;
seconds = Math.floor(milliseconds / 1000);
minute = Math.floor(seconds / 60);
seconds = seconds % 60;
hour = Math.floor(minute / 60);
minute = minute % 60;
day = Math.floor(hour / 24);
hour = hour % 24;
return {
@mjunaidi
mjunaidi / upload_demo_html.html
Created August 27, 2018 07:59 — forked from paambaati/upload_demo_html.html
Uploading files using NodeJS and Express 4
<html>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="text" name="title">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
</body>
</html>
public class SimpleRateLimiter {
private Semaphore semaphore;
private int maxPermits;
private TimeUnit timePeriod;
private ScheduledExecutorService scheduler;
public static SimpleRateLimiter create(int permits, TimeUnit timePeriod) {
SimpleRateLimiter limiter = new SimpleRateLimiter(permits, timePeriod);
limiter.schedulePermitReplenishment();
return limiter;
@mjunaidi
mjunaidi / getImages.js
Created March 22, 2018 01:43 — forked from ryuone/getImages.js
Node.js program. parseHTML and get Image files to save it.
/* node getImages.js http://www.yahoo.co.jp */
var htmlparser = require('htmlparser');
var sys = require('sys');
var http = require('http');
var fs = require('fs');
var url = require('url');
var path = require('path');
if(process.argv.length !== 3){
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@mjunaidi
mjunaidi / playground.swift
Created December 28, 2017 07:30
UIStackView + UIView test
import UIKit
var a = UIView()
var b = UIView()
var c = UIView()
a.backgroundColor = #colorLiteral(red: 0.1019607857, green: 0.2784313858, blue: 0.400000006, alpha: 1)
b.backgroundColor = #colorLiteral(red: 0.9254902005, green: 0.2352941185, blue: 0.1019607857, alpha: 1)
c.backgroundColor = #colorLiteral(red: 0.4666666687, green: 0.7647058964, blue: 0.2666666806, alpha: 1)