Skip to content

Instantly share code, notes, and snippets.

View luveti's full-sized avatar

luveti

  • DRM Productions Inc.
  • Ohio
View GitHub Profile
@luveti
luveti / SimpleNodeServer.js
Last active August 29, 2015 14:07
A small nodejs web server with support for evaluating javascript files in a way similar to php (files with .jss extension). This server can be run as-is without needing to install any additional packages. To run type: nodejs "server.js" "/path/to/root/folder/" "port"
var sys = require('sys'), url = require("url"), path = require("path"), fs = require("fs"),
querystring = require("querystring"), folder = "/", port = process.argv[3] || 25565;
var server = require("http").createServer(HTTP_Server).listen(parseInt(port, 10));
function HTTP_ProcessPost(request, response, callback) {
var queryData = "";
if(typeof callback !== 'function') return null;
@luveti
luveti / download_images.js
Created August 27, 2015 15:22
Download random google images in a specific format
var fs = require('fs');
var url = require('url');
var path = require("path");
var request = require('sync-request');
var base_url = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=";
function downloadImages(type) {
var res = JSON.parse(request('GET', base_url + type + '&as_filetype=' + type + '&start=' + Math.floor((Math.random() * 50) + 1)).body.toString('utf-8'));
if(res['responseData']['results']) {
var images = res['responseData']['results'];
@luveti
luveti / toggle_hosts.js
Created August 30, 2015 02:21
Enable or disable sites in /etc/hosts using nodejs
var fs = require('fs');
var sites = [
'example.com',
'test.com'
];
if(process.argv[2]) {
if(process.argv[2] == 'enable' || process.argv[2] == 'disable') {
@luveti
luveti / small_big_recursive.sh
Created June 9, 2016 22:43
Recursively find the smallest and largest file by extension, in a directory
#! /bin/bash
find "$1" -type f -name "*.$2" -printf "%s\t%p\n" | sort -n -r | tail -1;
find "$1" -type f -name "*.$2" -printf "%s\t%p\n" | sort -n | tail -1;
@luveti
luveti / pull_apk_from_android_device.sh
Created June 13, 2016 15:28
Pull APK from android device
# list all packages
adb -dshell pm list packages
# get full apk path
adb -d shell pm path <package name>
# pull it
adb pull <path to apk> <local path>
@luveti
luveti / .vimrc
Last active September 8, 2016 16:14
My .vimrc, if anyone's interested :)
" luveti - vimrc - 9/8/16
" these 4 lines are required by Vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" list our plugins, Vundle needs to be the first one
Plugin 'VundleVim/Vundle.vim'
@luveti
luveti / require.js
Created September 19, 2016 17:12
A simple require function that: takes an array of urls, fetches the code using the Fetch API, then evals them using a wrapper that exposes module.exports to the code.
function require (urls, cb) {
if (!Array.isArray(urls) && typeof urls === 'string') urls = [urls];
var modules = [];
var i = 0, next = function () {
fetch(urls[i])
.then(function (response) {
return response.text();
})
.then(function (code) {
try {
@luveti
luveti / ios_img_gen.js
Last active June 10, 2021 22:37
Generate iOS icons and splashscreen images from an svg, using nodejs and phantomjs.
#!/usr/bin/env node
const path = require("path")
const fs = require("fs")
// https://gist.github.com/luveti/67a1c93be3d58b085f6c76ae876c556c
function installDeps(deps, quiet, cb) {
const hash = require('crypto').createHash('md5').update(__filename).digest('hex')
const dir = require('os').tmpdir() + require('path').sep + hash
try {
@luveti
luveti / installDeps.js
Last active May 17, 2017 20:47
Installs node_modules into temp directory and gives you access to them. This lets you avoid needing a node_modules folder.
function installDeps(deps, quiet, cb) {
const hash = require('crypto').createHash('md5').update(__filename).digest('hex')
const dir = require('os').tmpdir() + require('path').sep + hash
try {
require('fs').mkdirSync(dir)
if (!quiet) console.log(`Created temp folder at "${dir}"`)
} catch (e) {}
try {
require('fs').writeFileSync(dir + require('path').sep + 'package.json', JSON.stringify({
name: hash, description: hash, author: hash, repository: hash, license: "ISC",
@luveti
luveti / promisifyAll.js
Created July 23, 2017 01:01
promisify an entire nodejs module using util.promisify
function promisifyAll(module, callbackParameterName) {
const util = require('util')
function isFunction(f) {
return f && Object.prototype.toString.call(f) === '[object Function]'
}
if (!callbackParameterName) callbackParameterName = 'callback'
Object.keys(module)