Skip to content

Instantly share code, notes, and snippets.

View GUIEEN's full-sized avatar
💭
美しい未来に

Seung Kwak GUIEEN

💭
美しい未来に
  • tokyo
View GitHub Profile
@GUIEEN
GUIEEN / openContentWithNewContent.js
Created December 7, 2019 06:55
Open a new tap with content JS
// https://stackoverflow.com/a/19078591
let win = window.open(
'',
'Title',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=200,top=' +
(screen.height - 400) +
',left=' +
(screen.width - 840),
);
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@GUIEEN
GUIEEN / udp.js
Created November 14, 2019 01:45 — forked from sid24rane/udp.js
Simple UDP Client and Server in Node.js ==> ( Echo Server )
var udp = require('dgram');
// --------------------creating a udp server --------------------
// creating a udp server
var server = udp.createSocket('udp4');
// emits when any error occurs
server.on('error',function(error){
console.log('Error: ' + error);
@GUIEEN
GUIEEN / instanceof vs typeof.md
Created November 12, 2019 08:39
Instance vs typeof in Javascript

Use instanceof for custom types:

var ClassFirst = function () {};
var ClassSecond = function () {};
var instance = new ClassFirst();
typeof instance; // object
typeof instance == 'ClassFirst'; // false
instance instanceof Object; // true
instance instanceof ClassFirst; // true
instance instanceof ClassSecond; // false 
@GUIEEN
GUIEEN / postgres-cheatsheet.md
Last active January 29, 2020 14:21 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet
@GUIEEN
GUIEEN / nvmCommands.js
Last active October 5, 2019 13:31 — forked from chranderson/nvmCommands.js
Useful NVM commands
// check version
node -v || node --version
// list installed versions of node (via nvm)
nvm ls
// install specific version of node
nvm install 6.9.2
// set default version of node
@GUIEEN
GUIEEN / changeName.js
Created September 27, 2019 02:28
changing multiple files' name
const fs = require('fs');
const path = require('path');
fs.readdir('./icons', (err, files) => {
if (err) {
return;
}
for (const file of files) {
console.log(file);
@GUIEEN
GUIEEN / secure.md
Last active September 23, 2019 10:46
How secure are query strings over https

http://blog.httpwatch.com/2009/02/20/how-secure-are-query-strings-over-https/

Problems of sending credentials in query

  1. URLs are stored in web server logs
  • typically the whole URL of each request is stored in a server log. This means that any sensitive data in the URL (e.g. a password) is being saved in clear text on the server. Here’s the entry that was stored in the httpwatch.com server log when a query string was used to send a password over HTTPS:
2009-02-20 10:18:27 W3SVC4326 WWW 208.101.31.210 GET /Default.htm password=mypassword 443 ...
@GUIEEN
GUIEEN / md5.md
Last active September 23, 2019 10:39
md5

Add salt at the end of the string when you're using md5

hash = md5(salt + 'xyzzy')

hash = md5('xyzzy' + salt)

Reason.

mind: point taken about md5 being 'good enough' for your purposes. yes, sha1 is cryptographically broken, move to sha512/sha256 ("sha2").

@GUIEEN
GUIEEN / MD5-based random number generator.md
Last active September 23, 2019 10:28
MD5-based random number generator

parent ref: http://www.skrenta.com/2007/08/md5_tutorial.html ref: http://www.pbm.com/dice/random.html

After becoming frustrated with the lack of a standalone, portable, decent random number generator, I decided to make one based on a one-way hash function. I chose MD5 since it is fast and free source was readily available. More cryptographically secure hash functions are available (e.g. SHA-1), but for the purposes of a rand/random/erand48 replacement, MD5 should be more than sufficient. MD5 takes an arbitrary amount of input and yields a 16 byte hash. This RNG continually MD5's a 16 byte digest, and uses the bottom N bits as the random number yielded, where N is just large enough to include the largest random number desired, e.g.:

To yield a random number between 0 and r:

         create mask which has enough bits to include all of r

(for example, if r is 100, mask would be 0x7F)