Skip to content

Instantly share code, notes, and snippets.

View indrabagus's full-sized avatar
🏠
Working from home

インドラバグス indrabagus

🏠
Working from home
  • PT Sovware Data Mandiri
  • Bandung, West Java, Indonesia
View GitHub Profile
@indrabagus
indrabagus / nginx.conf
Last active May 21, 2024 09:01 — forked from weapp/nginx.conf
Return common errors as json in Nginx
error_page 500 /500.json;
location /500.json{
return 500 '{"error": {"status_code": 500,"status": "Internal Server Error"}}';
}
error_page 502 /502.json;
location /502.json{
return 502 '{"error": {"status_code": 502,"status": "Bad Gateway"}}';
}
@indrabagus
indrabagus / Application.java
Created January 6, 2023 03:31 — forked from simon04/Application.java
Lightweight REST API using Jersey on embedded Jetty server
package root;
import root.resources.HelloResource;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
public class Application {
@indrabagus
indrabagus / wsl2_all_hacks.md
Last active November 5, 2024 13:26 — forked from wllmsash/assigning-static-ip-addresses-in-wsl2.md
Assigning a Static IP Address to a WSL2 Distribution

1. Assigning a Static IP Address to a WSL2 Distribution

Hyper-V creates a hidden virtual switch for WSL2. In Windows, the virtual NIC vEthernet (WSL (Hyper-V firewall)) (use command route print to ensure the name of this virtual NIC) is connected to the switch. In WSL2 (Ubuntu), the virtual NIC eth0 is connected to the switch. Communication between the two network endpoints happens over the switch. The virtual NICs (and possibly the switch) are ephemeral and disappear at host system restart time. The NICs are recreated on demand when WSL2 first runs.

To use a custom static IP address we can assign each of the NICs to IP addresses on a shared subnet. It's a good idea to pick a subnet in the Private Address range.

@indrabagus
indrabagus / GetMore100TweetsTweepyOAuth2.py
Created October 25, 2022 06:36 — forked from mGalarnyk/GetMore100TweetsTweepyOAuth2.py
Get more than 100 Tweets at a time using paginator. If you need more than 100 Tweets, you will have to use paginator (https://docs.tweepy.org/en/latest/pagination.html). Replace the limit=1000 with the maximum number of tweets you want.
# OAuth2.0 Version
import tweepy
#Put your Bearer Token in the parenthesis below
client = tweepy.Client(bearer_token='Change this')
"""
If you don't understand search queries, there is an excellent introduction to it here:
https://github.com/twitterdev/getting-started-with-the-twitter-api-v2-for-academic-research/blob/main/modules/5-how-to-write-search-queries.md
"""
@indrabagus
indrabagus / gist:3d01286d3ff0f875a9f0c350a6df7855
Created February 5, 2020 07:31 — forked from skyuplam/gist:ffb1b5f12d7ad787f6e4
Flask-Security and Flask-Admin example by Steve Saporata
# Example of combining Flask-Security and Flask-Admin.
# by Steve Saporta
# April 15, 2014
#
# Uses Flask-Security to control access to the application, with "admin" and "end-user" roles.
# Uses Flask-Admin to provide an admin UI for the lists of users and roles.
# SQLAlchemy ORM, Flask-Mail and WTForms are used in supporting roles, as well.
from flask import Flask, render_template
from flask.ext.sqlalchemy import SQLAlchemy
@indrabagus
indrabagus / vocabulary.md
Last active November 15, 2023 01:42 — forked from machikoyasuda/vocabulary.md
Japanese/English programming/tech vocabulary

Tech Expression in Japanese

拡張現実【かくちょうげんじつ】 augmented reality, AR

投資家【とうしか】 investor

静的【せいてき】

@indrabagus
indrabagus / axios-catch-error.js
Created November 11, 2019 01:53 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@indrabagus
indrabagus / gunicorn_start.bash
Created April 12, 2018 12:06 — forked from postrational/gunicorn_start.bash
Example of how to set up Django on Nginx with Gunicorn and supervisordhttp://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
#!/bin/bash
NAME="hello_app" # Name of the application
DJANGODIR=/webapps/hello_django/hello # Django project directory
SOCKFILE=/webapps/hello_django/run/gunicorn.sock # we will communicte using this unix socket
USER=hello # the user to run as
GROUP=webapps # the group to run as
NUM_WORKERS=3 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=hello.settings # which settings file should Django use
DJANGO_WSGI_MODULE=hello.wsgi # WSGI module name
@indrabagus
indrabagus / web-servers.md
Created April 11, 2018 23:36 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@indrabagus
indrabagus / force_all_users_logged_out.md
Last active April 10, 2018 02:08
How to log out all Django's users at once

server:~/smartlock_system$ python manage.py

>>> from django.contrib.sessions.models import Session
>>> Session.objects.all().delete()

Congratulations! Your site is now very lonely.