Skip to content

Instantly share code, notes, and snippets.

View royswale's full-sized avatar
💕
TypeScript & Go & Rust

royswale

💕
TypeScript & Go & Rust
View GitHub Profile
@royswale
royswale / Android - Launch another app
Created January 11, 2023 08:38 — forked from dominicthomas/Android - Launch another app
Launch another app using an intent with package name if app has a launcher activity or using package name and class name of main activity.
// only works if app has a launcher activity
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.yourapp");
startActivity(launchIntent);
// works if we know the name of the main activity, even if not a launcher
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.example.yourapp", "com.example.yourapp.MainActivity");
startActivity(intent);
@royswale
royswale / Car.cpp
Created November 29, 2022 14:33 — forked from DavidYKay/Car.cpp
C++ Class / Header file example
#import "Car.h"
const int ACCELERATION_FACTOR = 10;
const int BRAKING_FACTOR = 30;
Car::Car() {
speed = 0;
}
void Car::accelerate(float intensity) {
@royswale
royswale / RenderHtml.vue
Created November 21, 2022 08:44 — forked from adrianjost/RenderHtml.vue
RenderHtml Component
<script>
// Cool way to render Vue components from HTML Strings
// https://medium.com/haiiro-io/compile-markdown-as-vue-template-on-nuxt-js-1c606c15731c
import VueWithCompiler from "vue/dist/vue.esm";
export default {
props: {
html: {
type: String,
default: "",
},
@royswale
royswale / nginx_assets.md
Created October 24, 2022 07:03 — forked from XUJiahua/nginx_assets.md
Serving Static Assets via Nginx

Concept

  • People talk about two servers: a web server (e.g. Nginx, Apache, etc.) and a app server (e.g. Language specific servers like Unicorn, Node.js, Tomcat, Http-Kit, etc.). There are exceptions where app servers not required at all (as web server itself provides preprocessors for handling), but let's not talk about now.
  • Web servers are really fast and supports lot of standard and commonly used MIME-type requests. Concept of serving a file is -- forming and sending a response of bytes of data and labeling it with requested MIME-type by a client (e.g. web browser).
  • Every response format (in layman's language, a file) is recognized by it's MIME-type, for e.g. a PNG image file has "image/png" MIME-type. JavaScript file has "text/javascript". HTML responses (or files) has "text/html". Plain text files have "text/plain".
  • Modern Browsers supports a lot of standard MIME-types. Images, videos, text files (XML, HTML, SVG, JS), and they better know how to visualize it. Browser also knows unrec
@royswale
royswale / jupyter_echarts.py
Created August 10, 2022 03:30 — forked from drorhilman/jupyter_echarts.py
A script to display echarts charts in jupyter notebook, both in notebook and in vscode!
# -- consts --
ECHARTS_CDN = "https://cdn.jsdelivr.net/npm/echarts@5.3.2/dist/echarts.min"
ECHARTS_REQUIREJS_CONF = f"requirejs.config({{paths: {{echarts: '{ECHARTS_CDN}',}}}});"
ECHARTS_TEMPLATE = f"""
<div id="{{ID}}" style="width: {{WIDTH}};height:{{HEIGHT}};"></div>
<script type="module">
{ECHARTS_REQUIREJS_CONF}
requirejs(["echarts"], (echarts) => {{
let myChart = echarts.init(document.getElementById({{ID}}));
@royswale
royswale / screenshot.bat
Created May 26, 2022 01:35
adb shell screenshot
adb connect 192.168.0.55
adb shell /system/bin/screencap -p /sdcard/screenshot.png
adb pull /sdcard/screenshot.png C:/Users/xxxx/Downloads/screenshot.png
@echo off
for /F "tokens=2" %%i in ('date /t') do set mydate=%%i
set mytime=%time%
@royswale
royswale / gpa.sh
Created May 26, 2022 01:32
git pull all
#!/bin/bash
# put this script in directory
# D:\laragon\bin\git\usr\bin
# then gpa.sh will be available in git bash
# git push to all remote
remotes=( $(git remote) )
# coding
@royswale
royswale / merge.md
Created April 22, 2022 01:52 — forked from rotimi-best/merge.md
How to merge one folder within two branches in git

git - How to merge one folder within two branches

In my project folder I have 2 folders client and server, I only want get the changes in my server folder from master to prod branch

  1. git checkout prod - Go to the branch with the oldest changes
  2. git merge --no-commit --no-ff master - Merge with the branch with the latest changes. Read More
  3. git reset -- client* - Unstage any changes from client folder, I only want to server folder. Read More
  4. git checkout -- client* - Remove any changes from client folder, I only want to server folder.
  5. git clean -n - View all unstaged files. Read More
  6. git clean -fd - Remove all unstaged folder, if you dont want to remove all then you should add those with git add and then run this command. Read More
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <string>
using namespace std;
@royswale
royswale / bbclient.cpp
Created April 14, 2022 15:08 — forked from codehoose/bbclient.cpp
Barebones TCP client for Linux
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <string>
using namespace std;