Skip to content

Instantly share code, notes, and snippets.

View ivankahl's full-sized avatar
🤪
"Maybe if I close and open it again it'll build..."

Ivan Kahl ivankahl

🤪
"Maybe if I close and open it again it'll build..."
View GitHub Profile
@ivankahl
ivankahl / Initials in 140bytes (annotated).js
Last active May 14, 2018 17:55
This function returns the initials of a name which is passed to it.
function(fn)
{
var n=fn.split(" "), // Split the full name into an array
it="", // Create and set the intials variable to nothing
i; // Set i to 0 for the while loop
while(i<n.length) // While loop that runs while i is smaller than the length of the array of names
{
it+=n[i][0]; // Get the first letter from the name and add it to the it(initial) variable
i++ // Increment i by 1
}
@ivankahl
ivankahl / Hex Colour in 132 bytes (annotated).js
Created November 17, 2013 09:29
This function generates random hex colours. Useful for random HTML pages.
function()
{
var l=["A","B","C","D","E","F",0,1,2,3,4,5,6,7,8,9], // We declare our list with all the possible characters that can be used
c="", // Our variable we are going to use to store our final hex colour in
i=0; // The i variable we will use in our while loop
while(i<6) // Loop the code 6 times so that we get a 6-byte string (i.e. the hex colour)
{
c+=l[Math.floor(Math.random()*16)]; // Get a random value from the list
i++ // Increment i by 1
}
@ivankahl
ivankahl / Search and Replace.py
Created April 28, 2015 19:35
Search and Replace.py
# This script simply searches for all instances of a search term and replaces tgem with supplied text
# Ivan Kahl, 28 April 2015
import console
import editor
def main():
# Get the search term
searchFor = console.input_alert('Search Term', 'Enter the term to search for in the text file', '', 'Continue')
@ivankahl
ivankahl / Open In.py
Created April 28, 2015 21:41
Open In.py
import console
import editor
import os
def main():
# Get the path to the file or select the current file open in the editor
path = console.input_alert('File Path', 'Enter the path to the file you want to open relative to the Documents directory Leave <CURRENT> to open current file', '<CURRENT>', 'Open In')
# Check if text was returned
if not path:
@ivankahl
ivankahl / SelectionSorting.cs
Last active November 19, 2015 19:17
Visual C#: Linear Sorting Algorithm
private static int[] SelectionSort(int[] items)
{
// Loop through each element
for (int i = 0; i < items.Length - 1; i++)
// Loop through each element afterwards
for (int j = i + 1; j < items.Length; j++)
// Check if the first item is bigger than the second item
if (items[i] > items[j])
{
// If it is, swap the two values
@ivankahl
ivankahl / BubbleSorting.cs
Created June 3, 2015 17:48
Visual C#: Bubble Sorting Algorithm
private static int[] BubbleSort(int[] numbers)
{
// Create a boolean to store whether the list has been sorted or not
bool sorted = false;
do
{
// Set our sorted value to true. This will be set to false if
// any values have to be swapped
sorted = true;
@ivankahl
ivankahl / swap_integers.pas
Created June 11, 2015 11:49
Swap two integers inside Delphi
var
X, Y, Temp := Integer;
begin
Temp := X;
X := Y;
Y := Temp;
end;
@ivankahl
ivankahl / Deserialize.cs
Last active September 24, 2015 13:23
Serialize and Deserialize JSON data in C#
using System;
using System.Text;
using System.Runtime.Serialization.Json;
using System.IO;
namespace JSONSerializerDesarializer
{
class Program
{
static void Main(string[] args)
@ivankahl
ivankahl / Deserialize.cs
Created September 24, 2015 13:22
Serialize and Deserialize XML data in C#
using System;
using System.IO;
using System.Xml.Serialization;
namespace XMLSerilizationDeserialization
{
class Program
{
static void Main(string[] args)
{
static int[] RemoveDuplicates(int[] items)
{
// Create a new array to store the items with no
// duplicates
List<int> newList = new List<int> { items[0] };
// Loop through every item in our items array
for (int i = 1; i < items.Length; i++)
{
// Create a new boolean to determine whether