Skip to content

Instantly share code, notes, and snippets.

View aniongithub's full-sized avatar

Ani aniongithub

View GitHub Profile
@cosimo
cosimo / parse-options.sh
Created September 21, 2012 09:31
Example of how to parse options with bash/getopt
#!/bin/bash
#
# Example of how to parse short/long options with 'getopt'
#
OPTS=`getopt -o vhns: --long verbose,dry-run,help,stack-size: -n 'parse-options' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
echo "$OPTS"
@ozh
ozh / new empty git branch.md
Last active April 8, 2025 20:49
Create a new empty branch in Git
$ git checkout --orphan NEWBRANCH
$ git rm -rf .

--orphan creates a new branch, but it starts without any commit. After running the above command you are on a new branch "NEWBRANCH", and the first commit you create from this state will start a new history without any ancestry.

You can then start adding files and commit them and they will live in their own branch. If you take a look at the log, you will see that it is isolated from the original log.

@davisford
davisford / setup-avahi.sh
Created July 12, 2013 14:14
Setup avahi-daemon on Ubuntu for so you can reach hostname `ubuntu.local` from host OS
sudo apt-get install avahi-daemon avahi-discover avahi-utils libnss-mdns mdns-scan
@dergachev
dergachev / squid-deb-proxy_on_docker.md
Last active February 21, 2025 02:49
Caching debian package installation with docker

TLDR: I now add the following snippet to all my Dockerfiles:

# If host is running squid-deb-proxy on port 8000, populate /etc/apt/apt.conf.d/30proxy
# By default, squid-deb-proxy 403s unknown sources, so apt shouldn't proxy ppa.launchpad.net
RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt
RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | grep squid-deb-proxy \
  && (echo "Acquire::http::Proxy \"http://$(cat /tmp/host_ip.txt):8000\";" > /etc/apt/apt.conf.d/30proxy) \
  && (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) \
  || echo "No squid-deb-proxy detected on docker host"
@madrobby
madrobby / gist:9476733
Created March 10, 2014 23:34
Download a single file from a private GitHub repo. You'll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use
curl -H 'Authorization: token INSERTACCESSTOKENHERE' -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/owner/repo/contents/path
@staltz
staltz / introrx.md
Last active May 15, 2025 10:37
The introduction to Reactive Programming you've been missing
@bengfarrell
bengfarrell / gist:4bd75031e40c5dd7202e
Created September 19, 2014 05:30
Injecting a script into a page using Atom-Shell
app.on('ready', function() {
var injectscript = escape(__dirname + '/inject/test.js');
mainWindow = new BrowserWindow( { width: '800px', height: '600px', 'web-preferences': { 'web-security': false } });
mainWindow.loadUrl('http://google.com' );
mainWindow.openDevTools();
mainWindow.getWebContents().on('did-finish-load', function() {
var remotejs = "var js = document.createElement('script'); \
js.src = 'file://' + unescape('" + injectscript + "'); \
console.log(js); \
document.getElementsByTagName('body')[0].appendChild(js);";
@alan-mushi
alan-mushi / json_parser.c
Last active April 2, 2025 07:28
Examples for the json-c tutorial.
/*
* A simple example of json string parsing with json-c.
*
* clang -Wall -g -I/usr/include/json-c/ -o json_parser json_parser.c -ljson-c
*/
#include <json.h>
#include <stdio.h>
int main() {
struct json_object *jobj;
@rob-blackbourn
rob-blackbourn / BufferExtension.md
Last active July 4, 2024 00:27
A C# linq extension to buffer an enumerable into an enumerable of enumerable blocks

Bufering in linq

static void Main()
{
    foreach (var block in "The quick brown fox jumped over the lazy dog".Split(' ').Buffer(4))
        Console.WriteLine(string.Join(" ", block));
}

The code takes the sentence "The quick brown fox jumped over the lazy dog", splits it into words, buffers it into blocks of four words, then writes each block of words joined by spaces.

@mariobadr
mariobadr / game_loop.cpp
Last active April 14, 2025 20:46
A basic game loop using std::chrono
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Mario Badr
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is