Last active
May 26, 2025 02:09
-
-
Save ans-4175/c799651a8e757c468efb to your computer and use it in GitHub Desktop.
Smol App
This file contains hidden or 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
/** | |
* Determine if the session and input CSRF tokens match. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return bool | |
*/ | |
protected function tokensMatch($request) | |
{ | |
$sessionToken = $request->session()->token(); | |
$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN'); | |
if (! $token && $header = $request->header('X-XSRF-TOKEN')) { | |
$token = $this->encrypter->decrypt($header); | |
} | |
if (! is_string($sessionToken) || ! is_string($token)) { | |
return false; | |
} | |
return hash_equals($sessionToken, $token); | |
} |
This file contains hidden or 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
var FCM = require('fcm-push-notif'); | |
var serverKey = 'firebase_server_key'; | |
var fcm = new FCM(serverKey); | |
var message = { | |
to: '/topics/news', // required could be topic url or device registration token | |
collapse_key: 'your_collapse_key', | |
data: { | |
message: 'This is data message' | |
}, | |
notification: { | |
title: 'Test', | |
body: 'test message' | |
} | |
}; | |
fcm.send(message) | |
.then(function(response){ | |
console.log("Successfully sent with response: ", response); | |
}) | |
.catch(function(err){ | |
console.log("Something has gone wrong!"); | |
console.error(err); | |
}) |
This file contains hidden or 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
const request = require('request'); | |
const Promise = require('bluebird'); | |
const cheerio = require('cheerio'); | |
const fs = require("node-fs-extra"); | |
const ThrottleEngine = require("throttle-exec"); | |
const maximumProcess = 10; | |
const throttleInstanceAuthor = new ThrottleEngine(maximumProcess) | |
const throttleInstanceBooks = new ThrottleEngine(maximumProcess) | |
const punctuationRegEx = /[!-/:-@[-`{-~¡-©«-¬®-±´¶-¸»¿×÷˂-˅˒-˟˥-˫˭˯-˿͵;΄-΅·϶҂՚-՟։-֊־׀׃׆׳-״؆-؏؛؞-؟٪-٭۔۩۽-۾܀-܍߶-߹।-॥॰৲-৳৺૱୰௳-௺౿ೱ-ೲ൹෴฿๏๚-๛༁-༗༚-༟༴༶༸༺-༽྅྾-࿅࿇-࿌࿎-࿔၊-၏႞-႟჻፠-፨᎐-᎙᙭-᙮᚛-᚜᛫-᛭᜵-᜶។-៖៘-៛᠀-᠊᥀᥄-᥅᧞-᧿᨞-᨟᭚-᭪᭴-᭼᰻-᰿᱾-᱿᾽᾿-῁῍-῏῝-῟῭-`´-῾\u2000-\u206e⁺-⁾₊-₎₠-₵℀-℁℃-℆℈-℉℔№-℘℞-℣℥℧℩℮℺-℻⅀-⅄⅊-⅍⅏←-⏧␀-␦⑀-⑊⒜-ⓩ─-⚝⚠-⚼⛀-⛃✁-✄✆-✉✌-✧✩-❋❍❏-❒❖❘-❞❡-❵➔➘-➯➱-➾⟀-⟊⟌⟐-⭌⭐-⭔⳥-⳪⳹-⳼⳾-⳿⸀-\u2e7e⺀-⺙⺛-⻳⼀-⿕⿰-⿻\u3000-〿゛-゜゠・㆐-㆑㆖-㆟㇀-㇣㈀-㈞㈪-㉃㉐㉠-㉿㊊-㊰㋀-㋾㌀-㏿䷀-䷿꒐-꓆꘍-꘏꙳꙾꜀-꜖꜠-꜡꞉-꞊꠨-꠫꡴-꡷꣎-꣏꤮-꤯꥟꩜-꩟﬩﴾-﴿﷼-﷽︐-︙︰-﹒﹔-﹦﹨-﹫!-/:-@[-`{-・¢-₩│-○-�]|\ud800[\udd00-\udd02\udd37-\udd3f\udd79-\udd89\udd90-\udd9b\uddd0-\uddfc\udf9f\udfd0]|\ud802[\udd1f\udd3f\ude50-\ude58]|\ud809[\udc00-\udc7e]|\ud834[\udc00-\udcf5\udd00-\udd26\udd29-\udd64\udd6a-\udd6c\udd83-\udd84\udd8c-\udda9\uddae-\udddd\ude00-\ude41\ude45\udf00-\udf56]|\ud835[\udec1\udedb\udefb\udf15\udf35\udf4f\udf6f\udf89\udfa9\udfc3]|\ud83c[\udc00-\udc2b\udc30-\udc93]/g; | |
// createDir | |
function createDir(dirName) { | |
return new Promise((resolve) => { | |
if (fs.existsSync(dirName) === false) { | |
fs.mkdir(dirName, (err) => { | |
resolve(dirName); | |
}); | |
} else { | |
resolve(dirName); | |
} | |
}); | |
} | |
// write to file | |
function writeToFile(filePath, content) { | |
return new Promise((resolve, reject) => { | |
console.log('writing to:', filePath); | |
fs.writeFile(filePath, content, (err) => { | |
if (err) { | |
reject(console.error(err)); | |
} | |
resolve(filePath); | |
}); | |
}); | |
} | |
// HOME | |
function getAll() { | |
return new Promise((resolve) => { | |
request({ | |
method: 'GET', | |
url: 'http://kepadapuisi.blogspot.co.id/' | |
}, function(err, response, body) { | |
if (err) return console.error(err); | |
// Tell Cherrio to load the HTML | |
const urls = []; | |
$ = cheerio.load(body); | |
$('#Label1 div ul li').each(function() { | |
const href = $('a', this).attr('href'); | |
if (typeof href !== 'undefined') { | |
if(urls.indexOf(href) === -1) { | |
urls.push(href); | |
} | |
} | |
}); | |
resolve(urls); | |
}); | |
}); | |
} | |
// BOOKS | |
function getAuthors(url) { | |
return new Promise((resolve) => { | |
console.log(`Processing ${url}`); | |
const urlSplit = url.split('/'); | |
const authName = (urlSplit[urlSplit.length - 1] !== '') ? urlSplit[urlSplit.length - 1] : urlSplit[urlSplit.length - 2]; | |
request({ | |
method: 'GET', | |
url: url | |
}, function(err, response, body) { | |
if (err) return console.error(err); | |
// Tell Cherrio to load the HTML | |
const urls = []; | |
$ = cheerio.load(body); | |
$('#Blog1 div.blog-posts.hfeed div').each(function() { | |
const href = $('div div div h3 a', this).attr('href'); | |
if (typeof href !== 'undefined') { | |
if(urls.indexOf(href) === -1) { | |
urls.push(href); | |
} | |
} | |
}); | |
resolve({ | |
urls: urls, | |
authName: authName, | |
}); | |
}); | |
}); | |
} | |
const throttledGetAuthors = throttleInstanceAuthor.wrap(getAuthors); | |
// BOOK | |
function getBook(url, authName) { | |
return new Promise((resolve) => { | |
console.log(`Getting books ${authName}_${url}`); | |
request({ | |
method: 'GET', | |
url: url | |
}, function(err, response, body) { | |
if (err) return console.error(err); | |
// Tell Cherrio to load the HTML | |
const texts = []; | |
$ = cheerio.load(body); | |
$('.post-body div span').each(function() { | |
let text = $(this).html(); | |
if (typeof text !== 'undefined' && (text.indexOf('<') === -1) && (text.indexOf('&#') === -1)) { | |
text = text.trim(); | |
text = text.replace(/(\r\n|\n|\r)/gm," ").replace(punctuationRegEx, '').replace(/(\s){2,}/g, '$1'); | |
if (text !== '') texts.push(text.toLowerCase()); | |
} | |
}); | |
// write to text | |
const urlParts = url.split('/'); | |
const urlEnd = (urlParts[urlParts.length - 1] !== '') ? urlParts[urlParts.length - 1] : urlParts[urlParts.length - 2]; | |
const fileSplit = urlEnd.split('.'); | |
const fileName = fileSplit[0]; | |
const dirName = (authName) ? `${__dirname}/poets/${authName}` : `${__dirname}/poets/`; | |
const filePath = `${dirName}/${fileName}`; | |
if (texts.length) { | |
createDir(dirName).then(() => { | |
resolve(writeToFile(filePath, texts.join("\n"))); | |
}); | |
} else { | |
resolve(filePath); | |
} | |
}); | |
}); | |
} | |
const throttledGetBook = throttleInstanceBooks.wrap(getBook); | |
getAll() | |
.then((urls) => { | |
urls.forEach((url) => { | |
throttledGetAuthors(url) | |
.then((obj) => { | |
const authName = obj.authName; | |
obj.urls.forEach((url) => { | |
throttledGetBook(url, authName); | |
}); | |
}) | |
}); | |
}) |
This file contains hidden or 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
object HelloWorld { | |
def main(args: Array[String]) { | |
val listKopi = List("Noah’s Barn Coffenery","Two Hands Full","Yellow Truck","Jack Runner Roastery","Kopi Anjis","Blue Doors","Rumah kopi","Cups Coffee & Kitchen","Kopi Lamping","Lacamera Coffee","Two Cents","Kopi Selasar Sunaryo","Kopi Gesang Café","Kedai Kopi Mata Angin","Kopi Ireng","Coffe And John") | |
val r = scala.util.Random | |
println(listKopi(r.nextInt(listKopi.size))) | |
} | |
} |
This file contains hidden or 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
const charset = "abcdefghijklmnopqrstuvwxyz"; | |
const consonantset = "bcdfghjklmnpqrstvwxyz"; | |
const vocalset = "aiueo"; | |
const VOCAL_TYPE = "vocal"; | |
const CONSONANT_TYPE = "const"; | |
const NUM_TYPE = "num"; | |
const MUTATE_THRESHOLD_LETTERS = 0.9696; | |
const MUTATE_THRESHOLD_CASES = 0.8686; | |
const checkGeneType = (char) => { | |
if (vocalset.includes(char)) | |
return VOCAL_TYPE; | |
else if (consonantset.includes(char)) | |
return CONSONANT_TYPE; | |
else | |
return NUM_TYPE; | |
} | |
const pickOneRandom = (arr) => { | |
return arr[Math.floor(Math.random() * arr.length)]; | |
} | |
function pickNRandom(arr, n) { | |
let result = new Array(n), | |
len = arr.length, | |
taken = new Array(len); | |
if (n > len) | |
throw new RangeError("getRandom: more elements taken than available"); | |
while (n--) { | |
const x = Math.floor(Math.random() * len); | |
result[n] = arr[x in taken ? taken[x] : x]; | |
taken[x] = --len in taken ? taken[len] : len; | |
} | |
return result; | |
} | |
const generateChromosome = (chromLength) => { | |
return [...Array(chromLength)] | |
.map((_) => charset[Math.floor(Math.random() * charset.length)]) | |
.join(""); | |
} | |
const checkFitnessScore = (chromosome) => { | |
// rule1: consonant or vocal cannot be in double occurences sequentially | |
let score = 10 * chromosome.length; | |
let lastGeneType = ""; | |
let lastGeneSeqCount = 1; | |
chromosome.split("").forEach(gene => { | |
if (checkGeneType(gene) === lastGeneType) ++lastGeneSeqCount; | |
if (lastGeneSeqCount > 1) { | |
score = score - 10; | |
lastGeneSeqCount = 1; | |
} | |
lastGeneType = checkGeneType(gene); | |
}); | |
return score; | |
} | |
const mutateCases = (chromosome) => { | |
return chromosome.split("").map(gene => { | |
return (Math.random() < MUTATE_THRESHOLD_CASES ? gene.toLowerCase() : gene.toUpperCase()); | |
}).join(""); | |
} | |
const mutationLetters = (gene) => { | |
switch (gene.toLowerCase()) { | |
case "i": | |
return "1"; | |
case "r": | |
return "2" | |
case "e": | |
return "3" | |
case "a": | |
return "4" | |
case "s": | |
return "5" | |
case "g": | |
return "6" | |
case "z": | |
return "7" | |
case "b": | |
return "8" | |
case "q": | |
return "9" | |
default: | |
return gene | |
} | |
} | |
const mutateLetters = (chromosome) => { | |
return chromosome.split("").map(gene => { | |
return (Math.random() < MUTATE_THRESHOLD_LETTERS ? gene : mutationLetters(gene)); | |
}).join(""); | |
} | |
const geneticProcess = (firstGenes, secondGenes) => { | |
// breed new crossover | |
const randXOver = Math.ceil(Math.random() * firstGenes.length); | |
const firstHalfFront = firstGenes.slice(0, randXOver); | |
const firstHalfLast = firstGenes.slice(randXOver, firstGenes.length); | |
const secondHalfFront = secondGenes.slice(0, randXOver); | |
const secondHalfLast = secondGenes.slice(randXOver, secondGenes.length); | |
let firstXOver = [...firstHalfFront, ...secondHalfLast].join(""); | |
let secondXOver = [...secondHalfFront, ...firstHalfLast].join(""); | |
// mutate letters to numbers | |
firstXOver = mutateLetters(firstXOver); | |
secondXOver = mutateLetters(secondXOver); | |
// mutate cases | |
firstXOver = mutateCases(firstXOver); | |
secondXOver = mutateCases(secondXOver); | |
if (checkFitnessScore(firstXOver) > checkFitnessScore(secondXOver)) | |
return firstXOver | |
else | |
return secondXOver; | |
} | |
const survivalFittest = (population, maxPopulation) => { | |
return population.sort((a,b) => { | |
return checkFitnessScore(b) - checkFitnessScore(a); | |
}).slice(0, maxPopulation); | |
} | |
const generatePasswords = ({ | |
chromosomeLength = 12, maxPopulation = 33, | |
generations = 20, pickCount = 1 | |
}) => { | |
// logic password generator, by genetic programming | |
// initialize population by random chars | |
let population = [...Array(maxPopulation)].map((_) => generateChromosome(chromosomeLength)); | |
population = survivalFittest(population); | |
let currGeneration = 0; | |
while (currGeneration <= generations) { | |
// prepare population to be mated | |
const half = Math.ceil(population.length / 2); | |
const firstHalf = population.slice(0, half); | |
const secondHalf = population.slice(-half); | |
// breeding new | |
firstHalf.forEach(candidate => { | |
population.push(geneticProcess(candidate, pickOneRandom(secondHalf))); | |
}); | |
// sort by fitness score | |
population = survivalFittest(population, maxPopulation); | |
currGeneration++; | |
} | |
// pick population | |
return pickNRandom(population, pickCount); | |
} | |
(async () => { | |
const pickedPasswords = generatePasswords({}); | |
console.log(pickedPasswords); | |
})(); |
This file contains hidden or 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
#!/bin/bash | |
wget --no-check-certificate --quiet \ | |
--method POST \ | |
--timeout=0 \ | |
--server-response \ | |
--header 'Cookie: PHPSESSID=<value_from_web_cookies>' \ | |
--body-data 'latitude=YGLhZGpjZmL1AwLlAGD2Amx1&longitude=ZGN2YwtlAQRkAmp4ZGxlAQLk&status=checkin&description=hi from Indonesia' \ | |
'https://hr.talenta.co/api/web/live-attendance/request' 2>&1 | grep "HTTP/1.1" | |
# run with `sh talenta-clock-in.sh` |
This file contains hidden or 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
var ThrottleEngine = require("throttle-exec") | |
var Promise = require("when/es6-shim/Promise") | |
var Request = require("request") | |
var throttlingCount = 10 | |
var ThrottleInstance = new ThrottleEngine(throttlingCount) | |
var Engine = function(param){ | |
return ThrottleInstance.registerAction("request",[param]) | |
} | |
function createRequest(param){ | |
return new Promise(function(resolve,reject){ | |
Request(param,function(err,response,body){ | |
if(!err){ | |
resolve({ | |
response:response, | |
body:body | |
}) | |
}else{ | |
reject(new Error(err)) | |
} | |
}) | |
}) | |
} | |
ThrottleInstance.registerFunction("request",createRequest) | |
module.exports = Engine; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment