Skip to content

Instantly share code, notes, and snippets.

View lastday154's full-sized avatar

Steve Hoang lastday154

  • NIT Warangal, India
View GitHub Profile
@lastday154
lastday154 / singleton.php
Created November 22, 2017 06:34
Singleton PHP
<?php
class UserFactory
{
private function __construct()
{
}
public static function Instance()
{
@lastday154
lastday154 / factory.php
Created November 22, 2017 06:43
Factory Pattern
<?php
class Automobile
{
private $vehicleMake;
private $vehicleModel;
public function __construct($make, $model)
{
$this->vehicleMake = $make;
$this->vehicleModel = $model;
@lastday154
lastday154 / di.php
Created November 22, 2017 07:09
Dependency Injection
<?php
class Database
{
protected $adapter;
public function __construct()
{
$this->adapter = new MysqlAdapter;
}
@lastday154
lastday154 / duplicate.sql
Created November 22, 2017 08:30
Remove duplicate rows mysql
// delete With temp table
CREATE TABLE temp_users AS
SELECT * FROM users GROUP BY user_name;
DROP TABLE users;
RENAME TABLE temp_users TO users;
// delete and keep lower id
DELETE u1 FROM users u1, users u2
@lastday154
lastday154 / curl.php
Created November 23, 2017 13:25
curl request php
<?php
$ch = curl_init('https://pal-test.adyen.com/pal/servlet/Payment/v25/refund');
# Setup request to send json via POST.
$payload = '{
"merchantAccount": "ZaloraTW",
"modificationAmount": {
"currency": "TWD",
"value": 8739100.00
},
@lastday154
lastday154 / request.py
Created November 25, 2017 00:25
HTTP Request python
import requests
API_URL = 'https://en.wikipedia.org/w/api.php?action=parse&section=0&prop=text&format=json&page='
def get(topic):
r = requests.get(API_URL + topic)
return r.text
def getTopicCount(topic):
text = get(topic)
@lastday154
lastday154 / tour.cpp
Created November 25, 2017 00:43
Tournament Honestbee
#include <iostream>
#include <vector>
using namespace std;
int tour(int num_kid, int x)
{
vector<int> v;
for (int i=0; i<num_kid; i++) {
v.push_back(i);
}
@lastday154
lastday154 / missing.cpp
Created November 25, 2017 01:44
Missing interger
// you can use includes, for example:
// #include <algorithm>
#include <unordered_set>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
unordered_set<int> s;
int max = 0;
@lastday154
lastday154 / step.md
Last active December 3, 2017 01:49 — forked from evenchange4/step.md
Deploy a Express.js project on Heroku

Deploy a Express.js project on Heroku

Step by step from command line by Steve Tuan

Quick start

Change app.js to dynamic port

const PORT = process.env.PORT || 3000
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`))

@lastday154
lastday154 / notifier.js
Created December 2, 2017 12:15
Grab Notifier
class Notifier
{
constructor() {
this.events = [];
}
on(eventName, callback) {
var self = this;
this.events.push(callback);