Skip to content

Instantly share code, notes, and snippets.

@dinh
dinh / useful-one-liners.sh
Created May 20, 2023 18:38 — forked from modem7/useful-one-liners.sh
Useful one liners
# Run the last command as root
sudo !!
# Serve current directory tree at http://$HOSTNAME:8000/
python -m SimpleHTTPServer
# Save a file you edited in vim without the needed permissions
:w !sudo tee %
# change to the previous working directory
cd -
# Runs previous command but replacing
^foo^bar
@dinh
dinh / 00-OozieWorkflowJavaMapReduceAction
Created February 23, 2023 20:19 — forked from airawat/00-OozieWorkflowJavaMapReduceAction
Oozie workflow application with a Java Mapreduce action that parses syslog generated log files and generates a report Gist includes sample data, all workflow components, java mapreduce program code, commands - hdfs and Oozie
This gist includes components of a oozie workflow - scripts/code, sample data
and commands; Oozie actions covered: java mapreduce action; Oozie controls
covered: start, kill, end; The java program uses regex to parse the logs, and
also extracts the path of the mapper input directory path and includes in the
key emitted.
Note: The reducer can be specified as a combiner as well.
Usecase
-------
@dinh
dinh / name-shortening functions.js
Created February 18, 2023 12:40 — forked from nilsandrey/name-shortening functions.js
Name-shortening functions from Hacker News own JS for web site
// From yesenadam at https://news.ycombinator.com/item?id=23590848
function $(id) { return document.getElementById(id); }
function byClass (el, cl) { return el ? el.getElementsByClassName(cl) : [] }
function byTag (el, tg) { return el ? el.getElementsByTagName(tg) : [] }
function allof (cl) { return byClass(document, cl) }
function hasClass (el, cl) { var a = el.className.split(' '); return afind(cl, a) }
function addClass (el, cl) { if (el) { var a = el.className.split(' '); if (!afind(cl, a)) { a.unshift(cl); el.className = a.join(' ')}} }
function remClass (el, cl) { if (el) { var a = el.className.split(' '); arem(a, cl); el.className = a.join(' ') } }
function html (el) { return el ? el.innerHTML : null; }
@dinh
dinh / bookmarkleting.md
Created January 31, 2023 10:28 — forked from caseywatts/bookmarkleting.md
Making Bookmarklets

This is one chapter of my "Chrome Extension Workshops" tutorial, see the rest here: https://gist.github.com/caseywatts/8eec8ff974dee9f3b247

Unrelated update: my book is out! Debugging Your Brain is an applied psychology / self-help book

Making Bookmarklets

I'm feeling very clever. I've got this sweet line of javascript that replaces "cloud" with "butt". My mom would LOVE this, but she doesn't computer very well. I'm afraid to show her the Developer Console and have her type/paste this in. But she IS pretty good at bookmarks, she knows just how to click those!

A bookmark normally takes you to a new web page. A bookmarklet is a bookmark that runs javascript on the current page instead of taking you to a new page. To declare that it is a bookmarklet, the "location" it points to starts with javascript:.

@dinh
dinh / torrent.py
Created January 28, 2023 10:19 — forked from hannes/torrent.py
Create and query a local search engine for PirateBay torrents
#!/usr/bin/env python3
import sqlite3 # yay SQLite!
import base64
import os
import sys
if sys.version_info<(3,6,0):
print("You need python 3.6 or later to run this script.")
exit(-1)
@dinh
dinh / Main.java
Created January 24, 2023 21:32 — forked from smac89/Main.java
Read a large json file, but do so lazily so as to not use too much memory. Thanks to Java 8 streams, this is quite possible
import com.google.common.io.Resources;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonObject;
import java.io.IOException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
@dinh
dinh / _no_code_page_.php
Created January 11, 2023 21:05 — forked from Dan-Q/_no_code_page_.php
Hacky PHP to produce a "blank" web page which somehow has content when viewed in Firefox. Sample page at https://danq.me/wp-content/no-code-webpage/, explanation at https://danq.me/nocode
<?php
// half-hearted CSS minification
$css = preg_replace(
array('/\s*(\w)\s*{\s*/','/\s*(\S*:)(\s*)([^;]*)(\s|\n)*;(\n|\s)*/','/\n/','/\s*}\s*/'),
array('$1{ ','$1$3;',"",'} '),
file_get_contents('linked.css')
);
// embed as a data: uri
$base64css = rtrim(strtr(base64_encode($css), '+/', '-_'), '=');
@dinh
dinh / index.html
Created January 8, 2023 21:28
Voice Search with JavaScript (Web Speech API)
<div class="container">
<form action="https://www.google.com/search" method="get" target="_blank" id="search-form">
<input name="q" type="text" placeholder="Search Google..." autocomplete="off" autofocus>
<!-- <button type="button"><i class="fas fa-microphone"></i></button> -->
</form>
<p class="info"></p>
</div>
@dinh
dinh / index.html
Created January 8, 2023 21:23 — forked from praveenrambalu/index.html
Speech to Color Changer
<script src="main.js"></script>
<link rel="stylesheet" href="main.css">
<h1>Say Color:</h1>
<div class="color-cube">
<div class="circle outer">
<div class="circle inner"></div>
</div>
</div>