Skip to content

Instantly share code, notes, and snippets.

View DenoGeek's full-sized avatar

Dennis Kariuki DenoGeek

View GitHub Profile
@DenoGeek
DenoGeek / combine.go
Created January 11, 2020 10:13
Recombine file chunks
chunkSizeInBytes := 1048576
chunksDir := "/path/to/uploads/temp/3203610240-WildifeTactics"
/*
Generate an empty file
*/
f, err := os.Create("testfile.mp4")
if err != nil {
fmt.Printf("Error: %s", err)
}
// ResumableUpload handles reumable uploads
func ResumableUpload(w http.ResponseWriter, r *http.Request) {
tempFolder := "/path/to/uploads/temp/"
switch r.Method {
case "GET":
resumableIdentifier, _ := r.URL.Query()["resumableIdentifier"]
resumableChunkNumber, _ := r.URL.Query()["resumableChunkNumber"]
path := fmt.Sprintf("%s%s", tempFolder, resumableIdentifier[0])
@DenoGeek
DenoGeek / resumable.html
Created January 11, 2020 09:42
Resumable js configuration
<script src="resumable.js"></script>
<script>
var r = new Resumable({
target:'http://localhost:8080/upload',
});
r.assignBrowse(document.getElementById('upload-area'));
// Resumable.js isn't supported, fall back on a different method
if(!r.support) location.href = '/some-old-crappy-uploader';
@DenoGeek
DenoGeek / resumablediv.html
Last active January 11, 2020 09:39
Resumable js div
<style type="text/css">
.resume-upload{
width: 60%;
height: 200px;
background: skyblue;
margin: 40 auto;
border: 1px dashed black;
}
</style>
class MobileTokenBaseSerializer(serializers.Serializer):
verification_code=serializers.CharField()
def validate_verification_code(self,value):
if not MobileToken.objects.filter(verification_code=value).exists():
raise serializers.ValidationError("The token provided does not exist")
elif MobileToken.objects.filter(verification_code=value).first().is_used:
raise serializers.ValidationError("The token provided is used")
return value
class MobileAuthView(generics.GenericAPIView):
permission_classes = ()
authentication_classes = ()
serializer_class=MobileAuthSerializer
def post(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
if serializer.is_valid():
class MobileToken(models.Model):
verification_code=models.CharField(max_length=225)
user=models.ForeignKey(settings.AUTH_USER_MODEL, related_name="mobile_tokens",on_delete=models.CASCADE)
phone_number=models.CharField(max_length=225)
is_used=models.BooleanField(default=False)
created = models.DateTimeField("Created on", auto_now_add=True)
class MobileAuthSerializer(serializers.Serializer):
phone_number=serializers.CharField(required=True)
def save(self):
#Retrieve the user with this mobile number or create a user instance with that phone number
try:
user=User.objects.get(mobile=self.validated_data['phone_number'])
except Exception as e:
user=User.objects.create(mobile=self.validated_data['phone_number'],email=self.validated_data['phone_number'])
#Generate the users token and send it out
@DenoGeek
DenoGeek / src_match.php
Last active April 22, 2019 16:52
Src pregmatch
$iframe_string = '<iframe width="100%" height="315" src="https://www.youtube.com/embed/-XC6r9SIQfo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
preg_match('/src="([^"]+)"/', $iframe_string, $match);
/*Output all the matches by the expression*/
print_r($match);
/*Get the index of the array*/
$url = $match[1];
@DenoGeek
DenoGeek / query.php
Created April 3, 2019 22:44
crazy query
$orders = Order::join('assignments', 'orders.active_assignment', '=', 'assignments.id');
$orders->join('users', 'assignments.user_id', '=', 'users.id');
$orders->leftJoin('bargains', 'bargains.order_id', '=', 'orders.id');
$orders->doesntHave('payment');
$orders->where('orders.status',4);
$orders->select(['orders.id','bargains.order_id','users.id as user_id','orders.order_no','orders.salary','users.name',DB::raw('SUM(bargains.amount) As bargains_sum, (SUM(bargains.amount)+orders.salary) as total')]);
$orders->groupBy(['orders.id']);
$result = $orders->get();
/*