Skip to content

Instantly share code, notes, and snippets.

View nesk's full-sized avatar

Johann Pardanaud nesk

View GitHub Profile
@nesk
nesk / MyDatabaseHelper.kt
Created June 25, 2018 17:03
Android pre-populated database (basic database helper)
package com.example.example
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
class ActsDbHelper(val context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
override fun onCreate(db: SQLiteDatabase?) {
// Nothing to do
@nesk
nesk / metadata.sql
Created June 25, 2018 16:13
Android pre-populated database (android_metadata table)
CREATE TABLE android_metadata (locale TEXT);
INSERT INTO android_metadata VALUES ("en_US");
@nesk
nesk / mapping.js
Created March 16, 2018 14:49
Mapping objects in JavaScript (Object.fromEntries + pipeline operator)
const data = {
a: 1,
b: 2,
};
const newData = Object.entries(data)
.map(([key, value]) => ({ [`_${key}`]: value + 1 }))
|> Object.fromEntries;
@nesk
nesk / mapping.js
Created March 16, 2018 14:47
Mapping objects in JavaScript (Object.fromEntries)
const data = {
a: 1,
b: 2,
};
const newData = Object.fromEntries(
Object.entries(data)
.map(([key, value]) => ({ [`_${key}`]: value + 1 }))
);
@nesk
nesk / mapping.js
Created March 16, 2018 14:40
Mapping objects in JavaScript (ES2017+)
const data = {
a: 1,
b: 2,
};
const newData = Object.entries(data)
.map(([key, value]) => ({ [`_${key}`]: value + 1 }))
.reduce((obj, item) => Object.assign(obj, item), {});
@nesk
nesk / mapping.js
Created March 16, 2018 14:40
Mapping objects in JavaScript (ES2015)
const data = {
a: 1,
b: 2,
};
const newData = Object.keys(data)
.map(key => ({ [`_${key}`]: data[key] + 1 }))
.reduce((obj, item) => Object.assign(obj, item), {});
@nesk
nesk / mapping.js
Created March 16, 2018 14:40
Mapping objects in JavaScript (ES5)
const data = {
a: 1,
b: 2,
};
const newData = Object.keys(data)
.map(function (key) {
return {
key: '_' + key,
value: data[key] + 1,
@nesk
nesk / dereferencing-method.php
Created February 1, 2018 12:06
Circular references: dereferencing method
<?php
class ParentClass
{
public function __construct()
{
$this->child = new ChildClass($this);
}
public function destroy()
@nesk
nesk / weak-references.php
Last active February 1, 2018 12:02
Circular references: weak references
<?php
class ParentClass
{
public function __construct()
{
$this->child = new ChildClass($this);
}
}
@nesk
nesk / Handler.php
Last active January 16, 2018 10:54
Laravel default error page (2/2)
<?php
/**
* Render the given HttpException.
*
* @param \Symfony\Component\HttpKernel\Exception\HttpException $e
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function renderHttpException(HttpException $e)
{