View cache.js
const _ = require('lodash'); | |
const LRU = require('lru-cache'); | |
class Cache { | |
constructor(maxSizeInMB = 128) { | |
this.lru = new LRU({ | |
max: maxSizeInMB * 1e+6, | |
length: n => Buffer.byteLength(n, 'utf8') | |
}); | |
} |
View loader.js
export const loadScript = (id, url, test) => new Promise(resolve => { | |
let s = document.getElementById(id); | |
if (!s) { | |
s = document.createElement('script'); | |
s.setAttribute('id', id); | |
s.defer = true; | |
s.src = url; | |
document.body.appendChild(s); | |
} |
View classic solution
import React, { Component } from 'react'; | |
import { Image, Button, Icon} from 'semantic-ui-react'; | |
import Style from './card1.module.css'; | |
import Photo from '../food.jpg'; | |
class Card1 extends Component { | |
constructor(props) { | |
super(props); | |
const { |
View index.js
const Redis = require('ioredis'); | |
const redis = new Redis(); | |
exports.handler = (event, context, callback) => { | |
context.callbackWaitsForEmptyEventLoop = false; | |
redis.pipeline() | |
.set('a', 'b') | |
.get('a') | |
.exec() |
View disable-transparent-hugepages
#!/bin/bash | |
### BEGIN INIT INFO | |
# Provides: disable-transparent-hugepages | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Disable Linux transparent huge pages | |
# Description: Disable Linux transparent huge pages, to improve | |
# database performance. | |
### END INIT INFO |
View install-redis.sh
#!/bin/bash | |
############################################### | |
# To use: | |
# chmod +x install-redis.sh | |
# ./install-redis.sh | |
############################################### | |
version=3.2.0 | |
echo "*****************************************" | |
echo " 1. Prerequisites: Install updates, set time zones, install GCC and make" |
View shortcuts.json
{ | |
"beautify.config": { | |
"js": { | |
"e4x": true | |
}, | |
"css": { | |
"selector_separator_newline": true, | |
"newline_between_rules": true, | |
"preserve_newlines": true, | |
"end_with_newline": true |
View image_handler.go
package main | |
import ( | |
"bytes" | |
"encoding/base64" | |
"errors" | |
"github.com/aws/aws-lambda-go/lambda" | |
"github.com/disintegration/imaging" | |
"github.com/nickalie/go-webpbin" | |
"io/ioutil" |
View GraphQLMux.js
/* | |
Usage: | |
const http = json => fetch('http://yourGraphQLEndpoint.com', { | |
method: 'POST', | |
cache: 'no-store', | |
headers: { | |
'content-type': 'application/json' | |
}, | |
body: JSON.stringify(json) |
View Events.js
import filter from 'lodash/filter'; | |
import forEach from 'lodash/forEach'; | |
import isFunction from 'lodash/isFunction'; | |
import isString from 'lodash/isString'; | |
export default class Events { | |
constructor(persist) { | |
this._fns = []; | |
} |
NewerOlder