Skip to content

Instantly share code, notes, and snippets.

@ceilfors
ceilfors / env.js
Created July 5, 2018 06:21
better-dependency-injection-with-laconia
const handler = ({ env }) => { console.log(env.MY_ENV_VAR); };
@ceilfors
ceilfors / event-context.js
Created July 5, 2018 06:21
better-dependency-injection-with-laconia
const handler = ({ event, context }) => {};
@ceilfors
ceilfors / lambda.spec.js
Created July 5, 2018 06:18
better-dependency-injection-with-laconia
const { handler } = require("./lambda");
let twitterService;
beforeEach(() => {
// Creates a mocked twitterService
twitterService = {
getLatestTweets: jest.fn().mockReturnValue(Promise.resolve())
};
});
@ceilfors
ceilfors / lambda.js
Last active September 10, 2018 06:16
better-dependency-injection-with-laconia
const laconia = require("@laconia/core");
// Creates the dependencies
const instances = async () => {
const password = await getPassword();
return { twitterService: new TwitterService(password) };
};
// Declare the dependency you need by destructuring
const handler = ({ twitterService }) => {
@ceilfors
ceilfors / cleanupUnusedWorkspaceInSlaves.groovy
Last active September 9, 2024 12:46
When you delete jobs in Jenkins, the corresponding workspaces in the build slaves won't be deleted automatically. This Jenkins script will go to each slave and check if the jobs are already deleted in Jenkins master and delete the workspace.
import com.cloudbees.hudson.plugins.folder.Folder
import hudson.FilePath
import jenkins.model.Jenkins
def boolean isFolder(String name) {
def item = Jenkins.instance.getItemByFullName(name)
return item instanceof Folder
}
def deleteUnusedWorkspace(FilePath root, String path) {
@ceilfors
ceilfors / externals.py
Last active October 12, 2016 18:21
Python script to extract all of the svn:externals in a SVN path recursively.
"""
This script is adapted from http://stackoverflow.com/a/10286163/2464295 but without the
multi threading factor of it.
Usage: `externals.py https://svn-server/repository`
Do note that the script is excluding src and hidden directories that starts with dot. Just modify the file
as it's not parameterized.
If you want this script to run faster, SSH to the SVN server and use file protocol.
Usage: `externals.py file:///svn/repository`
@ceilfors
ceilfors / settings-xml.py
Created July 9, 2014 09:31
A simple script to provide multiple profiles for your maven settings at {user.home}/.m2/settings.xml. See description in the python file below for details.
description = """A simple script to provide multiple profiles for your maven settings at {user.home}/.m2/settings.xml.
With the folder structure like below, profile [home] and [work] will be available be used.
{user.home}/.m2/profile
|-home
| |-settings.xml
|-work
| |-settings.xml
"""
import argparse, os, shutil
@ceilfors
ceilfors / ssh-copy-id.py
Last active June 3, 2023 01:48
ssh-copy-id for Windows
"""ssh-copy-id for Windows.
Example usage: python ssh-copy-id.py ceilfors@my-remote-machine
This script is dependent on msysgit by default as it requires scp and ssh.
For convenience you can also try that comes http://bliker.github.io/cmder/.
"""
import argparse, os
from subprocess import call
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>playground</groupId>
<artifactId>testant</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<build>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>playground</artifactId>
<groupId>playground</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>