Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion scripts/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { linuxRepo } from "./linux";
import { reactRepo } from "./react";
import { tensorFlowRepo } from "./tensorflow";
import { kotlinRepo } from "./kotlin";
import { javaRepo } from "./java";
import { pythonRepo } from "./python";

export type RepoFile = {
path: string;
Expand All @@ -16,5 +19,8 @@ export type Repo = {
export const repoOptions: Repo[] = [
linuxRepo,
reactRepo,
tensorFlowRepo
tensorFlowRepo,
kotlinRepo,
javaRepo,
pythonRepo
]
81 changes: 81 additions & 0 deletions scripts/data/java.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Repo } from "."

export const javaRepo: Repo = {
label: "Java",
url: "https://github.com/openjdk/jdk",
files: [
{
path: "/src/java.base/windows/classes/java/lang/Terminator.java",
code:`
package java.lang;

import jdk.internal.misc.Signal;

class Terminator {

private static Signal.Handler handler = null;


static void setup() {
if (handler != null) return;
Signal.Handler sh = new Signal.Handler() {
public void handle(Signal sig) {
Shutdown.exit(sig.getNumber() + 0200);
}
};
handler = sh;

try {
Signal.handle(new Signal("INT"), sh);
} catch (IllegalArgumentException e) {
}
try {
Signal.handle(new Signal("TERM"), sh);
} catch (IllegalArgumentException e) {
}
}

static void teardown() {
}

}
`
},
{
path: "/src/jdk.httpserver/windows/classes/sun/net/httpserver/simpleserver/URIPathSegment.java",
code:`
package sun.net.httpserver.simpleserver;

/**
* A class that represents a URI path segment.
*/
final class URIPathSegment {

private URIPathSegment() { throw new AssertionError(); }

/**
* Checks if the segment of a URI path is supported. For example,
* "C:" is supported as a drive on Windows only.
*
* @param segment the segment string
* @return true if the segment is supported
*/
static boolean isSupported(String segment) {
// apply same logic as WindowsPathParser
if (segment.length() >= 2 && isLetter(segment.charAt(0)) && segment.charAt(1) == ':') {
return false;
}
return true;
}

private static boolean isLetter(char c) {
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
}
}

`
},


]
}
93 changes: 93 additions & 0 deletions scripts/data/kotlin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Repo } from "."


export const kotlinRepo: Repo = {
label: "Kotlin",
url: "https://github.com/JetBrains/kotlin",
files:
[
{
path: "/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt",
code: `
package org.jetbrains.kotlin.utils

import java.util.*

fun <K, V> Iterable<K>.keysToMap(value: (K) -> V): Map<K, V> {
return associateBy({ it }, value)
}

fun <K, V : Any> Iterable<K>.keysToMapExceptNulls(value: (K) -> V?): Map<K, V> {
val map = LinkedHashMap<K, V>()
for (k in this) {
val v = value(k)
if (v != null) {
map[k] = v
}
}
return map
}

fun <K> Iterable<K>.mapToIndex(): Map<K, Int> {
val map = LinkedHashMap<K, Int>()
for ((index, k) in this.withIndex()) {
map[k] = index
}
return map
}

inline fun <K, V> MutableMap<K, V>.getOrPutNullable(key: K, defaultValue: () -> V): V {
return if (!containsKey(key)) {
val answer = defaultValue()
put(key, answer)
answer
} else {
@Suppress("UNCHECKED_CAST")
get(key) as V
}
}

inline fun <T, C : Collection<T>> C.ifEmpty(body: () -> C): C = if (isEmpty()) body() else this

inline fun <K, V, M : Map<K, V>> M.ifEmpty(body: () -> M): M = if (isEmpty()) body() else this

inline fun <T> Array<out T>.ifEmpty(body: () -> Array<out T>): Array<out T> = if (isEmpty()) body() else this

fun <T : Any> MutableCollection<T>.addIfNotNull(t: T?) {
if (t != null) add(t)
}

suspend fun <T : Any> SequenceScope<T>.yieldIfNotNull(t: T?) = if (t != null) yield(t) else Unit

fun <K, V> newHashMapWithExpectedSize(expectedSize: Int): HashMap<K, V> =
HashMap(capacity(expectedSize))

fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> =
HashSet(capacity(expectedSize))

fun <K, V> newLinkedHashMapWithExpectedSize(expectedSize: Int): LinkedHashMap<K, V> =
LinkedHashMap(capacity(expectedSize))

fun <E> newLinkedHashSetWithExpectedSize(expectedSize: Int): LinkedHashSet<E> =
LinkedHashSet(capacity(expectedSize))

private fun capacity(expectedSize: Int): Int =
if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1

fun <T> ArrayList<T>.compact(): List<T> =
when (size) {
0 -> emptyList()
1 -> listOf(first())
else -> apply { trimToSize() }
}

fun <T> List<T>.indexOfFirst(startFrom: Int, predicate: (T) -> Boolean): Int {
for (index in startFrom..lastIndex) {
if (predicate(this[index])) return index
}
return -1
}
`
}
]
}
87 changes: 87 additions & 0 deletions scripts/data/python.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Repo } from "."

export const pythonRepo: Repo = {
label: "Python",
url: "https://github.com/Python",
files:
[
{
path: "https://github.com/Pycord-Development/pycord/blob/master/examples/app_commands/slash_cog.py",
code: `
import discord
from discord.ext import commands


class Example(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.slash_command(
guild_ids=[...]
) # Create a slash command for the supplied guilds.
async def hello(self, ctx: discord.ApplicationContext):
await ctx.respond("Hi, this is a slash command from a cog!")

@commands.slash_command() # Not passing in guild_ids creates a global slash command.
async def hi(self, ctx: discord.ApplicationContext):
await ctx.respond("Hi, this is a global slash command from a cog!")


def setup(bot):
bot.add_cog(Example(bot))

`
},
{
path: "https://github.com/Pycord-Development/pycord/blob/master/examples/app_commands/info.py",
code: `
import discord

intents = discord.Intents.default()
intents.members = True

bot = discord.Bot(
debug_guilds=[...],
description="An example to showcase how to extract info about users.",
intents=intents,
)


@bot.slash_command(name="userinfo", description="Gets info about a user.")
async def info(ctx: discord.ApplicationContext, user: discord.Member = None):
user = (
user or ctx.author
) # If no user is provided it'll use the author of the message
embed = discord.Embed(
fields=[
discord.EmbedField(name="ID", value=str(user.id), inline=False), # User ID
discord.EmbedField(
name="Created",
value=discord.utils.format_dt(user.created_at, "F"),
inline=False,
), # When the user's account was created
],
)
embed.set_author(name=user.name)
embed.set_thumbnail(url=user.display_avatar.url)

if user.colour.value: # If user has a role with a color
embed.colour = user.colour

if isinstance(user, discord.User): # Checks if the user in the server
embed.set_footer(text="This user is not in this server.")
else: # We end up here if the user is a discord.Member object
embed.add_field(
name="Joined",
value=discord.utils.format_dt(user.joined_at, "F"),
inline=False,
) # When the user joined the server

await ctx.respond(embeds=[embed]) # Sends the embed


bot.run("TOKEN")
`
}
]
}