Skip to content

Instantly share code, notes, and snippets.

View ppalone's full-sized avatar
🎯
Focusing

Pranjal Alone ppalone

🎯
Focusing
View GitHub Profile
@tetsuok
tetsuok / fibonacci_closure.go
Created April 2, 2012 08:48
An answer of the exercise: Fibonacci closure on a tour of Go
package main
import "fmt"
// Very naive answer.
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
n := 0
a := 0
@lovasoa
lovasoa / node-walk.es6
Last active May 10, 2024 05:30
Walk through a directory recursively in node.js.
// ES6 version using asynchronous iterators, compatible with node v10.0+
const fs = require("fs");
const path = require("path");
async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) yield* walk(entry);
else if (d.isFile()) yield entry;
@joshnuss
joshnuss / app.js
Last active March 4, 2024 00:01
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@gophertron
gophertron / weboauth.go
Last active November 25, 2023 06:36
github oauth gorilla
package main
import (
"fmt"
"log"
"net/http"
"github.com/codegangsta/negroni"
gh "github.com/google/go-github/github"
"github.com/gorilla/mux"
@inotnako
inotnako / server.go
Last active August 29, 2023 11:38
get meta from html page
package main
import (
"encoding/json"
"net/http"
"net/url"
"golang.org/x/net/html"
"io"
)
@sebble
sebble / stars.sh
Last active May 17, 2024 20:59
List all starred repositories of a GitHub user.
#!/bin/bash
USER=${1:-sebble}
STARS=$(curl -sI https://api.github.com/users/$USER/starred?per_page=1|egrep '^Link'|egrep -o 'page=[0-9]+'|tail -1|cut -c6-)
PAGES=$((658/100+1))
echo You have $STARS starred repositories.
echo
@tzmartin
tzmartin / m3u8-to-mp4.md
Last active May 18, 2024 19:05
m3u8 stream to mp4 using ffmpeg

1. Copy m3u8 link

Alt text

2. Run command

echo "Enter m3u8 link:";read link;echo "Enter output filename:";read filename;ffmpeg -i "$link" -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 $filename.mp4
@LunaSquee
LunaSquee / queue.js
Last active February 16, 2023 01:52
Liquidsoap radio + youtube-dl queueing (Node.js as helper)
// $ node queue <file name or youtube URL>
const net = require('net')
let client = net.connect(1234, 'localhost')
client.on('connect', function () {
if (process.argv[2]) {
console.log('Queueing ' + process.argv[2])
client.write('queue.push smart:' + process.argv[2] + '\r\n')
}
@mattli001
mattli001 / ffmpeg_test.go
Created May 19, 2017 01:56
golang test ffmpeg example
package ffmpeg
import (
"bytes"
"context"
"io"
"os"
"os/exec"
"strings"
"testing"
@Geoyi
Geoyi / install virtualenv ubuntu 16.04.md
Created September 16, 2017 12:19 — forked from frfahim/install virtualenv ubuntu 16.04.md
How to install virtual environment on ubuntu 16.04

How to install virtualenv:

Install pip first

sudo apt-get install python3-pip

Then install virtualenv using pip3

sudo pip3 install virtualenv