Skip to content

Instantly share code, notes, and snippets.

View DavidMellul's full-sized avatar

David Mellul DavidMellul

View GitHub Profile
// Hypothetical NLP function - ES6 includes used
function isTextFunEnough(text) {
if(text.length == 0 || text.includes('angry'))
return false;
return text.includes('lol');
}
console.log(isTextFunEnough('This article is so epic lol') ? 'Definitely fun, LMAO':'Not very funny...');
// => Definitely fun, LMAO
// Using ES6 arrow functions
// Returns true if all even numbers doubled from @numbers are above 5
function doubleEvenNumbersES6(numbers) {
return numbers.filter(x => x % 2 == 0).map(x => x*2).every(x => x > 5);
}
console.log(doubleEvenNumbersES6([3,4,5,6]))
// => True, because doubled array is [8,12]
// Using ES6 arrow functions
// Returns true if all even numbers doubled from @numbers are above 5
function doubleEvenNumbers(numbers) {
return numbers
.filter(x => x % 2 == 0) // Odd numbers removed
.map(x => x*2) // Even numbers doubled
.every(x => x > 5); // Are they all above 5 ?
}
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// Stuff
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
function Champion(category = 'Champion') {
this.category = category;
};
function Warrior() {
Champion.call(this,'Warrior');
}
function Dwarf() {
Champion.call(this,'Dwarf');
function Champion(category = 'Champion') {
this.category = category;
this.sayHi = function() { console.log(`Hey, a ${this.category} is here`) };
};
function Warrior() {
Champion.call(this,'Warrior');
}
function Dwarf() {
// A dead-easy data structure representing a database
let ArticlesDatabase = {
articles: [
{
'id': 1,
'title': 'Insane prank, I broke my leg watch this'
},
{
'id': 2,
'title': 'Cops arrested me, discover why'
// A dead-easy data structure representing a database
let ArticlesDatabase = {
content: [
{
'id': 1,
'title': 'Insane prank, I broke my leg watch this'
},
{
'id': 2,
'title': 'Cops arrested me, discover why'
<?php
// CodeIgniter coding style with plain queries, easy to read
$users = $this->db->query('SELECT * FROM Users')->result();
$cities = $this->db->query('SELECT * FROM Cities')->result();
$usersWithCity = $this->db->query('SELECT U.*, C.city_name FROM Users U LEFT JOIN Cities C ON U.id_user = C.id_user')->result();
<?php
// Could have broken request clauses line by line
// SELECT X FROM Y WHERE Z
// ->
// SELECT X
// FROM Y
// WHERE Z
final class RequestHolder {
// Query a list of users without ordering