Skip to content

Instantly share code, notes, and snippets.

View obonyojimmy's full-sized avatar
💻
probably coding

jimmycliff obonyo obonyojimmy

💻
probably coding
View GitHub Profile
@a-h
a-h / index.js
Last active May 17, 2022 05:27
JSON logging in winston with a timestamp
const winston = require('winston');
const MESSAGE = Symbol.for('message');
const jsonFormatter = (logEntry) => {
const base = { timestamp: new Date() };
const json = Object.assign(base, logEntry)
logEntry[MESSAGE] = JSON.stringify(json);
return logEntry;
}
function fullSync(page = 1) {
let open = indexedDB.open("books", 1);
// Set up the database schema
open.onsuccess = evt => {
let db = open.result;
fullSyncPage(db, 1);
};
}
@nnnikolay
nnnikolay / fix-npm.config
Last active May 13, 2019 21:19
Not the final AWS Elastic Beanstalk deployment for NodeJS. Why not the final? some parts are missing or not tested, like configuration changes. Currently it has been tested for application deployment only.
files:
"/opt/elasticbeanstalk/env.vars":
mode: "000775"
owner: root
group: users
content: |
# enable extra logs
set -xe
# Defines variables for use by the other scripts below.
@Atinux
Atinux / async-foreach.js
Last active October 10, 2023 03:04
JavaScript: async/await with forEach()
const waitFor = (ms) => new Promise(r => setTimeout(r, ms))
const asyncForEach = async (array, callback) => {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array)
}
}
const start = async () => {
await asyncForEach([1, 2, 3], async (num) => {
await waitFor(50)
@roxlu
roxlu / CMakeLists.txt
Last active March 9, 2023 07:11
CMake example that shows how you can build Freetype2 with support for Harfbuzz and Harfbuzz with support for Freetype2. This example uses ExternalProject which is the standard way to include external dependencies. Note that we have to patch Freetype2 and Harfbuzz because their CMakelists are not fully CMake compatible (still depend on pkg-config…
# This CMake file will build Freetype and Harfbuzz as external
# projects. We follow the build description as described here:
# https://sourceforge.net/projects/freetype/files/freetype2/2.5.3/ So,
# first we build Freetype2 w/o Harfbuzz, then we build Harfbuzz with
# freetype support after which we rebuild Freetype2 again.
#
# Both CMake files of Freetype2 and Harfbuzz are depending on
# pkg-config to find the dependencies for both projects. I've
# included a patch for Freetype2 and Harfbuzz which allows you to
# build Freetype2 and Harbuzz with pure CMake features. So I removed
@lehtu
lehtu / how-to-setup-eslint-for-meteor.md
Last active October 17, 2023 06:07
How to setup eslint for Meteor project

How to setup eslint for Meteor project

Usage

  • install dependencies
  • setup .eslintrc to the root of your project
  • run eslint .

Dependencies

Install all needed dependencies

@coryhouse
coryhouse / immutableJsExample.js
Last active July 18, 2022 04:40
Handling React state via Immutable.js map
// At top, import immutable
import { Map } from 'immutable';
// Later, in constructor...
this.state = {
// Create an immutable map in state using immutable.js
user: Map({ firstName: 'Cory', lastName: 'House'})
};
updateState({target}) {
@alkrauss48
alkrauss48 / Dockerfile
Last active November 10, 2022 16:24
Running a docker container as a non-root user
# By default, Docker containers run as the root user. This is bad because:
# 1) You're more likely to modify up settings that you shouldn't be
# 2) If an attacker gets access to your container - well, that's bad if they're root.
# Here's how you can run change a Docker container to run as a non-root user
## CREATE APP USER ##
# Create the home directory for the new app user.
RUN mkdir -p /home/app
@russelldavies
russelldavies / build.sh
Created November 24, 2016 16:53
AWS Lambda Weasyprint
#!/bin/sh
mkdir task
cp build_weasyprint.sh task
docker run --rm -it -v $PWD/task:/var/task \
-e LD_LIBRARY_PATH='/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib' \
lambdalinux/baseimage-amzn build_weasyprint.sh
@jacurtis
jacurtis / _spacing-helpers.scss
Last active April 15, 2024 12:05
SASS Margin and Padding Helpers Loop. Generates .m-t-10 type helper classes.
/*
This .scss loop will create "margin helpers" and "padding helpers" for use in your web projects.
It will generate several classes such as:
.m-r-10 which gives margin-right 10 pixels.
.m-r-15 gives MARGIN to the RIGHT 15 pixels.
.m-t-15 gives MARGIN to the TOP 15 pixels and so on.
.p-b-5 gives PADDING to the BOTTOM of 5 pixels
.p-l-40 gives PADDING to the LEFT of 40 pixels