This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function forEach(array, action) { | |
for (var i = 0; i < array.length; i++) | |
action(array[i]); | |
} | |
// Example | |
function sum(numbers) { | |
var total = 0; | |
forEach(numbers, function (number) { | |
total += number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$to = "dangtruong@gmail.com"; | |
$header = "From: {$to}"; | |
$subject = "Hi!"; | |
$body = "Hi,\n\nHow are you?"; | |
if (mail($to, $subject, $body, $header)) { | |
echo("<p>Message successfully sent!</p>"); | |
} else { | |
echo("<p>Message delivery failed...</p>"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Profile(models.Model): | |
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) | |
date_of_birth = models.DateField(blank=True, null=True) | |
photo = models.ImageField(upload_to='users/%Y/%m/%d/', default='/default_avatar.png', blank=True) | |
def __str__(self): | |
return f'Profile for user {self.user.username}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProfileEditForm(forms.ModelForm | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.fields['photo'].widget.template_name = 'core/widgets/photo.html' | |
class Meta: | |
model = Profile | |
fields = ('date_of_birth', 'photo') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
{% if widget.is_initial %} | |
<a href="{{ widget.value.url }}"><img src="{{ widget.value.url }}" width="auto" height="auto" alt="" /></a> | |
{% if not widget.required %} | |
<br /> | |
{{ widget.clear_checkbox_label }}:<input type="checkbox" name="{{ widget.checkbox_name}}" id="{{ widget.checkbox_id }}"> | |
{% endif %}<br /> | |
{{ widget.input_text }}: | |
{% endif %} | |
<br /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore } from "vuex"; | |
import axios from "axios"; | |
const api = axios.create({ | |
baseURL: "https://hacker-news.firebaseio.com/v0/", | |
}); | |
export default createStore({ | |
state: { | |
items: [], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div v-if="items.length"> | |
<div class="rounded-md bg-blue-50 px-3 py-1 my-1 h-auto" v-for="item in items" :key="item.id"> | |
<div class="flex flex-wrap"> | |
<a class="flex-auto font-sans text-black" target="blank" :href="item.url">{{ item.title }}</a> | |
<div class="text-sm font-medium text-gray-500">{{ item.time }}</div> | |
<div class="w-full flex-nonefont-semibold text-yellow-500 mt-2">{{ item.by }}</div> | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="container mx-auto px-4 text-left py-10"> | |
<div class="flex"> | |
<div class="flex-auto"> | |
<h1 class="text-red-500 text-3xl">Latest</h1> | |
<Stories :items="items"></Stories> | |
</div> | |
<div class="flex-auto"></div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(true ?? "not defined") // true | |
console.log(false ?? "not defined") // false | |
console.log(undefined ?? "not defined") // "not defined" | |
console.log(null ?? "not defined") // "not defined" | |
//Compared with the OR operator || | |
console.log(true || "not defined") // true | |
console.log(false || "not defined") // "not defined" | |
console.log(undefined || "not defined") // "not defined" | |
console.log(null || "not defined") // "not defined" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Callback Function Example | |
function greet(name, myFunction) { | |
console.log("Hello World"); | |
// execute callback function only after the greet() is executed | |
myFunction(name); | |
} | |
// callback function | |
function callNameBack(name) { | |
// calling the function after 2 seconds |
OlderNewer