Skip to content

Instantly share code, notes, and snippets.

View HasanGokce's full-sized avatar
🎯
Focusing

Hasan Gokce HasanGokce

🎯
Focusing
View GitHub Profile
@HasanGokce
HasanGokce / index-test.js
Created December 10, 2020 06:56
With async / await
const request = require('supertest');
const app = require('../../app');
describe('the homepage', () => {
it('returns the correct content', async () => {
const response = await request(app)
.get('/')
.send();
console.log(response.text);
@HasanGokce
HasanGokce / index-test.js
Created December 10, 2020 06:51
Without async / await
const request = require('supertest');
const app = require('../../app');
describe('the homepage', () => {
it('returns the correct content', () => {
const response = request(app)
.get('/')
.send();
console.log(response.text);
@HasanGokce
HasanGokce / jsdom-test.js
Created December 10, 2020 06:19
We can use the jsdom library to improve this type of assertion. It allows us to select elements of the DOM and check relationships and content. To increase the readability of our tests, we abstracted the jsdom functionality into a custom function, parseTextFromHTML
const {assert} = require('chai');
const {jsdom} = require('jsdom');
const parseTextFromHTML = (htmlAsString, selector) => {
const selectedElement = jsdom(htmlAsString).querySelector(selector);
if (selectedElement !== null) {
return selectedElement.textContent;
} else {
throw new Error(`No element with selector ${selector} found in HTML string`);
}
@HasanGokce
HasanGokce / chai-test.js
Created December 10, 2020 06:03
In chai-test.js to the right, we’ve included Chai at the top of the file and set up a describe block with Mocha. Use Chai on line 9 to assert that the foo array contains the number 4. Use npm test to verify the test is passing.
const {assert} = require('chai');
describe('Array', () => {
describe('.pop()', () => {
it('should return a value and remove the element from the array', () => {
// setup
const foo = [4];
const includedNumber = 4;
// check setup
assert.include(foo, includedNumber);
// exercise
@HasanGokce
HasanGokce / Playlist.java
Created November 19, 2020 16:58
ArrayList Example
import java.util.ArrayList;
class Playlist {
public static void main(String[] args) {
// creating playlist
ArrayList<String> desertIslandPlaylist = new ArrayList<String>();
// adding songs to playlist
desertIslandPlaylist.add("Sneaker Pimps - Six Undergound");
@HasanGokce
HasanGokce / Store.java
Created November 16, 2020 13:32
When this runs, the command System.out.println(myCar) will print This is a red car!, which tells us about the Object myCar.
public class Store {
// instance fields
String productType;
double price;
// constructor method
public Store(String product, double initialPrice) {
productType = product;
price = initialPrice;
}
public class BankAccount {
public static void main(String[] args){
double balance = 1000.75;
double amountToWithdraw = 250;
double updatedBalance = balance - amountToWithdraw;
double amountForEachFriend = updatedBalance / 3;
boolean canPurchaseTicket = amountForEachFriend >= 25;
System.out.println(canPurchaseTicket);
System.out.println("I gave each friend " + amountForEachFriend + "...");
}
@HasanGokce
HasanGokce / settings.php
Created December 27, 2018 06:24
Options page for wordpress. Paste this code into functions.php
<?php
add_action( 'admin_menu', 'tnew_plugin_add_admin_menu' );
add_action( 'admin_init', 'tnew_plugin_settings_init' );
function tnew_plugin_add_admin_menu( ) {
add_menu_page( 'Site Bilgilerini Ayarla', 'Site Bilgileri', 'manage_options', 'tnew_theme', 'tnew_plugin_options_page' );
}
@HasanGokce
HasanGokce / archive.php
Created December 1, 2018 20:48
The template for displaying archive pages for all posts
<?php
/**
* The template for displaying archive pages for all posts
*
*/
get_header(); ?>
<div class="wrap">
@HasanGokce
HasanGokce / MainActivity.java
Created November 27, 2018 14:42
DATABASE EXAMPLE
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create new helper
DatabaseHelper dbHelper = new DatabaseHelper(getContext());
// Get the database. If it does not exist, this is where it will
// also be created.
SQLiteDatabase db = dbHelper.getWriteableDatabase();