Skip to content

Instantly share code, notes, and snippets.

@agmike
agmike / CamelCaseToSnakeCaseUppercased.swift
Created March 2, 2021 12:02
camelCaseToSnakeCaseUppercased
func camelCaseToSnakeCaseUppercased(_ input: String) -> String {
enum State {
case outside
case nextLetter
case subsequentUpperLetters
case subsequentLowerLetters
case digits
}
@agmike
agmike / prepare-commit-msg
Created October 20, 2020 09:13
Automatically adds task ID in square brackets eg [TASK-1234] (if it exists) or branch name to every commit message
#!/bin/sh
#
# Automatically adds task ID in square brackets eg [TASK-1234] (if it exists) or branch name to every commit message.
#
NAME=$(git branch | grep '*' | sed 's/* //')
JIRA_TICKET=$(echo "$NAME" | grep -o '[A-Z]\{3,5\}-[0-9]\{3,7\}' )
TEXT=$(cat "$1")
TEXT_HAS_PREFIX=$(echo "$TEXT" | egrep -o '^\[')
if [ -z "$TEXT_HAS_PREFIX" ]
@agmike
agmike / Model.java
Created December 21, 2015 19:12
FSM example
package fsm;
public class Model {
private boolean x1, x2, x3, x4;
private boolean f1, f2, f3;
private boolean y1, y2, y3, y4, y5, y6;
private State state;
public Model() {
state = State.S0;
@agmike
agmike / solver.java
Created July 14, 2015 18:40
Nanoseconds
package p5_parallel;
import java.util.Scanner;
public class solver {
public static void main(String[] args) {
System.out.println(solve(new Scanner(System.in)));
}
@agmike
agmike / solver.java
Created July 14, 2015 18:36
Digit permutations
package h_test_bigger;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class solver {
public static void main(String[] args) {
System.out.println(solve(new Scanner(System.in)));
}
@agmike
agmike / solver.java
Created July 10, 2015 17:47
Partition problem: DP algorithm
package p4_students;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
public class solver {
public static void main(String[] args) {
System.out.println(solve(new Scanner(System.in)));
}
@agmike
agmike / Tests.java
Created July 6, 2015 18:42
Юнит-тесты в спортивном программировании
package p5_parallel;
import org.junit.Test;
import java.util.Scanner;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
public class Tests {
@agmike
agmike / pom.xml
Created July 1, 2015 10:04
Test UTF-8 pom setup
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.teamyeah</groupId>
<artifactId>cheapaviasales</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
@agmike
agmike / GameScript.g4
Last active August 29, 2015 14:22
GameScript ANTLR4 grammar. Contains additional rule for annotations inside /*[ ]*/ comment block.
grammar GameScript;
/*
* Parser Rules
*/
//
// Top level items
program
@agmike
agmike / main.rs
Last active August 29, 2015 14:21
extern crate parser_combinators;
use parser_combinators::*;
#[derive(Debug)]
struct IncludeDecl { pub file: String }
#[derive(Debug)]
struct ClassDecl { pub name: String }