Skip to content

Instantly share code, notes, and snippets.

View Songbird0's full-sized avatar

Bobbywan-Roboyo Songbird0

  • France
View GitHub Profile
@Songbird0
Songbird0 / Corrector.java
Created November 28, 2015 17:33
A primitive Corrector (update 0.4_2-ALPHA)
package fr.songbird.survivalDevKit;
import java.io.*;
import net.wytrem.logging.*;
/**
* I'm happy to present you my primitive Corrector !
* He can to correct words that your file contains ! (he's not case sensitive currently)
* @author songbird
* @version 0.4_2-ALPHA
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.40">
<children>
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.40">
@Songbird0
Songbird0 / ipRegex.rb
Last active May 9, 2016 23:38
regex for ip address
ipAddress = "192.168.254.255"
if ipAddress =~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ixu
puts "it run" #=> it run
end
ipAddress = "192...168..224.36"
if ipAddress =~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ixu
puts "it run" #=> nil
@Songbird0
Songbird0 / regexAbsolutePath.rb
Last active May 10, 2016 01:52
A regex for checking absolute path :D
path = "/my/awesome/path/file"
puts path =~ /^((\/[a-zA-Z0-9_-]+)\/?)+$/ # => 0 it's ok
path = "/////////////"
puts path =~ /^((\/[a-zA-Z0-9_-]+)\/?)+$/ # => nil error
@Songbird0
Songbird0 / regexRelativePath.rb
Created May 10, 2016 01:37
Matches relative path
path = "../my/path/file/"
puts path =~ /^(\.{2}\/)?([\w\d!?_-]\/?)+/ #=> 0
path = "my/awesome/path/file"
puts path =~ /^(\.{2}\/)?([\w\d!?_-]\/?)+/ #=> 0
@Songbird0
Songbird0 / splitter_function.js
Created August 1, 2016 22:00
Macro permettant l'extraction d'une sous-chaîne de caractères dans une chaîne plus grande.
/*
Creates a new string if the pattern is found.
*/
function splitter(pattern, target) {
var array_length = pattern.length;
var tmp = null;
for (var i = 0; i < array_length; i++) {
if (tmp != null)
tmp += pattern[i];
if (tmp === null)
@Songbird0
Songbird0 / sliceAt.js
Last active August 14, 2016 22:37
Removes the wanted word/expression and returns a new string without him.
function sliceAt(initial_string: string, target: string)
{
let index : number = initial_string.indexOf(target);
if(index !== -1)
{
switch(index)
{
case 0:return initial_string.substring(index+target.length);
case (initial_string.length - 1): return initial_string.substring(index, target.length-1);
@Songbird0
Songbird0 / replace_word.js
Last active August 14, 2016 21:26
Replaces a word by another word (or a substring) - This file has '.js' as file extension for syntaxic coloration only. (It's a TypeScript function) See example in comments.
/*
let foo : string = 'Hello world !';
console.log(replace_word(foo, 'world', 'my name is John')); // print Hello my name is John !
*/
function replace_word(initial_string : string, word : string, newWord: string) : string
{
let newString : string = '';
const index : number = initial_string.indexOf(word);
if(index !== -1)
@Songbird0
Songbird0 / replace_word_jsstyle.js
Created August 14, 2016 21:33
replace_word function for javascript developers. See original function here: https://gist.github.com/Songbird0/978bf046b37a2969c51495336c7c29ef
function replace_word(initial_string, word, newWord) {
var index = initial_string.indexOf(word);
if (index !== -1) {
var first_part = '';
var mid_part = '';
var second_part = '';
if (index === 0) {
first_part = newWord;
second_part = sliceAt(initial_string, word);
return "" + first_part + second_part;