Skip to content

Instantly share code, notes, and snippets.

View DavidTPate's full-sized avatar

David Pate DavidTPate

  • Denver
View GitHub Profile
@DavidTPate
DavidTPate / Express-Morgan-JSON.js
Last active July 27, 2023 13:53
A gist which shows how to run Morgan in Express with output in JSON
const express = require('express');
const app = express();
const morgan = require('morgan');
const port = 3000;
// Define your morgan logger to log JSON to your client
// The object here takes your keys and strings that use
// the morgan token format
app.use(morgan(format({
response_time: ':response-time',
([]+[][+[]])[+!+[]+!+[]+!+[]+!+[]+!+[]][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+![])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]]+([]+!![])[+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+!![])[+!+[]]][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+![])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]]+([]+!![])[+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+!![])[+!+[]]](([]+!![])[+!+[]]+([]+[][+[]])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]+!+[]]+([]+!![])[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[])[([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wemakestuff.autoanswer"
android:versionCode="1"
android:versionName="0.1" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
public class PhoneAnswerIntentService extends IntentService {
/**
* Creates an IntentService. Invoked by the parent class's constructor.
*/
public PhoneAnswerIntentService() {
super("PhoneAnswerIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
public class PhoneStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Check phone state
String currentPhoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
// If the phone is ringing
if (currentPhoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
// If the phone is already in a call, ignore this call.
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
public class OnDemandSingleton {
private OnDemandSingleton() { }
private static class OnDemandSingletonHolder {
public static final OnDemandSingleton instance = new OnDemandSingleton();
}
public static OnDemandSingleton getInstance() {
return OnDemandSingletonHolder.instance;
}
public class EagerStaticSingleton {
private static EagerStaticSingleton instance = null;
private EagerStaticSingleton() { }
static {
try {
instance = new EagerStaticSingleton();
} catch (Exception e) {
// Do something
public class EagerSingleton {
private static final EagerSingleton instance = new EagerSingleton();
private EagerSingleton() { }
public static EagerSingleton getInstance() {
return instance;
}
}
public class LazySingleton {
private static LazySingleton instance = null;
private LazySingleton() { }
public static synchronized LazySingleton getInstance() {
if (instance == null) {
instance = new LazySingleton();
}
return instance;
// Using the Telescoping Constructor anti-pattern
Car carSearchCriteria = new Car(1998, null, "Focus", "Sedan");
// Using the Builder Pattern
Car carSearchCriteria = new Car.Builder().year(1998)
.model("Focus")
.carType("Sedan")
.build();