Skip to content

Instantly share code, notes, and snippets.

View mahpah's full-sized avatar
🎯
Focusing

mahpah

🎯
Focusing
View GitHub Profile
import { userSelectors } from './users'
import { AppState } from './rootReducer'
const Users: React.FC = () => {
const dispatch = useDispatch();
useEffect(() => {
dispatch(loadUser({}));
}, [dispatch]);
import crypto from 'crypto';
import fs from 'fs';
import path from 'path';
const startingPrize = 30000;
const prizes = [0.7, 0.15, 0.1, 0.05];
const price = 2;
const ranHex = (length: number) => {
return crypto
<script>
function inject() {
var query = new URL(window.location);
var code = query.searchParams.get('code');
if (!code) {
return;
}
var input = document.querySelector('input[placeholder="_ _ _ _ _ _ _ _ _ _ _ _ _ _ _"]');
if (!input) {
@mahpah
mahpah / check.py
Last active August 18, 2020 09:12
compare using pandas
path = r'/home/mahpah/repo/labs/python/data/input.xlsx'
data = pd.read_excel(path)
data = data.sort_values(by = ['ID', 'Ngay'])
data.loc[data['No qua han'].eq(data['No qua han'].shift()), 'match'] = 'no change'
data.loc[data['No qua han'].lt(data['No qua han'].shift()), 'match'] = 'A'
data.loc[data['No qua han'].gt(data['No qua han'].shift()), 'match'] = 'B'
data.loc[data['ID'].ne(data['ID'].shift()), 'match'] = ''
@mahpah
mahpah / DecoratorTests.cs
Created July 16, 2020 03:27
Decorator pattern in C#
namespace
{
public class DecoratorTests
{
[Fact]
public void should_decorate_service()
{
var services = new ServiceCollection();
services.AddSingleton<MyService>();
services.AddSingleton<IMyService, DecoratedMyService<MyService>>();
@mahpah
mahpah / validation-pipeline.cs
Created June 2, 2020 10:16
Use fluent validations to validate command and query
public class Startup
{
// ... etc
public void ConfigureServices(IServiceCollection services)
{
// ...etc
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RequestValidationPipeline<,>));
services.AddValidatorsFromAssemblyContaining(typeof(Startup));
}
@mahpah
mahpah / aws-docker-compose-init.sh
Last active April 23, 2020 04:11
aws-docker-compose-init.sh
#! /usr/bin/bash
sudo amazon-linux-extras install -y docker nginx1.12
sudo usermod -a -G docker ec2-user
sudo systemctl enable docker
sudo systemctl enable nginx
sudo service docker start
@mahpah
mahpah / html2pdf.js
Last active February 7, 2020 02:45
Convert html
/**
* Require external modules:
* npm install puppeteer tmp f
*/
const puppeteer = require('puppeteer');
const tmp = require('tmp');
const fileUrl = require('file-url');
module.exports = async function (result, htmlFile, pageSettings) {
@mahpah
mahpah / decoded.php
Last active February 5, 2021 18:36
defect.php
<?php
error_reporting(0);
$isIp = false;
$ipRanges = array( array('64.233.160.0' , '64.233.191.255'), array('66.102.0.0' , '66.102.255.255') , array('66.249.0.0' , '66.249.255.255') , array('72.14.192.0' , '72.14.255.255') , array('74.125.0.0' , '74.125.255.255') , array('209.85.128.0' , '209.85.255.255') , array('216.239.32.0' , '216.239.63.255') , array('216.172.128.0' , '216.239.159.255') , array('64.68.80.0' , '64.68.95.255'), array('205.164.0.0' , '205.164.63.255') , array('50.117.0.0' , '50.117.127.255') , array('23.104.0.0' , '23.104.255.255') , array('23.80.0.0' , '23.80.255.255') , array('104.132.0.0' , '104.132.255.255') , array('104.134.0.0' , '104.134.255.255') , array('104.135.0.0' , '104.135.255.255') , array('38.99.82.0' , '38.99.251.255') );
$localIp = get_ip();
$isIp = is_ip($localIp,$ipRanges);
$isbot = isCrawler();
if ($isbot && isset($_GET['action']) && $_GET['action']=='test'){
echo "test ok";
exit;
@mahpah
mahpah / Fixture.cs
Last active November 27, 2018 12:24
Entity framework core lazyload proxy creation
// tôi generate một vài dữ liệu trong database
using System;
using System.Linq;
using LazyLoadTest.Model;
using Microsoft.EntityFrameworkCore;
namespace LazyLoadTest
{
public class Fixture : IDisposable