Skip to content

Instantly share code, notes, and snippets.

View jweinst1's full-sized avatar
🎯
Focusing

Josh Weinstein jweinst1

🎯
Focusing
View GitHub Profile
@jweinst1
jweinst1 / String character Indexing Swift
Created July 19, 2015 02:48
Functions that allow you to check for the indexes at which a character appears in a string in Swift.
// returns a dictionary that holds the indexes for every character in a string
func StringIndexer(str:String) ->Dictionary<Int, Character> {
var strlist = Array(str); var strdict = [Int:Character](); var indexer = 0
for letter in strlist {
strdict.updateValue(letter, forKey: indexer)
indexer += 1
}
return strdict
}
// returns an array containing the indexes where a character appears in a string
@jweinst1
jweinst1 / Array Slicing Swift
Created July 19, 2015 05:00
Two functions that slice arrays in Swift
// Returns a slice of an array that contains characters
func StringSlicer(list:Array<Character>, n1:Int, n2:Int) ->Array<Character> {
var slicer = n1; var slicedlist = [Character]()
while slicer <= n2 {
slicedlist.append(list[slicer])
slicer += 1
}
return slicedlist
}
// returns a slice of an array of characters with an increment
@jweinst1
jweinst1 / String Slicer Swift
Created July 19, 2015 07:12
For every a character appears in a string, it creates a slice of the string and appends it to an array
// returns a dictionary that holds the indexes for every character in a string
func StringIndexer(str:String) ->Dictionary<Int, Character> {
var strlist = Array(str); var strdict = [Int:Character](); var indexer = 0
for letter in strlist {
strdict.updateValue(letter, forKey: indexer)
indexer += 1
}
return strdict
}
// returns an array containing the indexes where a character appears in a string
@jweinst1
jweinst1 / Counting Words and Letters in Swift.swift
Created July 20, 2015 20:14
Functions that count words and letters in a string in swift.
//counts a specific letter in a string
func SpecificLetterCount(str:String, char:Character) ->Int {
var letters = Array(str); var count = 0
for letter in letters {
if letter == char {
count += 1
}
}
return count
}
@jweinst1
jweinst1 / Linked Nodes.py
Created July 22, 2015 18:20
Linked Nodes.py
class Node (object):
def __init__(self, cargo=0, next=0):
self.cargo, self.next = cargo, next
class NodeList (list):
def __init__(self, head):
self.append(head)
def deeplen(self):
strlst = list(str(self))
numlist = [s for s in strlst if s != '[' and s != ']' and s != ' ' and s != ',']
@jweinst1
jweinst1 / Circular Linked List.py
Created August 17, 2015 05:59
Circular Linked List.py
class Link (object):
def __init__(self, first=None, rest=None):
self.first = first
self.rest = rest
def get_data(self):
return self.first
def get_next(self):
return self.rest
def __getitem__(self, i):
@jweinst1
jweinst1 / sample_applet.java
Created August 30, 2015 04:33
basic applet template for Java
package tester;
import java.applet.*;
import java.awt.*;
public class list_applet extends Applet{
public void init(){
System.out.print ("Peace Out");
}
public void paint(Graphics g){
@jweinst1
jweinst1 / textfield.java
Created August 30, 2015 05:13
basic textfield template in java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class textfield extends Applet implements ActionListener {
TextField inputLine = new TextField(15);
public textfield() {
add(inputLine);
inputLine.addActionListener(this);
@jweinst1
jweinst1 / printinganarrayJava.java
Created August 31, 2015 22:31
Printing an Array in String Format in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
int[] thing = {1, 2, 3};
System.out.println(Arrays.toString(thing));
}
}
@jweinst1
jweinst1 / retrievearrayvalue.java
Created August 31, 2015 22:47
Retrieving value from an Array in Java
import java.util.Arrays;
class Main {
public static void main(String[] args) {
System.out.println(checkvalue(thing, 2));
}
static int[] thing = {1, 2, 3};
static int checkvalue(int[] x, int y) {
return x[y];
}