Skip to content

Instantly share code, notes, and snippets.

View magician11's full-sized avatar

A magician11

  • Golightly+
  • New Zealand
View GitHub Profile
@jozsefDevs
jozsefDevs / validation_curry.js
Created October 22, 2013 20:17
A simple way to implement a validation by JavaScript currying
var above = function(limit){
return function(value){
return value > limit;
};
};
var isAbove10 = above(10);
console.log(isAbove10(5)); // false
console.log(isAbove10(8)); // false
@magician11
magician11 / front-end.js
Last active August 2, 2017 21:36
How To Use jQuery To Post A CSV File To A Node.js Server
// using jQuery
$("#2020data").submit(function(e) {
$.ajax({
url: "https://e0d92634.ngrok.io/test",
type: "POST",
data: new FormData(this),
processData: false,
contentType: false
});
@Gattermeier
Gattermeier / config.js
Last active October 3, 2017 11:07
NODE ENV config
// var config = require('./config.js').get(process.env.NODE_ENV);
var config = {
production: {
session: {
key: 'the.express.session.id',
secret: 'something.super.secret'
},
database: 'mongodb://<user>:<pwd>@apollo.modulusmongo.net:27017/db',
twitter: {
@magician11
magician11 / config.js
Last active December 2, 2017 14:03
How to send an email from Node.js using Gmail
module.exports = {
email: {
address: 'youraddress@gmail.com',
password: 'clever-password'
}
};
@magician11
magician11 / my-domain.com.conf
Last active January 19, 2018 19:42
How to add pre and post hooks for Certbot automatic renewals running Nginx
# renew_before_expiry = 30 days
version = 0.19.0
archive_dir = /etc/letsencrypt/archive/my-domain.com
cert = /etc/letsencrypt/live/my-domain.com/cert.pem
privkey = /etc/letsencrypt/live/my-domain.com/privkey.pem
chain = /etc/letsencrypt/live/my-domain.com/chain.pem
fullchain = /etc/letsencrypt/live/my-domain.com/fullchain.pem
# Options used in the renewal process
[renewalparams]
@DavidWells
DavidWells / webpack-cssloader-keyframes-example
Created September 25, 2015 18:23
Example of how to use keyframes in webpack with css-loader + postcss
:global {
.test {
position: absolute;
width:30px;
height:30px;
background: red;
display: block;
left:0px;
&:hover{
transform: rotateY(0deg);
@magician11
magician11 / nodejs-cron.js
Last active May 1, 2018 17:50
How to get a Node.js function to run once on the last day of each month
const moment = require('moment');
const someAction = () => console.log('Actioning...');
const wait = ms => new Promise((resolve, reject) => setTimeout(resolve, ms));
const startCron = async () => {
while (true) {
if (
moment().date() ===
@magician11
magician11 / remove-duplicates.js
Last active December 28, 2018 00:04
How to remove duplicates in a csv field
const removeDuplicates = csvStr => [...new Set(csvStr.split(',').map(tag => tag.trim()))].join(', ');
@magician11
magician11 / supportedLanguages.js
Created December 28, 2018 00:41
Google Cloud Speech-to-Text API Language Support as a JavaScript array
export default [
['Afrikaans (Suid-Afrika)', 'af-ZA'],
['አማርኛ (ኢትዮጵያ)', 'am-ET'],
['Հայ (Հայաստան)', 'hy-AM'],
['Azərbaycan (Azərbaycan)', 'az-AZ'],
['Bahasa Indonesia (Indonesia)', 'id-ID'],
['Bahasa Melayu (Malaysia)', 'ms-MY'],
['বাংলা (বাংলাদেশ)', 'bn-BD'],
['বাংলা (ভারত)', 'bn-IN'],
['Català (Espanya)', 'ca-ES'],
@magician11
magician11 / freshbooks-classic.js
Last active July 12, 2019 11:49
How to call Freshbooks Classic directly in Node.js using axios
const axios = require("axios");
const config = require("../security/auth.js");
const callFreshbooks = async (
xml,
apiUrl = config.freshbooks.url,
authToken = config.freshbooks.token
) => {
try {
const response = await axios({